forked from tatyam-prime/SortedSet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathABC308-G.py
More file actions
45 lines (39 loc) · 938 Bytes
/
Copy pathABC308-G.py
File metadata and controls
45 lines (39 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# https://atcoder.jp/contests/abc308/submissions/46930610
# paste SortedMultiset here
import sys
input = sys.stdin.readline
Q = int(input())
A = SortedMultiset()
X = SortedMultiset()
def add(a):
A.add(a)
i = A.index(a)
l = A[i - 1] if i else None
r = A[i + 1] if i + 1 < len(A) else None
if l is not None and r is not None:
X.discard(l ^ r)
if l is not None:
X.add(l ^ a)
if r is not None:
X.add(r ^ a)
def erase(a):
i = A.index(a)
l = A[i - 1] if i else None
r = A[i + 1] if i + 1 < len(A) else None
A.discard(a)
if l is not None and r is not None:
X.add(l ^ r)
if l is not None:
X.discard(l ^ a)
if r is not None:
X.discard(r ^ a)
for _ in range(Q):
query = input()
if query[0] == "3":
print(X[0])
continue
t, x = query[0], int(query[2:])
if t == '1':
add(x)
else:
erase(x)