結果

問題 No.2942 Sigma Music Game Level Problem
ユーザー ルクルク
提出日時 2024-10-18 23:06:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 2,448 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-10-18 23:07:13
合計ジャッジ時間 3,618 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left, bisect_right
from sortedcontainers import SortedList

# セグメントツリー用の関数
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 = SortedList()
    b = SortedList()
    x = list(map(int,input().split()))

    for _ in range(n):
        b.add(x[_])
        a.add((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])
            a.add((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])
            b.add(x[2])
        elif q[0] == 2:
            l = q[1]
            r = q[2]
            left = bisect_left(schedule, l)
            right = bisect_right(schedule, r)
            l2 = b.bisect_left(l)
            r2 = b.bisect_right(r)
            print(r2 - l2, seg.prod(left, right))
        else:
            nowL = q[1]

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