fork download
  1. //NiceDuck
  2. #include "bits/stdc++.h"
  3. typedef long long ll;
  4. using namespace std;
  5. #define FILE "000"
  6. #define foru(i,a,b) for(int i=(int)(a); i<=(int)(b); ++i)
  7. #define ford(i,a,b) for(int i=(int)(a); i>=(int)(b); --i)
  8. #define fastio ios_base::sync_with_stdio(0);cin.tie(0);
  9. #define pb push_back
  10. #define fi first
  11. #define se second
  12. #define pii pair<int,int>
  13. #define pil pair<int,ll>
  14. #define pli pair<ll,int>
  15. #define MOD 1000000007
  16. #define el "\n"
  17.  
  18. const int MAX=1e5+5;
  19. int n,q,a[MAX];
  20. ll cnt[MAX],cnt4,cnt2;
  21.  
  22. int main()
  23. {
  24. fastio
  25. #ifndef ONLINE_JUDGE
  26. freopen(FILE ".inp","r",stdin);
  27. freopen(FILE ".out","w",stdout);
  28. #endif // ONLINE_JUDGE
  29.  
  30. cin>>n;
  31. foru(i,1,n)
  32. {
  33. cin>>a[i];
  34. cnt[a[i]]++;
  35. }
  36. foru(i,1,MAX)
  37. {
  38. if(cnt[i]>=4)
  39. {
  40. ++cnt4;
  41. if(cnt[i]>=8)++cnt4;
  42. else if(cnt[i]>=6)++cnt2;
  43. }
  44. else if(cnt[i]>=2) ++cnt2;
  45. }
  46. cin>>q; cin.ignore();
  47. while(q--)
  48. {
  49. char c; cin>>c; int x; cin>>x;
  50. if(c=='+')
  51. {
  52. ++cnt[x];
  53. if(cnt[x]==8)
  54. {
  55. ++cnt4;
  56. --cnt2;
  57. }
  58. else if(cnt[x]==6) ++cnt2;
  59. else if(cnt[x]==4)
  60. {
  61. ++cnt4;
  62. --cnt2;
  63. }
  64. else if(cnt[x]==2) ++cnt2;
  65. }
  66. else
  67. {
  68. --cnt[x];
  69. if(cnt[x]==7)
  70. {
  71. ++cnt2;
  72. --cnt4;
  73. }
  74. else if(cnt[x]==5) --cnt2;
  75. else if(cnt[x]==3)
  76. {
  77. --cnt4;
  78. ++cnt2;
  79. }
  80. else if(cnt[x]==1) --cnt2;
  81. }
  82. // cout<<cnt4<<' '<<cnt2<<el;
  83. if(cnt4>=2 || cnt4==1 && cnt2>=2) cout<<"YES\n";
  84. else cout<<"NO\n";
  85. }
  86.  
  87. return 0;
  88. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty