jainbot27

Untitled

Aug 7th, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. //Author: jainbot27
  2. #pragma GCC optimize ("O3")
  3. #pragma GCC target("sse4")
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6.  
  7. const int N = 1e5 + 10;
  8. int amts[N];
  9. multiset<int> things;
  10. signed main(){
  11. ios_base::sync_with_stdio(0); cin.tie(0);
  12. // freopen("out.out", "r", stdin);
  13. memset(amts, 0, sizeof(amts));
  14. int n, q;
  15. cin >> n;
  16. for(int i = 0; i < n; i++){
  17. int x;
  18. cin >> x;
  19. if(amts[x] != 0)
  20. things.erase(things.find(amts[x]));
  21. amts[x]++;
  22. things.insert(amts[x]);
  23. }
  24. cin >> q;
  25. for(int i= 0; i < q; i++){
  26. char c;
  27. int w;
  28. cin >> c >> w;
  29. if(c == '+'){
  30. things.erase(things.find(amts[w]));
  31. things.insert((1+amts[w]));
  32. amts[w]++;
  33. }
  34. else{
  35. things.erase(things.find(amts[w]));
  36. things.insert((-1 + amts[w]));
  37. amts[w]--;
  38. }
  39. int x = 0, y = 0, z = 0;
  40. auto it = things.rbegin();
  41. if((int)things.size() >= 1){
  42. x = *it;
  43. }
  44. if((int)things.size() >= 2){
  45. it++;
  46. y = *it;
  47. }
  48. if((int)things.size() >= 3){
  49. it++;
  50. z = *it;
  51. }
  52. if(x >= 8 || (x >= 6 && y >= 2) || (x >= 4 && y >= 4) || (x >= 4 && y >= 2 && z >= 2)){
  53. cout << "YES" << "\n";
  54. }
  55. else{
  56. cout << "NO" << "\n";
  57. }
  58. }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment