結果
問題 | No.2942 Sigma Music Game Level Problem |
ユーザー | noriaoki |
提出日時 | 2024-10-19 00:16:26 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 4,365 ms / 6,000 ms |
コード長 | 3,496 bytes |
コンパイル時間 | 394 ms |
コンパイル使用メモリ | 82,044 KB |
実行使用メモリ | 264,856 KB |
最終ジャッジ日時 | 2024-11-15 07:14:33 |
合計ジャッジ時間 | 43,679 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
56,644 KB |
testcase_01 | AC | 49 ms
56,556 KB |
testcase_02 | AC | 46 ms
56,328 KB |
testcase_03 | AC | 48 ms
57,928 KB |
testcase_04 | AC | 47 ms
56,156 KB |
testcase_05 | AC | 45 ms
56,008 KB |
testcase_06 | AC | 48 ms
57,100 KB |
testcase_07 | AC | 55 ms
64,740 KB |
testcase_08 | AC | 97 ms
78,860 KB |
testcase_09 | AC | 72 ms
71,836 KB |
testcase_10 | AC | 66 ms
70,180 KB |
testcase_11 | AC | 1,876 ms
188,396 KB |
testcase_12 | AC | 3,877 ms
264,856 KB |
testcase_13 | AC | 3,714 ms
168,660 KB |
testcase_14 | AC | 1,613 ms
175,488 KB |
testcase_15 | AC | 1,552 ms
209,096 KB |
testcase_16 | AC | 3,303 ms
162,132 KB |
testcase_17 | AC | 946 ms
133,064 KB |
testcase_18 | AC | 2,629 ms
179,760 KB |
testcase_19 | AC | 4,365 ms
218,452 KB |
testcase_20 | AC | 1,425 ms
178,072 KB |
testcase_21 | AC | 4,281 ms
264,504 KB |
testcase_22 | AC | 4,136 ms
264,380 KB |
testcase_23 | AC | 1,335 ms
109,532 KB |
testcase_24 | AC | 46 ms
56,552 KB |
testcase_25 | AC | 45 ms
56,512 KB |
testcase_26 | AC | 2,248 ms
199,260 KB |
ソースコード
# 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())) flag = True st = SegmentTree(2*10**5+1, lambda x,y: (x[0]+y[0], x[1]+y[1]), (0, 0)) for i in range(n): c, v = st.get(a[i]) st.set_val(a[i], (c+1, v+a[i])) for i in range(q): t, *x = map(int, input().split()) if t == 1: x = x[0] c, v = st.get(x) st.set_val(x, (c+1, v+x)) elif t == 2: flag = False l, r = x print(*st.fold(l, r+1)) if flag: print('Not Found!')