Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. 4
  2. 3 4
  3. 2 1003
  4. 1 16
  5. 3 1
  6.  
  7. 0
  8. 1
  9.  
  10. n=int(input())
  11. #n is the number of test cases
  12. ham={}
  13. dam={}
  14. #Created two dictionaries
  15. for x in range(n):
  16. aa,b=list(map(int,input().split()))
  17. #aa is the query type and b is the integer
  18. if aa==1:
  19. if b in ham:
  20. ham[b]+=1
  21. #If the integer is present already, I am incrementing its count
  22. if ham[b] in dam:
  23. dam[ham[b]]+=1
  24. dam[ham[b]-1]-=1
  25. #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.
  26. else:
  27. dam[ham[b]]=1
  28. dam[ham[b]-1]-=1
  29. else:
  30. ham[b]=1
  31. if ham[b] in dam:
  32. dam[ham[b]]+=1
  33. else:
  34. dam[ham[b]]=1
  35. elif aa==2:
  36. if b in ham and ham[b]>0:
  37. kj=ham[b]
  38. ham[b]-=1
  39. dam[kj]-=1
  40. if ham[b]!=0:
  41. dam[ham[b]]+=1
  42.  
  43. else:
  44. pass
  45. else:
  46. if b in dam and dam[b]>=1:
  47. print(1)
  48. else:
  49. print(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement