-
Notifications
You must be signed in to change notification settings - Fork 1
/
FrequencyQueries.cpp
53 lines (45 loc) · 1014 Bytes
/
FrequencyQueries.cpp
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
49
50
51
52
53
// problem: "https://www.hackerrank.com/challenges/frequency-queries/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=dictionaries-hashmaps"
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int q;
cin>>q;
map<int,int>M;
vector<int>V(int(1e6+1),0);
while(q--)
{
int x,y;
cin>>x>>y;
if(x==1)
{
if(M.count(y) && M[y]>0)
{
V[M[y]]--;
M[y]++;
}
else
M[y] = 1;
V[M[y]]++;
}
else if(x==2)
{
if(M.count(y) && M[y]>0)
{
V[M[y]]--;
M[y]--;
V[M[y]]++;
}
}
else
{
if(y<=(int)(1e6) && V[y]>0)
cout<<1<<'\n';
else
cout<<0<<'\n';
}
}
return 0;
}