結果
問題 | No.2992 Range ABCD String Query |
ユーザー | lif4635 |
提出日時 | 2024-12-15 12:07:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 4,430 ms / 6,000 ms |
コード長 | 2,297 bytes |
コンパイル時間 | 383 ms |
コンパイル使用メモリ | 82,916 KB |
実行使用メモリ | 334,752 KB |
最終ジャッジ日時 | 2024-12-16 23:41:16 |
合計ジャッジ時間 | 110,647 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 709 ms
114,108 KB |
testcase_01 | AC | 630 ms
113,408 KB |
testcase_02 | AC | 836 ms
115,444 KB |
testcase_03 | AC | 738 ms
114,940 KB |
testcase_04 | AC | 955 ms
117,036 KB |
testcase_05 | AC | 792 ms
114,668 KB |
testcase_06 | AC | 844 ms
115,352 KB |
testcase_07 | AC | 496 ms
111,688 KB |
testcase_08 | AC | 1,003 ms
117,948 KB |
testcase_09 | AC | 812 ms
114,360 KB |
testcase_10 | AC | 3,878 ms
308,888 KB |
testcase_11 | AC | 3,713 ms
306,100 KB |
testcase_12 | AC | 3,894 ms
307,072 KB |
testcase_13 | AC | 3,838 ms
296,680 KB |
testcase_14 | AC | 3,742 ms
294,604 KB |
testcase_15 | AC | 3,742 ms
294,648 KB |
testcase_16 | AC | 3,562 ms
269,612 KB |
testcase_17 | AC | 4,052 ms
315,048 KB |
testcase_18 | AC | 3,801 ms
294,200 KB |
testcase_19 | AC | 4,131 ms
315,880 KB |
testcase_20 | AC | 2,975 ms
318,796 KB |
testcase_21 | AC | 2,946 ms
320,128 KB |
testcase_22 | AC | 3,019 ms
319,828 KB |
testcase_23 | AC | 2,951 ms
318,792 KB |
testcase_24 | AC | 2,942 ms
318,928 KB |
testcase_25 | AC | 4,349 ms
334,752 KB |
testcase_26 | AC | 4,331 ms
334,164 KB |
testcase_27 | AC | 4,398 ms
334,468 KB |
testcase_28 | AC | 4,371 ms
333,952 KB |
testcase_29 | AC | 4,430 ms
334,720 KB |
testcase_30 | AC | 3,268 ms
269,128 KB |
testcase_31 | AC | 3,170 ms
268,924 KB |
testcase_32 | AC | 3,184 ms
269,012 KB |
testcase_33 | AC | 3,161 ms
268,968 KB |
testcase_34 | AC | 3,105 ms
268,828 KB |
testcase_35 | AC | 3,078 ms
222,648 KB |
testcase_36 | AC | 3,079 ms
222,640 KB |
testcase_37 | AC | 343 ms
110,764 KB |
testcase_38 | AC | 431 ms
111,928 KB |
testcase_39 | AC | 492 ms
112,416 KB |
testcase_40 | AC | 505 ms
112,564 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} D = [] for i in range(N): c = alp[S[i]] A = [inf]*16 for i in range(4): for j in range(i,4): if i <= c <= j: A[i*size+j] = 0 else: A[i*size+j] = 1 D.append(A) def op(X,Y): res = [inf]*16 for i in range(4): for j in range(i,4): for k in range(i,j+1): res[i*size+j] = min(X[i*size+k]+Y[k*size+j],res[i*size+j]) return res e = [0]*16 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 = [inf]*16 for i in range(4): for j in range(i,4): if i <= c <= j: A[i*size+j] = 0 else: A[i*size+j] = 1 st.set(x,A) else: res = st.prod(x,c) ans.append(min(res)) print(*ans, sep = "\n")