結果

問題 No.2942 Sigma Music Game Level Problem
ユーザー kazuppakazuppa
提出日時 2024-10-05 23:00:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,795 ms / 6,000 ms
コード長 1,040 bytes
コンパイル時間 473 ms
コンパイル使用メモリ 82,512 KB
実行使用メモリ 230,112 KB
最終ジャッジ日時 2024-10-06 10:50:21
合計ジャッジ時間 28,112 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
70,016 KB
testcase_01 AC 62 ms
69,760 KB
testcase_02 AC 62 ms
69,760 KB
testcase_03 AC 68 ms
70,144 KB
testcase_04 AC 64 ms
70,528 KB
testcase_05 AC 63 ms
70,272 KB
testcase_06 AC 64 ms
70,272 KB
testcase_07 AC 66 ms
72,704 KB
testcase_08 AC 98 ms
80,968 KB
testcase_09 AC 82 ms
77,312 KB
testcase_10 AC 80 ms
77,440 KB
testcase_11 AC 1,062 ms
167,716 KB
testcase_12 AC 2,396 ms
209,240 KB
testcase_13 AC 2,443 ms
122,532 KB
testcase_14 AC 1,153 ms
197,480 KB
testcase_15 AC 790 ms
230,112 KB
testcase_16 AC 2,300 ms
102,392 KB
testcase_17 AC 585 ms
138,576 KB
testcase_18 AC 1,695 ms
144,736 KB
testcase_19 AC 2,795 ms
145,408 KB
testcase_20 AC 742 ms
155,828 KB
testcase_21 AC 1,806 ms
216,128 KB
testcase_22 AC 1,781 ms
216,376 KB
testcase_23 AC 997 ms
112,252 KB
testcase_24 AC 63 ms
70,272 KB
testcase_25 AC 64 ms
69,760 KB
testcase_26 AC 2,267 ms
218,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import typing


class FenwickTree:
    '''Reference: https://en.wikipedia.org/wiki/Fenwick_tree'''

    def __init__(self, n: int = 0) -> None:
        self._n = n
        self.data = [0] * n

    def add(self, p: int, x: typing.Any) -> None:
        assert 0 <= p < self._n

        p += 1
        while p <= self._n:
            self.data[p - 1] += x
            p += p & -p

    def sum(self, left: int, right: int) -> typing.Any:
        assert 0 <= left <= right <= self._n

        return self._sum(right) - self._sum(left)

    def _sum(self, r: int) -> typing.Any:
        s = 0
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r

        return s

N,Q,L=map(int,input().split())
A=list(map(int,input().split()))
f1=FenwickTree(200001)
f2=FenwickTree(200001)
for i in A:
	f1.add(i,1)
	f2.add(i,i)
flg=True
for i in range(Q):
	t,*q=list(map(int,input().split()))
	if t==1:
		l=q[0]
		f1.add(l,1)
		f2.add(l,l)
	if t==2:
		flg=False
		l,r=q
		print(f1.sum(l,r+1),f2.sum(l,r+1))
if flg:
	print("Not Found!")
0