結果

問題 No.2942 Sigma Music Game Level Problem
ユーザー timitimi
提出日時 2024-10-18 23:04:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,968 ms / 6,000 ms
コード長 2,457 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 82,852 KB
実行使用メモリ 251,848 KB
最終ジャッジ日時 2024-10-18 23:05:35
合計ジャッジ時間 21,091 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
71,364 KB
testcase_01 AC 55 ms
71,476 KB
testcase_02 AC 53 ms
72,104 KB
testcase_03 AC 52 ms
71,412 KB
testcase_04 AC 54 ms
71,484 KB
testcase_05 AC 56 ms
71,584 KB
testcase_06 AC 52 ms
71,960 KB
testcase_07 AC 69 ms
71,960 KB
testcase_08 AC 95 ms
87,616 KB
testcase_09 AC 82 ms
85,532 KB
testcase_10 AC 73 ms
80,220 KB
testcase_11 AC 667 ms
196,200 KB
testcase_12 AC 1,583 ms
189,068 KB
testcase_13 AC 1,800 ms
136,832 KB
testcase_14 AC 773 ms
216,272 KB
testcase_15 AC 433 ms
206,696 KB
testcase_16 AC 1,634 ms
129,456 KB
testcase_17 AC 368 ms
126,224 KB
testcase_18 AC 1,157 ms
135,308 KB
testcase_19 AC 1,968 ms
163,028 KB
testcase_20 AC 426 ms
182,620 KB
testcase_21 AC 1,846 ms
251,304 KB
testcase_22 AC 1,784 ms
251,848 KB
testcase_23 AC 595 ms
117,636 KB
testcase_24 AC 54 ms
72,292 KB
testcase_25 AC 54 ms
70,816 KB
testcase_26 AC 1,326 ms
207,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=998244353
N,Q,L=map(int, input().split())
A=list(map(int, input().split()))
ans=0

#####segfunc#####
def segfunc(x, y):
    return x+y
#################

#####ide_ele#####
ide_ele = 0
#################

class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(N)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])
    
    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

BB=[0]*(2*10**5+10)
CC=[0]*(2*10**5+10)
for a in A:
  BB[a]+=1
  
for i in range(2*10**5+10):
  CC[i]+=i*BB[i]
  
B= SegTree(BB, segfunc, ide_ele)
C= SegTree(CC, segfunc, ide_ele)

ans=[]
for i in range(Q):
  A=list(map(int, input().split()))
  if A[0]==1:
    _,l=A 
    b,c=B.query(l,l+1),C.query(l,l+1)
    B.update(l,b+1)
    C.update(l,c+l)
  elif A[0]==2:
    _,l,r=A 
    b,c=B.query(l,r+1),C.query(l,r+1)
    ans.append((b,c))

if len(ans)==0:
  print('Not Found!')
else:
  for i in ans:
    print(*i)
0