結果
問題 | No.2611 Count 01 |
ユーザー | titia |
提出日時 | 2024-03-13 04:57:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,521 ms / 6,000 ms |
コード長 | 2,208 bytes |
コンパイル時間 | 485 ms |
コンパイル使用メモリ | 81,700 KB |
実行使用メモリ | 268,408 KB |
最終ジャッジ日時 | 2024-03-13 04:57:57 |
合計ジャッジ時間 | 47,189 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
53,460 KB |
testcase_01 | AC | 35 ms
53,460 KB |
testcase_02 | AC | 41 ms
59,324 KB |
testcase_03 | AC | 2,521 ms
268,024 KB |
testcase_04 | AC | 2,184 ms
267,888 KB |
testcase_05 | AC | 2,118 ms
268,272 KB |
testcase_06 | AC | 2,108 ms
268,276 KB |
testcase_07 | AC | 2,071 ms
267,764 KB |
testcase_08 | AC | 2,018 ms
268,276 KB |
testcase_09 | AC | 2,137 ms
267,896 KB |
testcase_10 | AC | 2,023 ms
268,148 KB |
testcase_11 | AC | 2,000 ms
268,408 KB |
testcase_12 | AC | 2,038 ms
268,152 KB |
testcase_13 | AC | 2,042 ms
268,148 KB |
testcase_14 | AC | 2,075 ms
268,276 KB |
testcase_15 | AC | 2,111 ms
267,764 KB |
testcase_16 | AC | 2,064 ms
268,400 KB |
testcase_17 | AC | 2,059 ms
267,888 KB |
testcase_18 | AC | 2,114 ms
267,896 KB |
testcase_19 | AC | 2,039 ms
268,400 KB |
testcase_20 | AC | 1,980 ms
267,892 KB |
testcase_21 | AC | 2,071 ms
268,276 KB |
testcase_22 | AC | 2,117 ms
268,404 KB |
ソースコード
import sys input = sys.stdin.readline N,Q=map(int,input().split()) A=list(map(int,list(input().strip()))) mod=998244353 def seg_function(x,y): # Segment treeで扱うfunction ANS=[0,0,0,0,0,0,0,0,0,0] ANS[0]=x[0]+y[0] ANS[1]=x[1]+y[1] ANS[2]=x[2]+y[2] ANS[3]=x[3]+y[3]+x[9]*y[2]+y[6]*x[2]+x[7]*y[5]+x[8]*y[4] ANS[4]=x[4]+y[4]+x[0]*y[2] ANS[5]=x[5]+y[5]+x[1]*y[2] ANS[6]=x[6]+y[6]+x[0]*x[1]*y[2]+x[0]*y[5]+x[1]*y[4] ANS[7]=x[7]+y[7]+y[0]*x[2] ANS[8]=x[8]+y[8]+y[1]*x[2] ANS[9]=x[9]+y[9]+y[0]*y[1]*x[2]+y[0]*x[8]+y[1]*x[7] for i in range(10): ANS[i]%=mod return ANS seg_el=1<<(N.bit_length()) # Segment treeの台の要素数 SEG=[[0,0,0,0,0,0,0,0,0,0] for i in range(2*seg_el)] # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化 # 0の個数, 1の個数, 長さ, score, 左から見て累積0の個数の和,累積1の個数の和,その積の和,右から見て累積0の個数の和,累積1の個数の和,その積の和, for i in range(N): # Aを対応する箇所へupdate if A[i]==0: SEG[i+seg_el]=[1,0,1,0,1,0,0,1,0,0] else: SEG[i+seg_el]=[0,1,1,0,0,1,0,0,1,0] for i in range(seg_el-1,0,-1): # 親の部分もupdate SEG[i]=seg_function(SEG[i*2],SEG[i*2+1]) def update(n,x,seg_el): # A[n]をxへ更新 i=n+seg_el if x==0: SEG[i]=[1,0,1,0,1,0,0,1,0,0] else: SEG[i]=[0,1,1,0,0,1,0,0,1,0] i>>=1 # 子ノードへ while i!=0: SEG[i]=seg_function(SEG[i*2],SEG[i*2+1]) i>>=1 def getvalues(l,r): # 区間[l,r)に関するseg_functionを調べる L=l+seg_el R=r+seg_el ANS1=[0,0,0,0,0,0,0,0,0,0] ANS2=[0,0,0,0,0,0,0,0,0,0] while L<R: if L & 1: ANS1=seg_function(ANS1, SEG[L]) L+=1 if R & 1: R-=1 ANS2=seg_function(SEG[R], ANS2) L>>=1 R>>=1 return seg_function(ANS1, ANS2) for queries in range(Q): L=list(map(int,input().split())) if L[0]==1: x=L[1]-1 A[x]^=1 update(x,A[x],seg_el) else: x,y=L[1],L[2] print(getvalues(x-1,y)[3])