結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー titiatitia
提出日時 2022-10-15 04:53:15
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,778 bytes
コンパイル時間 448 ms
コンパイル使用メモリ 86,764 KB
実行使用メモリ 368,128 KB
最終ジャッジ日時 2023-09-09 02:09:04
合計ジャッジ時間 77,901 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,240 KB
testcase_01 AC 69 ms
71,468 KB
testcase_02 AC 80 ms
71,396 KB
testcase_03 AC 3,639 ms
280,204 KB
testcase_04 AC 4,402 ms
316,276 KB
testcase_05 AC 2,717 ms
267,368 KB
testcase_06 AC 4,089 ms
305,324 KB
testcase_07 AC 5,060 ms
345,564 KB
testcase_08 AC 4,158 ms
310,952 KB
testcase_09 AC 2,376 ms
267,440 KB
testcase_10 AC 1,911 ms
268,028 KB
testcase_11 AC 2,851 ms
267,356 KB
testcase_12 AC 2,835 ms
267,240 KB
testcase_13 AC 2,193 ms
266,576 KB
testcase_14 AC 965 ms
133,848 KB
testcase_15 AC 5,338 ms
344,808 KB
testcase_16 AC 5,068 ms
319,932 KB
testcase_17 AC 1,036 ms
161,164 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
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
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.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("\n".join(map(str,ANS)))

        
0