結果
問題 | No.833 かっこいい電車 |
ユーザー | mkawa2 |
提出日時 | 2021-02-16 18:41:22 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,137 ms / 2,000 ms |
コード長 | 3,317 bytes |
コンパイル時間 | 280 ms |
コンパイル使用メモリ | 13,184 KB |
実行使用メモリ | 34,436 KB |
最終ジャッジ日時 | 2024-09-13 07:15:16 |
合計ジャッジ時間 | 20,003 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,074 ms
30,684 KB |
testcase_01 | AC | 61 ms
26,704 KB |
testcase_02 | AC | 61 ms
26,676 KB |
testcase_03 | AC | 60 ms
26,624 KB |
testcase_04 | AC | 60 ms
26,660 KB |
testcase_05 | AC | 60 ms
26,672 KB |
testcase_06 | AC | 60 ms
26,552 KB |
testcase_07 | AC | 60 ms
26,764 KB |
testcase_08 | AC | 61 ms
26,552 KB |
testcase_09 | AC | 60 ms
26,768 KB |
testcase_10 | AC | 857 ms
31,280 KB |
testcase_11 | AC | 1,137 ms
33,592 KB |
testcase_12 | AC | 391 ms
30,424 KB |
testcase_13 | AC | 284 ms
27,920 KB |
testcase_14 | AC | 913 ms
33,624 KB |
testcase_15 | AC | 498 ms
30,676 KB |
testcase_16 | AC | 437 ms
32,048 KB |
testcase_17 | AC | 350 ms
27,208 KB |
testcase_18 | AC | 1,013 ms
31,744 KB |
testcase_19 | AC | 422 ms
31,820 KB |
testcase_20 | AC | 159 ms
29,024 KB |
testcase_21 | AC | 858 ms
29,220 KB |
testcase_22 | AC | 670 ms
34,188 KB |
testcase_23 | AC | 464 ms
31,868 KB |
testcase_24 | AC | 659 ms
33,784 KB |
testcase_25 | AC | 991 ms
30,900 KB |
testcase_26 | AC | 495 ms
32,124 KB |
testcase_27 | AC | 707 ms
31,268 KB |
testcase_28 | AC | 560 ms
29,264 KB |
testcase_29 | AC | 645 ms
31,252 KB |
testcase_30 | AC | 1,023 ms
34,436 KB |
testcase_31 | AC | 1,017 ms
30,592 KB |
ソースコード
import sys sys.setrecursionlimit(10**6) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def FI(): return float(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def MF(): return map(float, sys.stdin.buffer.readline().split()) def MI1(): return map(int1, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): return list(map(int1, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] inf = 10**16 md = 998244353 # md = 10**9+7 class BitSum: def __init__(self, n): self.n = n+1 self.table = [0]*self.n def add(self, i, x): i += 1 while i < self.n: self.table[i] += x i += i & -i def sum(self, i): if i<0:return 0 i += 1 res = 0 while i > 0: res += self.table[i] i -= i & -i return res def pos(self, x): idx = 0 for lv in range((self.n-1).bit_length()-1, -1, -1): mid = idx+(1 << lv) if mid >= self.n: continue if self.table[mid] < x: x -= self.table[mid] idx += 1 << lv return idx # 要素が[0,10**6]のとき使える class Cset: def __init__(self, mx=10**6): self.mx = mx self.size = 0 self.bit = BitSum(self.mx+1) self.nums = [False]*(self.mx+1) def __repr__(self): return " ".join(str(self[i]) for i in range(self.size)) def insert(self, a): if a < 0 or a > self.mx or self.nums[a]: return False self.size += 1 self.bit.add(a, 1) self.nums[a] = True return True def remove(self, value): if value < 0 or value > self.mx or not self.nums[value]: return False self.size -= 1 self.bit.add(value, -1) self.nums[value] = False return True def erase(self, index): i = index if i >= self.size or i < -self.size: return False return self.remove(self[i]) def __getitem__(self, i): if i >= self.size or i < -self.size: return -1 if i < 0: i = self.size+i+1 else: i += 1 return self.bit.pos(i) def __contains__(self, item): return self.nums[item] def __len__(self): return self.size def bisect_left(self, a): if a < 0 or a > self.mx: return -1 if a == 0: return 0 return self.bit.sum(a-1) def bisect_right(self, a): if a < 0 or a > self.mx: return -1 return self.bit.sum(a) n, q = MI() aa = LI() bit = BitSum(n+1) st = Cset() st.insert(n) for i, a in enumerate(aa): bit.add(i, a) st.insert(i) for _ in range(q): t, x = MI1() if t == 0: st.remove(x+1) if t == 1: st.insert(x+1) if t == 2: bit.add(x, 1) if t == 3: i = st.bisect_right(x) l, r = st[i-1], st[i] print(bit.sum(r-1)-bit.sum(l-1))