結果
問題 | No.2992 Range ABCD String Query |
ユーザー | Iroha_3856 |
提出日時 | 2024-12-15 11:06:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 4,571 ms / 6,000 ms |
コード長 | 3,462 bytes |
コンパイル時間 | 480 ms |
コンパイル使用メモリ | 82,716 KB |
実行使用メモリ | 297,640 KB |
最終ジャッジ日時 | 2024-12-16 23:37:57 |
合計ジャッジ時間 | 112,053 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 684 ms
87,136 KB |
testcase_01 | AC | 647 ms
86,716 KB |
testcase_02 | AC | 846 ms
89,708 KB |
testcase_03 | AC | 868 ms
87,896 KB |
testcase_04 | AC | 928 ms
91,892 KB |
testcase_05 | AC | 833 ms
88,248 KB |
testcase_06 | AC | 862 ms
89,216 KB |
testcase_07 | AC | 464 ms
85,260 KB |
testcase_08 | AC | 1,000 ms
92,172 KB |
testcase_09 | AC | 751 ms
88,668 KB |
testcase_10 | AC | 4,135 ms
271,720 KB |
testcase_11 | AC | 3,809 ms
272,600 KB |
testcase_12 | AC | 3,931 ms
271,864 KB |
testcase_13 | AC | 4,069 ms
272,108 KB |
testcase_14 | AC | 4,035 ms
272,228 KB |
testcase_15 | AC | 3,851 ms
272,304 KB |
testcase_16 | AC | 3,391 ms
267,936 KB |
testcase_17 | AC | 3,914 ms
276,420 KB |
testcase_18 | AC | 3,835 ms
270,976 KB |
testcase_19 | AC | 3,911 ms
276,540 KB |
testcase_20 | AC | 3,007 ms
280,372 KB |
testcase_21 | AC | 3,016 ms
279,348 KB |
testcase_22 | AC | 3,001 ms
279,588 KB |
testcase_23 | AC | 3,006 ms
280,240 KB |
testcase_24 | AC | 3,002 ms
279,416 KB |
testcase_25 | AC | 4,441 ms
297,640 KB |
testcase_26 | AC | 4,387 ms
296,796 KB |
testcase_27 | AC | 4,570 ms
297,032 KB |
testcase_28 | AC | 4,571 ms
297,220 KB |
testcase_29 | AC | 4,388 ms
296,712 KB |
testcase_30 | AC | 3,396 ms
246,648 KB |
testcase_31 | AC | 3,379 ms
246,516 KB |
testcase_32 | AC | 3,204 ms
247,344 KB |
testcase_33 | AC | 2,980 ms
247,272 KB |
testcase_34 | AC | 3,137 ms
246,800 KB |
testcase_35 | AC | 3,150 ms
203,760 KB |
testcase_36 | AC | 3,125 ms
203,608 KB |
testcase_37 | AC | 328 ms
83,156 KB |
testcase_38 | AC | 430 ms
84,396 KB |
testcase_39 | AC | 499 ms
85,120 KB |
testcase_40 | AC | 473 ms
85,420 KB |
ソースコード
class segtree(): n=1 size=1 log=2 d=[0] op=None e=10**15 def __init__(self,V,OP,E): self.n=len(V) self.op=OP self.e=E self.log=(self.n-1).bit_length() self.size=1<<self.log self.d=[E for i in range(2*self.size)] for i in range(self.n): self.d[self.size+i]=V[i] for i in range(self.size-1,0,-1): self.update(i) def set(self,p,x): assert 0<=p and p<self.n p+=self.size self.d[p]=x for i in range(1,self.log+1): self.update(p>>i) def get(self,p): assert 0<=p and p<self.n return self.d[p+self.size] def prod(self,l,r): assert 0<=l and l<=r and r<=self.n sml=self.e smr=self.e l+=self.size r+=self.size while(l<r): if (l&1): sml=self.op(sml,self.d[l]) l+=1 if (r&1): smr=self.op(self.d[r-1],smr) r-=1 l>>=1 r>>=1 return self.op(sml,smr) def all_prod(self): return self.d[1] def max_right(self,l,f): assert 0<=l and l<=self.n assert f(self.e) if l==self.n: return self.n l+=self.size sm=self.e while(1): while(l%2==0): l>>=1 if not(f(self.op(sm,self.d[l]))): while(l<self.size): l=2*l if f(self.op(sm,self.d[l])): sm=self.op(sm,self.d[l]) l+=1 return l-self.size sm=self.op(sm,self.d[l]) l+=1 if (l&-l)==l: break return self.n def min_left(self,r,f): assert 0<=r and r<=self.n assert f(self.e) if r==0: return 0 r+=self.size sm=self.e while(1): r-=1 while(r>1 and (r%2)): r>>=1 if not(f(self.op(self.d[r],sm))): while(r<self.size): r=(2*r+1) if f(self.op(self.d[r],sm)): sm=self.op(self.d[r],sm) r-=1 return r+1-self.size sm=self.op(self.d[r],sm) if (r& -r)==r: break return 0 def update(self,k): self.d[k]=self.op(self.d[2*k],self.d[2*k+1]) def __str__(self): return str([self.get(i) for i in range(self.n)]) import sys input = sys.stdin.readline inf = 10**6 size = 4 N,Q = map(int, input().split()) S = input()[:N] alp = {"A":0,"B":1,"C":2,"D":3} def make_matrix(c): x = alp[c] A = [inf]*16 for i in range(4): for j in range(i,4): if i <= x <= j: A[i*size+j] = 0 else: A[i*size+j] = 1 return A D = [] for i in range(N): D.append(make_matrix(S[i])) 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(D, op, e) for _ in range(Q): t,x,c = input().split() if t == "1": x = int(x)-1 st.set(x,make_matrix(c)) else: l,r = int(x)-1,int(c) res = st.prod(l,r) print(min(res))