結果

問題 No.2942 Sigma Music Game Level Problem
ユーザー ルクルク
提出日時 2024-10-18 23:09:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,601 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 82,512 KB
実行使用メモリ 191,196 KB
最終ジャッジ日時 2024-10-18 23:09:34
合計ジャッジ時間 10,689 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,564 KB
testcase_01 AC 38 ms
53,104 KB
testcase_02 AC 39 ms
53,724 KB
testcase_03 AC 37 ms
53,092 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 50 ms
54,508 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left, bisect_right, insort

# セグメントツリー用の関数
def op(a, b):
    return a + b

def e():
    return 0

class SegTree:
    def __init__(self, n):
        self.n = n
        self.data = [e()] * (2 * n)

    def set(self, p, value):
        # Set value at position p
        p += self.n
        self.data[p] = value
        while p > 1:
            p //= 2
            self.data[p] = op(self.data[2 * p], self.data[2 * p + 1])

    def prod(self, l, r):
        # Product from index l to r-1
        res = e()
        l += self.n
        r += self.n
        while l < r:
            if l % 2 == 1:
                res = op(res, self.data[l])
                l += 1
            if r % 2 == 1:
                r -= 1
                res = op(res, self.data[r])
            l //= 2
            r //= 2
        return res

def main():
    n, q, nowL = map(int, input().split())
    a = []
    b = []
    x = list(map(int,input().split()))

    for _ in range(n):
        insort(b, x[_])  # SortedListの代わりにinsortを使用
        insort(a, (x[_], 0))

    isNotFound = True
    query = []

    for _ in range(q):
        t,*cmd=list(map(int,input().split()))
        if t == 1:
            l = cmd[0]
            query.append([t, l])
            insort(a, (l, len(query)))
        elif t == 2:
            l, r = cmd[0:]
            query.append([t, l, r])
            isNotFound = False
        else:
            m = cmd[0]
            query.append([t, m])

    if isNotFound:
        print("Not Found!")
        return

    idx = []
    schedule = []
    i = 0

    for x, y in a:
        i += 1
        idx.append([y, i, x])
        schedule.append(x)

    idx.reverse()
    segArr = [0] * len(idx)

    while idx:
        if idx[-1][0] != 0:
            break
        segArr[idx[-1][1] - 1] = idx[-1][2]
        idx.pop()

    seg = SegTree(len(segArr))

    for i, value in enumerate(segArr):
        seg.set(i, value)

    for q in query:
        if q[0] == 1:
            x = idx.pop()
            seg.set(x[1] - 1, x[2])
            insort(b, x[2])  # SortedListの代わりにinsortを使用
        elif q[0] == 2:
            l = q[1]
            r = q[2]
            left = bisect_left(schedule, l)
            right = bisect_right(schedule, r)
            l2 = bisect_left(b, l)  # SortedListの代わりにbisect_leftを使用
            r2 = bisect_right(b, r)  # SortedListの代わりにbisect_rightを使用
            print(r2 - l2, seg.prod(left, right))
        else:
            nowL = q[1]

if __name__ == "__main__":
    main()
0