結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー titiatitia
提出日時 2022-10-15 05:05:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 4,829 ms / 6,000 ms
コード長 1,753 bytes
コンパイル時間 666 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 363,308 KB
最終ジャッジ日時 2024-04-29 22:55:55
合計ジャッジ時間 141,484 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,992 KB
testcase_01 AC 46 ms
52,864 KB
testcase_02 AC 43 ms
52,864 KB
testcase_03 AC 2,509 ms
283,392 KB
testcase_04 AC 3,275 ms
329,800 KB
testcase_05 AC 2,118 ms
281,252 KB
testcase_06 AC 2,935 ms
307,792 KB
testcase_07 AC 3,809 ms
350,344 KB
testcase_08 AC 3,135 ms
308,160 KB
testcase_09 AC 1,940 ms
270,548 KB
testcase_10 AC 1,437 ms
225,536 KB
testcase_11 AC 2,126 ms
274,892 KB
testcase_12 AC 2,196 ms
263,444 KB
testcase_13 AC 1,544 ms
227,708 KB
testcase_14 AC 809 ms
125,592 KB
testcase_15 AC 4,038 ms
362,812 KB
testcase_16 AC 3,620 ms
358,392 KB
testcase_17 AC 723 ms
133,600 KB
testcase_18 AC 4,772 ms
360,532 KB
testcase_19 AC 4,686 ms
359,716 KB
testcase_20 AC 4,575 ms
360,224 KB
testcase_21 AC 4,568 ms
361,120 KB
testcase_22 AC 4,579 ms
360,740 KB
testcase_23 AC 4,507 ms
360,484 KB
testcase_24 AC 4,532 ms
360,736 KB
testcase_25 AC 4,505 ms
360,876 KB
testcase_26 AC 4,558 ms
360,736 KB
testcase_27 AC 4,829 ms
359,244 KB
testcase_28 AC 4,505 ms
360,224 KB
testcase_29 AC 4,559 ms
361,120 KB
testcase_30 AC 4,543 ms
360,364 KB
testcase_31 AC 4,586 ms
361,008 KB
testcase_32 AC 4,558 ms
359,332 KB
testcase_33 AC 4,184 ms
360,624 KB
testcase_34 AC 4,127 ms
360,496 KB
testcase_35 AC 4,155 ms
363,308 KB
testcase_36 AC 4,112 ms
360,628 KB
testcase_37 AC 4,202 ms
361,648 KB
testcase_38 AC 270 ms
108,912 KB
testcase_39 AC 826 ms
148,240 KB
testcase_40 AC 1,386 ms
319,564 KB
testcase_41 AC 43 ms
52,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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[0]+y[0],x[1]+y[1],x[2]+y[2]]

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)))

        
0