fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define pep_Guardiola \
  4.   ios::sync_with_stdio(0); \
  5.   cin.tie(0); \
  6.   cout.tie(0);
  7. using namespace std;
  8. // #define int ll
  9.  
  10. void io()
  11. {
  12. #ifndef ONLINE_JUDGE
  13. freopen("input.txt", "r", stdin);
  14. #endif
  15. }
  16. const int N = 1e6 + 7;
  17.  
  18. void Guardiola()
  19. {
  20. int n, q;
  21. cin >> n >> q;
  22. vector<int> a(n), freq(N, 0), bits(20);
  23.  
  24. for (int i = 0; i < n; i++)
  25. {
  26. cin >> a[i];
  27. freq[a[i]]++;
  28. int msb = log2(a[i]);
  29. bits[msb]++;
  30. }
  31. while (q--)
  32. {
  33. char type;
  34. cin >> type;
  35. if (type == 'U')
  36. {
  37. int i, v;
  38. cin >> i >> v;
  39. i--;
  40. freq[a[i]]--;
  41. int b = log2(a[i]);
  42. bits[b]--;
  43. a[i] = v;
  44. freq[v]++;
  45. b = log2(v);
  46. bits[b]++;
  47. }
  48. else if (type == '|')
  49. {
  50. int v;
  51. cin >> v;
  52. cout << freq[v] << '\n';
  53. }
  54. else if (type == '&')
  55. {
  56. int v;
  57. cin >> v;
  58. cout << n << '\n';
  59. }
  60. else
  61. {
  62. int v;
  63. cin >> v;
  64. int ms = log2(v);
  65. cout << bits[ms] << '\n';
  66. }
  67. }
  68. }
  69.  
  70. signed main()
  71. {
  72. pep_Guardiola;
  73. io();
  74. int t = 1;
  75. // cin >> t;
  76. while (t--)
  77. Guardiola();
  78.  
  79. return 0;
  80. }
Success #stdin #stdout 0.01s 7092KB
stdin
5 5
6 12 7 15 7
| 7
^ 10
U 3 13
| 7
^ 10
stdout
2
2
1
3