-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfrequency_queries.cpp
56 lines (51 loc) · 1.06 KB
/
frequency_queries.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
54
55
56
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
// vector<pair<int,int>> q;
map<long, long> m;
map<long, long> val;
for (int i = 0; i < n; i++)
{
long a, b;
cin >> a >> b;
// q.emplace_back(a,b);
if (a == 1)
{
map<long, long>::iterator it;
it = m.find(m[b]);
if (it != m.end())
val[m[b]] -= 1;
m[b] += 1;
val[m[b]] += 1;
}
else if (a == 2)
{
map<long, long>::iterator it;
it = m.find(m[b]);
if (it != m.end())
val[m[b]] -= 1;
m[b] -= 1;
val[m[b]] += 1;
}
else if (a == 3)
{
bool flag = false;
if (val[b] > 0)
{
flag = true;
}
if (flag)
{
cout << 1 << "\n";
}
else
{
cout << 0 << "\n";
}
}
}
return 0;
}