結果
問題 | No.876 Range Compress Query |
ユーザー | titia |
提出日時 | 2019-09-07 20:51:49 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 670 ms / 2,000 ms |
コード長 | 1,338 bytes |
コンパイル時間 | 93 ms |
コンパイル使用メモリ | 11,136 KB |
実行使用メモリ | 37,176 KB |
最終ジャッジ日時 | 2023-09-09 11:12:27 |
合計ジャッジ時間 | 6,967 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
8,240 KB |
testcase_01 | AC | 20 ms
8,084 KB |
testcase_02 | AC | 17 ms
8,128 KB |
testcase_03 | AC | 21 ms
8,120 KB |
testcase_04 | AC | 18 ms
8,140 KB |
testcase_05 | AC | 18 ms
8,192 KB |
testcase_06 | AC | 19 ms
8,128 KB |
testcase_07 | AC | 19 ms
8,192 KB |
testcase_08 | AC | 19 ms
8,124 KB |
testcase_09 | AC | 19 ms
8,188 KB |
testcase_10 | AC | 19 ms
8,128 KB |
testcase_11 | AC | 628 ms
36,080 KB |
testcase_12 | AC | 502 ms
31,708 KB |
testcase_13 | AC | 520 ms
31,860 KB |
testcase_14 | AC | 618 ms
35,804 KB |
testcase_15 | AC | 458 ms
29,264 KB |
testcase_16 | AC | 636 ms
35,768 KB |
testcase_17 | AC | 635 ms
36,052 KB |
testcase_18 | AC | 670 ms
37,176 KB |
ソースコード
import sys input = sys.stdin.readline N,Q=map(int,input().split()) A=list(map(int,input().split())) Query=[list(map(int,input().split())) for i in range(Q)] B=[A[i]-A[i-1] for i in range(1,N)]+[0] A=[0 if B[i]==0 else 1 for i in range(N)] # BIT(BIT-indexed tree) LEN=len(A)# 必要なら座標圧縮する BIT=[0]*(LEN+1)# 1-indexedなtree def update(v,w):# index vにwを加える while v<=LEN: BIT[v]+=w v+=(v&(-v))# 自分を含む大きなノードへ. たとえばv=3→v=4 def getvalue(v):# [1,v]の区間の和を求める ANS=0 while v!=0: ANS+=BIT[v] v-=(v&(-v))# 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ return ANS for i in range(N-1): if B[i]!=0: update(i+1,1) for q in Query: if q[0]==1: i,l,r,x=q B[l-2]+=x B[r-1]-=x if A[l-2]==0 and B[l-2]!=0: A[l-2]=1 if l!=1: update(l-1,1) elif A[l-2]==1 and B[l-2]==0: A[l-2]=0 if l!=1: update(l-1,-1) if A[r-1]==0 and B[r-1]!=0: A[r-1]=1 update(r,1) elif A[r-1]==1 and B[r-1]==0: A[r-1]=0 update(r,-1) else: i,l,r=q print(getvalue(r-1)-getvalue(l-1)+1)