Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Author: jainbot27
- #pragma GCC optimize ("O3")
- #pragma GCC target("sse4")
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 1e5 + 10;
- int amts[N];
- multiset<int> things;
- signed main(){
- ios_base::sync_with_stdio(0); cin.tie(0);
- // freopen("out.out", "r", stdin);
- memset(amts, 0, sizeof(amts));
- int n, q;
- cin >> n;
- for(int i = 0; i < n; i++){
- int x;
- cin >> x;
- if(amts[x] != 0)
- things.erase(things.find(amts[x]));
- amts[x]++;
- things.insert(amts[x]);
- }
- cin >> q;
- for(int i= 0; i < q; i++){
- char c;
- int w;
- cin >> c >> w;
- if(c == '+'){
- things.erase(things.find(amts[w]));
- things.insert((1+amts[w]));
- amts[w]++;
- }
- else{
- things.erase(things.find(amts[w]));
- things.insert((-1 + amts[w]));
- amts[w]--;
- }
- int x = 0, y = 0, z = 0;
- auto it = things.rbegin();
- if((int)things.size() >= 1){
- x = *it;
- }
- if((int)things.size() >= 2){
- it++;
- y = *it;
- }
- if((int)things.size() >= 3){
- it++;
- z = *it;
- }
- if(x >= 8 || (x >= 6 && y >= 2) || (x >= 4 && y >= 4) || (x >= 4 && y >= 2 && z >= 2)){
- cout << "YES" << "\n";
- }
- else{
- cout << "NO" << "\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment