結果

問題 No.2942 Sigma Music Game Level Problem
ユーザー noriaokinoriaoki
提出日時 2024-10-18 23:59:39
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,784 bytes
コンパイル時間 614 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 280,712 KB
最終ジャッジ日時 2024-11-07 22:06:34
合計ジャッジ時間 16,119 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
53,248 KB
testcase_01 AC 42 ms
52,864 KB
testcase_02 AC 45 ms
52,736 KB
testcase_03 AC 43 ms
52,480 KB
testcase_04 AC 44 ms
52,992 KB
testcase_05 AC 44 ms
52,864 KB
testcase_06 AC 44 ms
52,992 KB
testcase_07 AC 56 ms
62,336 KB
testcase_08 AC 114 ms
76,928 KB
testcase_09 AC 84 ms
71,296 KB
testcase_10 AC 74 ms
68,608 KB
testcase_11 AC 5,601 ms
280,712 KB
testcase_12 TLE -
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 #

# https://maspypy.com/segment-tree-%E3%81%AE%E3%81%8A%E5%8B%89%E5%BC%B71

class SegmentTree():
    def __init__(self, N: int, func, unit: int = 0):
        self.N = N
        self.X_unit = unit
        self.X = [self.X_unit] * (2*self.N)
        self.X_f = func

    def build(self, seq):
        for i, x in enumerate(seq, self.N):
            self.X[i] = x
        for i in range(self.N - 1, 0, -1):
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def set_val(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])
    
    def get(self, i):
        return self.X[i + self.N]

    def fold(self, L, R):
        L += self.N
        R += self.N
        vL = self.X_unit
        vR = self.X_unit
        while L < R:
            if L & 1:
                vL = self.X_f(vL, self.X[L])
                L += 1
            if R & 1:
                R ^= 1
                vR = self.X_f(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.X_f(vL, vR)
    
    def fold_all(self):
        return self.X[1]
    
    def _search_right_root(self, L, f):
        R = self.N << 1
        vL = self.X_unit
        sR = []
        while L < R:
            if L & 1:
                if not f(self.X_f(vL, self.X[L])):
                    return vL, L
                vL = self.X_f(vL, self.X[L])
                L += 1
            if R & 1:
                R ^= 1
                sR.append(R)
            L >>= 1
            R >>= 1
        while sR:
            R = sR.pop()
            if not f(self.X_f(vL, self.X[R])):
                return vL, R
            vL = self.X_f(vL, self.X[R])
        return -1, self.N << 1
    
    def _search_left_root(self, R, f):
        L = self.N
        vR = self.X_unit
        sL = []
        while L < R:
            if L & 1:
                sL.append(L)
                L += 1
            if R & 1:
                R ^= 1
                if not f(self.X_f(self.X[R], vR)):
                    return vR, R
                vR = self.X_f(self.X[R], vR)
            L >>= 1
            R >>= 1
        while sL:
            L = sL.pop()
            if not f(self.X_f(self.X[L], vR)):
                return vR, L
            vR = self.X_f(self.X[L], vR)
        return -1, self.N

    def max_right(self, L, f):
        L += self.N
        vL, R = self._search_right_root(L, f)
        while R < self.N:
            R <<= 1
            if f(self.X_f(vL, self.X[R])):
                vL = self.X_f(vL, self.X[R])
                R |= 1
        return R - self.N

    def min_left(self, R, f):
        R += self.N
        vR, L = self._search_left_root(R, f)
        if L == self.N:
            return 0
        while L < self.N:
            L <<= 1
            L |= 1
            if f(self.X_f(self.X[L], vR)):
                vR = self.X_f(self.X[L], vR)
                L ^= 1
        return L + 1 - self.N

n, q, l = map(int, input().split())
a = list(map(int, input().split()))
qq = [list(map(int, input().split())) for _ in range(q)]

if sum(x[0]==2 for x in qq) == 0:
    exit(print('Not Found!'))

one = []
one.extend([(a[i], i) for i in range(n)])
one.extend([(qq[i][1], n+i) for i in range(q) if qq[i][0]==1])
one.sort()
d = dict()
for i in range(len(one)):
    d[one[i][1]] = i

st = SegmentTree(len(one), lambda x,y: (x[0]+y[0], x[1]+y[1]), (0, 0))
for i in range(n):
    st.set_val(d[i], (1, a[i]))
import bisect
for i in range(q):
    if qq[i][0] == 1:
        st.set_val(d[n+i], (1, qq[i][1]))
    elif qq[i][0] == 2:
        il = bisect.bisect_left(one, qq[i][1], key=lambda x: x[0])
        ir = bisect.bisect_right(one, qq[i][2], key=lambda x: x[0])
        print(*st.fold(il, ir))
0