Repository navigation
Expand file tree
/
Copy path1393b.cpp
More file actions
108 lines (77 loc) · 1.79 KB
/
Copy path1393b.cpp
File metadata and controls
108 lines (77 loc) · 1.79 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve() {
int n;
cin >> n;
vector<int> a(n + 2);
unordered_map<int, int> mp;
for (int i = 1; i <= n; i++) {
cin >> a[i];
mp[a[i]]++;
}
multiset<int, greater<>> p;
for (auto [k, v] : mp) {
p.emplace(v);
}
int q;
cin >> q;
auto ok = [&]() -> bool {
vector<int> all;
auto it = p.begin();
all.emplace_back(*it);
if (!p.empty()) {
if (all[0] >= 8) {
return true;
}
}
if (p.size() >= 2) {
it++;
all.emplace_back(*it);
if (all[0] >= 4 && all[1] >= 4 || all[0] >= 6 && all[1] >= 2) {
return true;
}
}
if (p.size() >= 3) {
it++;
all.emplace_back(*it);
if (all[0] >= 4 && all[1] >= 2 && all[2] >= 2) {
return true;
}
}
return false;
};
while (q--) {
char op;
int pls;
cin >> op >> pls;
if (op == '+') {
if (mp.contains(pls)) {
p.erase(p.find(mp[pls]));
}
mp[pls]++;
p.emplace(mp[pls]);
cout << (ok() ? "YES" : "NO") << '\n';
} else {
if (mp.contains(pls)) {
p.erase(p.find(mp[pls]));
}
mp[pls]--;
if (mp[pls] == 0) {
mp.erase(pls);
} else {
p.emplace(mp[pls]);
}
cout << (ok() ? "YES" : "NO") << '\n';
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}