結果
問題 | No.833 かっこいい電車 |
ユーザー | brthyyjp |
提出日時 | 2020-11-03 20:50:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 193 ms / 2,000 ms |
コード長 | 1,605 bytes |
コンパイル時間 | 410 ms |
コンパイル使用メモリ | 86,916 KB |
実行使用メモリ | 91,156 KB |
最終ジャッジ日時 | 2023-09-29 15:01:00 |
合計ジャッジ時間 | 7,520 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 180 ms
83,640 KB |
testcase_01 | AC | 65 ms
71,428 KB |
testcase_02 | AC | 62 ms
71,060 KB |
testcase_03 | AC | 61 ms
71,240 KB |
testcase_04 | AC | 63 ms
71,220 KB |
testcase_05 | AC | 59 ms
71,236 KB |
testcase_06 | AC | 61 ms
71,332 KB |
testcase_07 | AC | 60 ms
71,360 KB |
testcase_08 | AC | 64 ms
71,240 KB |
testcase_09 | AC | 62 ms
71,432 KB |
testcase_10 | AC | 169 ms
83,896 KB |
testcase_11 | AC | 190 ms
87,960 KB |
testcase_12 | AC | 136 ms
81,124 KB |
testcase_13 | AC | 121 ms
78,584 KB |
testcase_14 | AC | 171 ms
89,216 KB |
testcase_15 | AC | 145 ms
83,432 KB |
testcase_16 | AC | 134 ms
86,036 KB |
testcase_17 | AC | 140 ms
78,812 KB |
testcase_18 | AC | 193 ms
83,996 KB |
testcase_19 | AC | 135 ms
83,992 KB |
testcase_20 | AC | 92 ms
77,964 KB |
testcase_21 | AC | 178 ms
80,028 KB |
testcase_22 | AC | 146 ms
89,664 KB |
testcase_23 | AC | 131 ms
85,116 KB |
testcase_24 | AC | 157 ms
89,436 KB |
testcase_25 | AC | 180 ms
83,228 KB |
testcase_26 | AC | 141 ms
86,096 KB |
testcase_27 | AC | 158 ms
83,936 KB |
testcase_28 | AC | 147 ms
79,992 KB |
testcase_29 | AC | 157 ms
82,664 KB |
testcase_30 | AC | 142 ms
91,156 KB |
testcase_31 | AC | 179 ms
83,480 KB |
ソースコード
class BIT: def __init__(self, n): self.n = n self.bit = [0]*(self.n+1) # 1-indexed def init(self, init_val): for i, v in enumerate(init_val): self.add(i, v) def add(self, i, x): # i: 0-indexed i += 1 # to 1-indexed while i <= self.n: self.bit[i] += x i += (i & -i) def sum(self, i, j): # return sum of [i, j) # i, j: 0-indexed return self._sum(j) - self._sum(i) def _sum(self, i): # return sum of [0, i) # i: 0-indexed res = 0 while i > 0: res += self.bit[i] i -= i & (-i) return res def lower_bound(self, x): s = 0 pos = 0 depth = self.n.bit_length() v = 1 << depth for i in range(depth, -1, -1): k = pos + v if k <= self.n and s + self.bit[k] < x: s += self.bit[k] pos += v v >>= 1 return pos import sys input = sys.stdin.buffer.readline n, q = map(int, input().split()) A = list(map(int, input().split())) bit1 = BIT(n+1) bit1.init([1]*(n+1)) bit2 = BIT(n+1) bit2.init(A) for i in range(q): t, x = map(int, input().split()) x -= 1 if t == 1: if bit1.sum(x+1, x+2): bit1.add(x+1, -1) elif t == 2: if bit1.sum(x+1, x+2) == 0: bit1.add(x+1, 1) elif t == 3: bit2.add(x, 1) else: s = bit1.sum(0, x+1) l = bit1.lower_bound(s) r = bit1.lower_bound(s+1) print(bit2.sum(l, r))