fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define mt make_tuple
  5. #define mkp make_pair
  6. #define pb push_back
  7. #define pii pair<ll,ll>
  8. #define pss pair<int,int>
  9. #define pdd pair<double,double>
  10. #define pldd pair<ld,ld>
  11. #define pff pair<float,float>
  12. #define piii pair<ll, pair<ll,ll> >
  13. #define pddd pair<ld, pair<ld,ld> >
  14. #define ff first
  15. #define ss second
  16. typedef long long int ll;
  17. typedef unsigned long long int ull;
  18. typedef long double ld;
  19.  
  20.  
  21.  
  22.  
  23. const int N = (1 << 16);
  24.  
  25. int getBits(int s) {
  26. int ans = 0;
  27. for(int i = 0; i < 16; i++)
  28. if((s & (1 << i)) != 0)
  29. ans++;
  30. return ans;
  31. }
  32.  
  33. int main() {
  34. int ms[N];
  35. int osob[N];
  36.  
  37. int q;
  38. cin >> q;
  39. while(q--) {
  40. string c;
  41. int s;
  42. cin >> c >> s;
  43.  
  44. int bits = getBits(s);
  45.  
  46. if(c == "add" || c == "del") {
  47. int d = 1;
  48. if(c == "del") d = -1;
  49. ms[s] += d;
  50. if(bits <= 16) {
  51. osob[N - 1] += d;
  52. }
  53. } else {
  54. int ans = 0;
  55. if(bits >= 16) {
  56. ans = osob[s];
  57. } else {
  58. for(int ss = s; ; ss = (ss - 1) & s) {
  59. ans += ms[ss];
  60. if(ss == 0) break;
  61. }
  62. }
  63. cout << ans << endl;
  64. }
  65. }
  66. }
  67.  
  68.  
  69.  
Success #stdin #stdout 0s 3844KB
stdin
7
add 11
cnt 15
add 4
add 0
cnt 6
del 4
cnt 15
stdout
1
2
2