結果

問題 No.2942 Sigma Music Game Level Problem
ユーザー tassei903tassei903
提出日時 2024-10-18 21:55:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,716 ms / 6,000 ms
コード長 2,021 bytes
コンパイル時間 696 ms
コンパイル使用メモリ 82,092 KB
実行使用メモリ 246,972 KB
最終ジャッジ日時 2024-10-18 22:43:29
合計ジャッジ時間 3,771 ms
ジャッジサーバーID
(参考情報)
judge5 / judge6
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
59,552 KB
testcase_01 AC 60 ms
59,068 KB
testcase_02 AC 42 ms
59,412 KB
testcase_03 AC 42 ms
60,416 KB
testcase_04 AC 43 ms
61,256 KB
testcase_05 AC 43 ms
59,780 KB
testcase_06 AC 43 ms
60,388 KB
testcase_07 AC 49 ms
67,236 KB
testcase_08 AC 65 ms
75,088 KB
testcase_09 AC 57 ms
70,488 KB
testcase_10 AC 55 ms
71,148 KB
testcase_11 AC 873 ms
190,804 KB
testcase_12 AC 1,621 ms
183,728 KB
testcase_13 AC 1,417 ms
120,088 KB
testcase_14 AC 810 ms
221,080 KB
testcase_15 AC 703 ms
200,964 KB
testcase_16 AC 1,316 ms
106,052 KB
testcase_17 AC 425 ms
120,452 KB
testcase_18 AC 1,070 ms
128,652 KB
testcase_19 AC 1,704 ms
138,688 KB
testcase_20 AC 630 ms
177,204 KB
testcase_21 AC 1,709 ms
245,804 KB
testcase_22 AC 1,716 ms
246,972 KB
testcase_23 AC 576 ms
112,640 KB
testcase_24 AC 41 ms
60,032 KB
testcase_25 AC 41 ms
59,352 KB
testcase_26 AC 1,193 ms
202,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################


# Binary Indexed Tree (Fenwick Tree)
# 0-indexed
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x):
        assert 0 <= i < self.n
        i = i+1
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    def set(self, i, x):
        assert 0 <= i <= self.n
        self.add(i,x-self.get(i))
    def get(self, i, j=None):# j=Noneのときiを取得, [i, j)の和を取得
        if j is None:
            return self.el[i+1]
        return self.sum(j) - self.sum(i)
    def lower_bound(self, k):# a[0],…,a[i]>kなる最小のi
        n = self.n
        x = 0
        r = 1
        while r <= n:r <<= 1
        size = r
        while size:
            if x + size <= n and self.data[x+size] <= k:
                k-=self.data[x+size]
                x += size
            size >>= 1
        return x
    def debug(self):
        res = []
        n = self.n
        for i in range(n):
            res.append(self.get(i))
        print(*res)

m = 2 * 10 ** 5 + 10

n, q, _ = na()
a = na()

bit1 = BIT(m)
bit2 = BIT(m)
FLAG = 0
for i in range(n):
    bit1.add(a[i], 1)
    bit2.add(a[i], a[i])

for _ in range(q):
    que = na()
    if que[0] == 1:
        l = que[1]
        bit1.add(l, 1)
        bit2.add(l, l)
    elif que[0] == 2:
        FLAG = 1
        l, r = que[1], que[2] + 1
        print(bit1.get(l, r), bit2.get(l, r))
    else:
        continue

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