結果
問題 | No.833 かっこいい電車 |
ユーザー | maspy |
提出日時 | 2020-03-13 21:36:58 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 632 ms / 2,000 ms |
コード長 | 2,101 bytes |
コンパイル時間 | 119 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 30,436 KB |
最終ジャッジ日時 | 2024-11-22 19:50:36 |
合計ジャッジ時間 | 11,208 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 547 ms
30,112 KB |
testcase_01 | AC | 30 ms
10,880 KB |
testcase_02 | AC | 30 ms
10,752 KB |
testcase_03 | AC | 31 ms
10,752 KB |
testcase_04 | AC | 30 ms
10,880 KB |
testcase_05 | AC | 31 ms
10,880 KB |
testcase_06 | AC | 30 ms
10,752 KB |
testcase_07 | AC | 30 ms
10,880 KB |
testcase_08 | AC | 30 ms
10,752 KB |
testcase_09 | AC | 31 ms
10,752 KB |
testcase_10 | AC | 504 ms
26,216 KB |
testcase_11 | AC | 632 ms
30,436 KB |
testcase_12 | AC | 203 ms
17,172 KB |
testcase_13 | AC | 170 ms
15,988 KB |
testcase_14 | AC | 479 ms
25,932 KB |
testcase_15 | AC | 241 ms
18,932 KB |
testcase_16 | AC | 135 ms
17,672 KB |
testcase_17 | AC | 228 ms
18,256 KB |
testcase_18 | AC | 628 ms
30,092 KB |
testcase_19 | AC | 149 ms
17,292 KB |
testcase_20 | AC | 52 ms
12,928 KB |
testcase_21 | AC | 570 ms
29,360 KB |
testcase_22 | AC | 246 ms
20,524 KB |
testcase_23 | AC | 172 ms
17,440 KB |
testcase_24 | AC | 256 ms
20,512 KB |
testcase_25 | AC | 608 ms
29,104 KB |
testcase_26 | AC | 178 ms
17,708 KB |
testcase_27 | AC | 394 ms
22,644 KB |
testcase_28 | AC | 332 ms
20,776 KB |
testcase_29 | AC | 353 ms
21,468 KB |
testcase_30 | AC | 433 ms
25,024 KB |
testcase_31 | AC | 484 ms
26,216 KB |
ソースコード
#!/usr/bin/env python3.8 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% N, Q = map(int, readline().split()) A = [0] + list(map(int, readline().split())) m = map(int, read().split()) QX = tuple(zip(m, m)) # %% class BinaryIndexedTree(): def __init__(self, seq): self.size = len(seq) self.depth = self.size.bit_length() self.build(seq) def build(self, seq): data = seq size = self.size for i, x in enumerate(data): j = i + (i & (-i)) if j < size: data[j] += data[i] self.data = data def __repr__(self): return self.data.__repr__() def get_sum(self, i): data = self.data s = 0 while i: s += data[i] i -= i & -i return s def add(self, i, x): data = self.data size = self.size while i < size: data[i] += x i += i & -i def find_kth_element(self, k): data = self.data; size = self.size x, sx = 0, 0 dx = 1 << (self.depth) for i in range(self.depth - 1, -1, -1): dx = (1 << i) if x + dx >= size: continue y = x + dx sy = sx + data[y] if sy < k: x, sx = y, sy return x + 1 # %% value = BinaryIndexedTree(A) connection = [0] * (N + 1) right_end_count = BinaryIndexedTree([0] + [1] * N) for q, x in QX: if q == 1: if not connection[x]: connection[x] = 1 right_end_count.add(x, -1) elif q == 2: if connection[x]: connection[x] -= 1 right_end_count.add(x, 1) elif q == 3: value.add(x, 1) elif q == 4: k = right_end_count.get_sum(x - 1) if k == 0: L = 1 else: L = right_end_count.find_kth_element(k) + 1 R = right_end_count.find_kth_element(k + 1) S = value.get_sum(R) - value.get_sum(L - 1) print(S)