結果
問題 | No.2992 Range ABCD String Query |
ユーザー | lif4635 |
提出日時 | 2024-12-15 23:00:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 4,395 ms / 6,000 ms |
コード長 | 2,208 bytes |
コンパイル時間 | 296 ms |
コンパイル使用メモリ | 82,424 KB |
実行使用メモリ | 280,180 KB |
最終ジャッジ日時 | 2024-12-16 23:46:56 |
合計ジャッジ時間 | 112,128 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 743 ms
113,992 KB |
testcase_01 | AC | 681 ms
113,796 KB |
testcase_02 | AC | 937 ms
114,280 KB |
testcase_03 | AC | 806 ms
115,844 KB |
testcase_04 | AC | 984 ms
116,388 KB |
testcase_05 | AC | 815 ms
113,912 KB |
testcase_06 | AC | 869 ms
115,088 KB |
testcase_07 | AC | 496 ms
112,336 KB |
testcase_08 | AC | 1,107 ms
116,676 KB |
testcase_09 | AC | 843 ms
112,420 KB |
testcase_10 | AC | 3,910 ms
267,888 KB |
testcase_11 | AC | 3,931 ms
267,612 KB |
testcase_12 | AC | 3,890 ms
266,980 KB |
testcase_13 | AC | 3,736 ms
268,984 KB |
testcase_14 | AC | 3,791 ms
268,068 KB |
testcase_15 | AC | 3,873 ms
269,016 KB |
testcase_16 | AC | 3,721 ms
265,536 KB |
testcase_17 | AC | 4,144 ms
269,056 KB |
testcase_18 | AC | 3,882 ms
267,856 KB |
testcase_19 | AC | 4,114 ms
268,812 KB |
testcase_20 | AC | 2,945 ms
269,416 KB |
testcase_21 | AC | 2,905 ms
269,236 KB |
testcase_22 | AC | 2,993 ms
269,524 KB |
testcase_23 | AC | 3,057 ms
269,432 KB |
testcase_24 | AC | 2,946 ms
269,392 KB |
testcase_25 | AC | 4,291 ms
279,632 KB |
testcase_26 | AC | 4,365 ms
279,812 KB |
testcase_27 | AC | 4,340 ms
279,568 KB |
testcase_28 | AC | 4,379 ms
280,176 KB |
testcase_29 | AC | 4,395 ms
280,180 KB |
testcase_30 | AC | 3,249 ms
236,660 KB |
testcase_31 | AC | 3,282 ms
236,504 KB |
testcase_32 | AC | 3,312 ms
236,248 KB |
testcase_33 | AC | 3,234 ms
236,208 KB |
testcase_34 | AC | 3,255 ms
236,372 KB |
testcase_35 | AC | 3,265 ms
199,600 KB |
testcase_36 | AC | 3,223 ms
199,724 KB |
testcase_37 | AC | 339 ms
110,644 KB |
testcase_38 | AC | 450 ms
111,936 KB |
testcase_39 | AC | 516 ms
111,788 KB |
testcase_40 | AC | 510 ms
112,444 KB |
ソースコード
class SegTree: def __init__(self, op, e, lst): self.n = len(lst) self.N0 = 2 ** (self.n - 1).bit_length() self.op = op self.e = e self.data = [e] * (2 * self.N0) if type(lst) is list: for i in range(self.n): self.data[self.N0 + i] = lst[i] for i in range(self.N0 - 1, 0, -1): self.data[i] = self.op(self.data[2*i], self.data[2*i+1]) def get(self, i): return self.data[self.N0+i] def set(self, i, x): i += self.N0 self.data[i] = x while i > 1: i >>= 1 self.data[i] = self.op(self.data[2*i], self.data[2*i+1]) def prod(self, l, r): if r <= l: return self.e lres = self.e rres = self.e l += self.N0 r += self.N0 while l < r: if l & 1: lres = self.op(lres, self.data[l]) l += 1 if r & 1: r -= 1 rres = self.op(self.data[r], rres) l >>= 1 r >>= 1 return self.op(lres, rres) import sys input = sys.stdin.readline inf = 10**6 size = 4 N,Q = map(int, input().split()) S = input() alp = {"A":0,"B":1,"C":2,"D":3} p = [0,3,5,6] D = [] for i in range(N): c = alp[S[i]] A = [1]*10 #(0,0-3),(1,1-3) for i in range(4): for j in range(i,4): if i <= c <= j: A[p[i]+j] = 0 D.append(A) def op(X,Y): res = [inf]*10 for i in range(4): for j in range(i,4): for k in range(i,j+1): res[p[i]+j] = min(X[p[i]+k]+Y[p[k]+j],res[p[i]+j]) return res e = [0]*10 st = SegTree(op, e, D) qry = [] for _ in range(Q): t,x,c = input().split() t = int(t) x = int(x)-1 if t == 1: c = alp[c] else: c = int(c) qry.append((t,x,c)) ans = [] for t,x,c in qry: if t == 1: A = [1]*10 for i in range(4): for j in range(i,4): if i <= c <= j: A[p[i]+j] = 0 st.set(x,A) else: res = st.prod(x,c) ans.append(min(res)) print(*ans, sep = "\n")