結果
問題 | No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに |
ユーザー | titia |
提出日時 | 2022-10-15 04:55:15 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,751 bytes |
コンパイル時間 | 265 ms |
コンパイル使用メモリ | 87,156 KB |
実行使用メモリ | 344,612 KB |
最終ジャッジ日時 | 2023-09-09 02:10:57 |
合計ジャッジ時間 | 72,009 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 74 ms
71,328 KB |
testcase_01 | AC | 73 ms
71,324 KB |
testcase_02 | AC | 74 ms
71,404 KB |
testcase_03 | AC | 3,936 ms
278,172 KB |
testcase_04 | AC | 5,064 ms
316,732 KB |
testcase_05 | AC | 3,136 ms
267,484 KB |
testcase_06 | AC | 4,854 ms
306,368 KB |
testcase_07 | TLE | - |
testcase_08 | AC | 5,172 ms
310,952 KB |
testcase_09 | AC | 2,971 ms
267,944 KB |
testcase_10 | AC | 2,602 ms
267,740 KB |
testcase_11 | AC | 3,355 ms
267,676 KB |
testcase_12 | AC | 3,458 ms
267,744 KB |
testcase_13 | AC | 2,554 ms
266,492 KB |
testcase_14 | AC | 1,238 ms
133,504 KB |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | AC | 1,283 ms
160,728 KB |
testcase_18 | TLE | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
ソースコード
import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from operator import itemgetter N=int(input()) AT=[list(map(int,input().split())) for i in range(N)] Q=int(input()) QU=[list(map(int,input().split()))+[i] for i in range(Q)] # Segment tree(1-indexed,再帰を使わないもの) def seg_function(x,y): # Segment treeで扱うfunction return [x[i]+y[i] for i in range(3)] seg_el=1<<(N.bit_length()) # Segment treeの台の要素数 SEG=[[0,0,0] for i in range(2*seg_el)] # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化 for i in range(N): # Aを対応する箇所へupdate SEG[i+seg_el]=[AT[i][0],0,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 SEG[i]=x 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 ANS=[0,0,0] while L<R: if L & 1: ANS=seg_function(ANS , SEG[L]) L+=1 if R & 1: R-=1 ANS=seg_function(ANS , SEG[R]) L>>=1 R>>=1 return ANS for i in range(N): a,t=AT[i] if a==0: continue QU.append([t,a,i]) QU.append([t+a,i]) QU.reverse() QU.sort(key=itemgetter(0)) ANS=[-1]*Q for q in QU: if len(q)==4: d,l,r,ind=q x,y,z=getvalues(l-1,r) ANS[ind]=x-d*z+y elif len(q)==3: t,a,i=q update(i,[a,t-1,1],seg_el) else: t,i=q update(i,[0,0,0],seg_el) print("\n".join(map(str,ANS)))