-
Notifications
You must be signed in to change notification settings - Fork 80
/
FrequencyQueries.py
48 lines (38 loc) · 1014 Bytes
/
FrequencyQueries.py
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
46
47
48
#!/bin/python3
import math
import os
import random
import re
import sys
from collections import Counter
# Complete the freqQuery function below.
def freqQuery(queries):
freq = Counter()
cnt = Counter()
arr = []
for q in queries:
if q[0]==1:
cnt[freq[q[1]]]-=1
freq[q[1]]+=1
cnt[freq[q[1]]]+=1
elif q[0]==2:
if freq[q[1]]>0:
cnt[freq[q[1]]]-=1
freq[q[1]]-=1
cnt[freq[q[1]]]+=1
else:
if cnt[q[1]]>0:
arr.append(1)
else:
arr.append(0)
return arr
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
q = int(input().strip())
queries = []
for _ in range(q):
queries.append(list(map(int, input().rstrip().split())))
ans = freqQuery(queries)
fptr.write('\n'.join(map(str, ans)))
fptr.write('\n')
fptr.close()