結果

問題 No.2942 Sigma Music Game Level Problem
ユーザー hiro1729hiro1729
提出日時 2024-10-18 22:01:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,472 ms / 6,000 ms
コード長 1,087 bytes
コンパイル時間 429 ms
コンパイル使用メモリ 82,276 KB
実行使用メモリ 230,452 KB
最終ジャッジ日時 2024-10-18 22:44:58
合計ジャッジ時間 3,534 ms
ジャッジサーバーID
(参考情報)
judge1 / judge6
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
71,912 KB
testcase_01 AC 125 ms
71,412 KB
testcase_02 AC 80 ms
71,880 KB
testcase_03 AC 78 ms
71,808 KB
testcase_04 AC 82 ms
70,384 KB
testcase_05 AC 80 ms
72,076 KB
testcase_06 AC 78 ms
70,580 KB
testcase_07 AC 84 ms
74,740 KB
testcase_08 AC 113 ms
81,452 KB
testcase_09 AC 94 ms
77,864 KB
testcase_10 AC 93 ms
77,672 KB
testcase_11 AC 1,506 ms
167,788 KB
testcase_12 AC 3,148 ms
209,408 KB
testcase_13 AC 3,083 ms
122,792 KB
testcase_14 AC 1,368 ms
198,332 KB
testcase_15 AC 1,077 ms
230,452 KB
testcase_16 AC 2,760 ms
102,408 KB
testcase_17 AC 717 ms
139,100 KB
testcase_18 AC 2,111 ms
144,828 KB
testcase_19 AC 3,472 ms
145,328 KB
testcase_20 AC 1,042 ms
156,196 KB
testcase_21 AC 2,349 ms
216,120 KB
testcase_22 AC 2,238 ms
216,160 KB
testcase_23 AC 1,322 ms
112,724 KB
testcase_24 AC 75 ms
72,448 KB
testcase_25 AC 72 ms
70,264 KB
testcase_26 AC 2,523 ms
218,732 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, L0 = map(int, input().split())
A = list(map(int, input().split()))
f = FenwickTree(200001)
fi = FenwickTree(200001)
for i in A:
	f.add(i, 1)
	fi.add(i, i)
c = 0
for _ in range(Q):
	t, *q = map(int, input().split())
	if t == 1:
		l = q[0]
		f.add(l, 1)
		fi.add(l, l)
	if t == 2:
		c += 1
		l, r = q
		print(f.sum(l, r + 1), fi.sum(l, r + 1))
	if t == 3:
		m = q[0]
if c == 0:
	print("Not Found!")
0