Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 4
- 3 4
- 2 1003
- 1 16
- 3 1
- 0
- 1
- n=int(input())
- #n is the number of test cases
- ham={}
- dam={}
- #Created two dictionaries
- for x in range(n):
- aa,b=list(map(int,input().split()))
- #aa is the query type and b is the integer
- if aa==1:
- if b in ham:
- ham[b]+=1
- #If the integer is present already, I am incrementing its count
- if ham[b] in dam:
- dam[ham[b]]+=1
- dam[ham[b]-1]-=1
- #Similarly, if that frequecy is present, I increment it and decrement the previous count since if a frequency changes from 5 to 6 for a integer, I have to increment count for frequency 6 and decrement for frequency 5.
- else:
- dam[ham[b]]=1
- dam[ham[b]-1]-=1
- else:
- ham[b]=1
- if ham[b] in dam:
- dam[ham[b]]+=1
- else:
- dam[ham[b]]=1
- elif aa==2:
- if b in ham and ham[b]>0:
- kj=ham[b]
- ham[b]-=1
- dam[kj]-=1
- if ham[b]!=0:
- dam[ham[b]]+=1
- else:
- pass
- else:
- if b in dam and dam[b]>=1:
- print(1)
- else:
- print(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement