結果
問題 | No.833 かっこいい電車 |
ユーザー | maspy |
提出日時 | 2020-03-13 21:36:58 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 659 ms / 2,000 ms |
コード長 | 2,101 bytes |
コンパイル時間 | 126 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 30,308 KB |
最終ジャッジ日時 | 2024-05-02 07:47:03 |
合計ジャッジ時間 | 10,732 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 563 ms
30,108 KB |
testcase_01 | AC | 34 ms
10,880 KB |
testcase_02 | AC | 34 ms
10,880 KB |
testcase_03 | AC | 32 ms
10,880 KB |
testcase_04 | AC | 35 ms
10,752 KB |
testcase_05 | AC | 38 ms
10,880 KB |
testcase_06 | AC | 32 ms
11,008 KB |
testcase_07 | AC | 35 ms
10,880 KB |
testcase_08 | AC | 33 ms
10,752 KB |
testcase_09 | AC | 34 ms
11,008 KB |
testcase_10 | AC | 534 ms
26,220 KB |
testcase_11 | AC | 657 ms
30,308 KB |
testcase_12 | AC | 210 ms
17,172 KB |
testcase_13 | AC | 170 ms
15,988 KB |
testcase_14 | AC | 513 ms
26,028 KB |
testcase_15 | AC | 250 ms
19,028 KB |
testcase_16 | AC | 142 ms
17,716 KB |
testcase_17 | AC | 232 ms
18,380 KB |
testcase_18 | AC | 659 ms
30,092 KB |
testcase_19 | AC | 155 ms
17,428 KB |
testcase_20 | AC | 52 ms
13,184 KB |
testcase_21 | AC | 591 ms
29,116 KB |
testcase_22 | AC | 251 ms
20,656 KB |
testcase_23 | AC | 183 ms
17,552 KB |
testcase_24 | AC | 266 ms
20,504 KB |
testcase_25 | AC | 641 ms
29,420 KB |
testcase_26 | AC | 185 ms
17,708 KB |
testcase_27 | AC | 422 ms
22,892 KB |
testcase_28 | AC | 355 ms
20,772 KB |
testcase_29 | AC | 370 ms
21,356 KB |
testcase_30 | AC | 439 ms
25,028 KB |
testcase_31 | AC | 492 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)