結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー titiatitia
提出日時 2022-10-15 04:45:19
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,779 bytes
コンパイル時間 737 ms
コンパイル使用メモリ 85,720 KB
実行使用メモリ 310,364 KB
最終ジャッジ日時 2023-09-09 02:05:51
合計ジャッジ時間 34,454 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,496 KB
testcase_01 AC 81 ms
71,512 KB
testcase_02 AC 77 ms
71,616 KB
testcase_03 AC 5,006 ms
272,340 KB
testcase_04 TLE -
testcase_05 AC 3,739 ms
268,856 KB
testcase_06 AC 5,570 ms
281,500 KB
testcase_07 TLE -
testcase_08 AC 5,654 ms
285,424 KB
testcase_09 AC 3,331 ms
268,080 KB
testcase_10 AC 2,756 ms
266,248 KB
testcase_11 AC 3,877 ms
267,884 KB
testcase_12 AC 3,882 ms
267,604 KB
testcase_13 AC 2,959 ms
266,204 KB
testcase_14 AC 1,368 ms
125,684 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.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.sort(key=len)
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)

        #print(x,y,z)

        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(q)
    #print(SEG)
        
        

for ans in ANS:
    print(ans)

        
0