結果
問題 | No.1441 MErGe |
ユーザー |
|
提出日時 | 2021-02-08 10:58:00 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 522 ms / 1,000 ms |
コード長 | 736 bytes |
コンパイル時間 | 170 ms |
コンパイル使用メモリ | 82,428 KB |
実行使用メモリ | 103,948 KB |
最終ジャッジ日時 | 2024-10-12 06:06:28 |
合計ジャッジ時間 | 11,644 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 28 |
ソースコード
def main(): import sys input=sys.stdin.readline n,q=map(int,input().split()) a=list(map(int,input().split())) #BIT dat=[0]*(n+10) def add(i,a): i+=1 while i<=n: dat[i]+=a i+=i&-i def binary_search(x): i=1 while i*2<=n: i*=2 res=0 while i: if res+i<=n and x>dat[res+i]: x-=dat[res+i] res+=i i//=2 return res for i in range(n): add(i,1) #end for i in range(1,n): a[i]+=a[i-1] for _ in range(q): t,l,r=map(int,input().split()) if t==1: d=r-l for _ in range(d): add(binary_search(l+1),-1) else: R=binary_search(r+1)-1 L=binary_search(l) print(a[R]-(a[L-1] if L!=0 else 0)) main()