結果
問題 | No.2992 Range ABCD String Query |
ユーザー | 👑 rin204 |
提出日時 | 2024-12-17 00:21:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 5,848 ms / 6,000 ms |
コード長 | 4,047 bytes |
コンパイル時間 | 420 ms |
コンパイル使用メモリ | 82,204 KB |
実行使用メモリ | 298,044 KB |
最終ジャッジ日時 | 2024-12-17 00:24:01 |
合計ジャッジ時間 | 155,212 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,148 ms
83,272 KB |
testcase_01 | AC | 1,103 ms
83,232 KB |
testcase_02 | AC | 1,387 ms
85,360 KB |
testcase_03 | AC | 1,286 ms
84,308 KB |
testcase_04 | AC | 1,457 ms
86,016 KB |
testcase_05 | AC | 1,329 ms
83,740 KB |
testcase_06 | AC | 1,545 ms
84,888 KB |
testcase_07 | AC | 950 ms
81,852 KB |
testcase_08 | AC | 1,614 ms
87,628 KB |
testcase_09 | AC | 1,322 ms
83,352 KB |
testcase_10 | AC | 4,972 ms
272,784 KB |
testcase_11 | AC | 5,506 ms
273,636 KB |
testcase_12 | AC | 5,498 ms
273,072 KB |
testcase_13 | AC | 5,325 ms
272,776 KB |
testcase_14 | AC | 5,449 ms
270,580 KB |
testcase_15 | AC | 5,413 ms
270,556 KB |
testcase_16 | AC | 5,066 ms
269,048 KB |
testcase_17 | AC | 5,657 ms
278,952 KB |
testcase_18 | AC | 5,274 ms
270,272 KB |
testcase_19 | AC | 5,848 ms
279,788 KB |
testcase_20 | AC | 4,301 ms
281,220 KB |
testcase_21 | AC | 4,064 ms
280,896 KB |
testcase_22 | AC | 4,025 ms
281,564 KB |
testcase_23 | AC | 3,914 ms
281,952 KB |
testcase_24 | AC | 3,969 ms
281,124 KB |
testcase_25 | AC | 5,433 ms
297,848 KB |
testcase_26 | AC | 5,046 ms
298,012 KB |
testcase_27 | AC | 5,058 ms
297,964 KB |
testcase_28 | AC | 5,169 ms
298,044 KB |
testcase_29 | AC | 5,307 ms
297,696 KB |
testcase_30 | AC | 4,950 ms
232,420 KB |
testcase_31 | AC | 4,987 ms
230,264 KB |
testcase_32 | AC | 5,167 ms
231,316 KB |
testcase_33 | AC | 5,094 ms
231,084 KB |
testcase_34 | AC | 4,849 ms
231,868 KB |
testcase_35 | AC | 4,520 ms
177,560 KB |
testcase_36 | AC | 4,328 ms
176,920 KB |
testcase_37 | AC | 594 ms
78,384 KB |
testcase_38 | AC | 797 ms
80,676 KB |
testcase_39 | AC | 978 ms
81,564 KB |
testcase_40 | AC | 991 ms
81,616 KB |
ソースコード
class SegmentTreeBase_: def ope(self, l, r): raise NotImplementedError def e(self): raise NotImplementedError def __init__(self, n, init=None): self.n = n self.n0 = 1 << (n - 1).bit_length() self.data = [self.e()] * (2 * self.n0) if init is not None: for i in range(n): self.data[self.n0 + i] = init[i] for i in range(self.n0 - 1, 0, -1): self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1]) def build(self): for i in range(self.n0 - 1, 0, -1): self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1]) def set(self, i, x): i += self.n0 self.data[i] = x while i > 1: i >>= 1 self.data[i] = self.ope(self.data[2 * i], self.data[2 * i + 1]) def get(self, i): return self.data[i + self.n0] def __getitem__(self, i): return self.data[i + self.n0] def __setitem__(self, i, x): self.set(i, x) def prod(self, l, r): assert 0 <= l <= r <= self.n0 l += self.n0 r += self.n0 lles = self.e() rres = self.e() while l < r: if l & 1: lles = self.ope(lles, self.data[l]) l += 1 if r & 1: r -= 1 rres = self.ope(self.data[r], rres) l >>= 1 r >>= 1 return self.ope(lles, rres) def max_right(self, l, f): if l == self.n: return self.n l += self.n0 sm = self.e() while 1: while l % 2 == 0: l >>= 1 if not f(self.ope(sm, self.data[l])): while l < self.n0: l <<= 1 if f(self.ope(sm, self.data[l])): sm = self.ope(sm, self.data[l]) l += 1 return l - self.n0 sm = self.ope(sm, self.data[l]) l += 1 if l & -l == l: break return self.n def min_left(self, r, f): if r == 0: return 0 r += self.n0 sm = self.e() while 1: r -= 1 while r > 1 and r % 2: r >>= 1 if not f(self.ope(self.data[r], sm)): while r < self.n0: r = 2 * r + 1 if f(self.ope(self.data[r], sm)): sm = self.ope(self.data[r], sm) r -= 1 return r + 1 - self.n0 sm = self.ope(self.data[r], sm) if r & -r == r: break return 0 class segtree(SegmentTreeBase_): def ope(self, l, r): ret = [0] * 16 for i in range(4): for j in range(i, 4): for k in range(i, j + 1): ret[i * 4 + j] = max(ret[i * 4 + j], l[i * 4 + k] + r[k * 4 + j]) return ret def e(self): return [0] * 16 n, Q = map(int, input().split()) S = input() a = [0] * 16 b = [0] * 16 c = [0] * 16 d = [0] * 16 for i in range(4): for j in range(i, 4): if i <= 0 <= j: a[i * 4 + j] = 1 if i <= 1 <= j: b[i * 4 + j] = 1 if i <= 2 <= j: c[i * 4 + j] = 1 if i <= 3 <= j: d[i * 4 + j] = 1 data = [None] * n for i, s in enumerate(S): if s == "A": data[i] = a[:] elif s == "B": data[i] = b[:] elif s == "C": data[i] = c[:] else: data[i] = d[:] seg = segtree(n, data) for _ in range(Q): query = input().split() if query[0] == "1": x, s = int(query[1]) - 1, query[2] if s == "A": seg.set(x, a[:]) elif s == "B": seg.set(x, b[:]) elif s == "C": seg.set(x, c[:]) else: seg.set(x, d[:]) else: l, r = map(int, query[1:]) print(r - l + 1 - seg.prod(l - 1, r)[3])