結果

問題 No.2942 Sigma Music Game Level Problem
ユーザー titiatitia
提出日時 2024-10-19 03:06:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,523 ms / 6,000 ms
コード長 1,911 bytes
コンパイル時間 683 ms
コンパイル使用メモリ 82,012 KB
実行使用メモリ 268,720 KB
最終ジャッジ日時 2024-10-19 03:07:12
合計ジャッジ時間 19,064 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
127,520 KB
testcase_01 AC 80 ms
126,932 KB
testcase_02 AC 81 ms
127,308 KB
testcase_03 AC 81 ms
126,328 KB
testcase_04 AC 81 ms
126,672 KB
testcase_05 AC 82 ms
127,556 KB
testcase_06 AC 80 ms
127,152 KB
testcase_07 AC 82 ms
128,056 KB
testcase_08 AC 116 ms
142,292 KB
testcase_09 AC 96 ms
136,912 KB
testcase_10 AC 94 ms
134,660 KB
testcase_11 AC 716 ms
265,612 KB
testcase_12 AC 1,337 ms
258,720 KB
testcase_13 AC 1,329 ms
193,392 KB
testcase_14 AC 645 ms
237,820 KB
testcase_15 AC 499 ms
231,772 KB
testcase_16 AC 1,239 ms
186,788 KB
testcase_17 AC 373 ms
199,840 KB
testcase_18 AC 943 ms
217,948 KB
testcase_19 AC 1,523 ms
220,796 KB
testcase_20 AC 523 ms
262,112 KB
testcase_21 AC 1,197 ms
268,720 KB
testcase_22 AC 1,243 ms
268,460 KB
testcase_23 AC 596 ms
170,864 KB
testcase_24 AC 82 ms
127,176 KB
testcase_25 AC 87 ms
128,464 KB
testcase_26 AC 932 ms
236,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from collections import Counter

N,Q,L=map(int,input().split())
A=list(map(int,input().split()))

seg_el=1<<((2000000).bit_length()) # Segment treeの台の要素数
SEG=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
SEG2=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化


def seg_function(x,y): # Segment treeで扱うfunction
    return x+y


C=Counter(A)
for c in C:
    SEG[c+seg_el]=C[c]
    SEG2[c+seg_el]=C[c]*c

for i in range(seg_el-1,0,-1): # 親の部分もupdate
    SEG[i]=seg_function(SEG[i*2],SEG[i*2+1])
    SEG2[i]=seg_function(SEG2[i*2],SEG2[i*2+1])

def update(n,x,seg_el): # A[n]を+x更新
    i=n+seg_el
    SEG[i]+=1
    SEG2[i]+=x
    i>>=1 # 子ノードへ
    
    while i!=0:
        SEG[i]=seg_function(SEG[i*2],SEG[i*2+1])
        SEG2[i]=seg_function(SEG2[i*2],SEG2[i*2+1])
        i>>=1
        
def getvalues(l,r): # 区間[l,r)に関するseg_functionを調べる
    L=l+seg_el
    R=r+seg_el
    ANS1=0
    ANS2=0

    while L<R:
        if L & 1:
            ANS1=seg_function(ANS1, SEG[L])
            L+=1

        if R & 1:
            R-=1
            ANS2=seg_function(SEG[R], ANS2)
        L>>=1
        R>>=1

    L=l+seg_el
    R=r+seg_el
    ANS3=0
    ANS4=0

    while L<R:
        if L & 1:
            ANS3=seg_function(ANS3, SEG2[L])
            L+=1

        if R & 1:
            R-=1
            ANS4=seg_function(SEG2[R], ANS4)
        L>>=1
        R>>=1

    return seg_function(ANS1, ANS2),seg_function(ANS3, ANS4)

flag=0
for tests in range(Q):
    L=list(map(int,input().split()))

    if L[0]==1:
        x=L[1]
        A.append(x)

        update(x,x,seg_el)

    elif L[0]==2:
        flag+=1
        l,r=L[1],L[2]

        ANS=getvalues(l,r+1)
        print(*ANS)

if flag==0:
    print("Not Found!")

        
    


0