fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <queue>
  5. #include <map>
  6. #include <set>
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. #include <ext/pb_ds/assoc_container.hpp>
  10. using namespace __gnu_pbds;
  11. template <class T>
  12. using orderStaticTree =
  13. tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  14.  
  15. #define ll long long
  16.  
  17. #define saleh \
  18.   ios_base::sync_with_stdio(false); \
  19.   cin.tie(nullptr);
  20. const int N = 3e5 + 100;
  21. int bit[N];
  22.  
  23. int get(int ind)
  24. {
  25. int ret = 0;
  26. for (; ind; ind -= (ind & (-ind)))
  27. {
  28. ret += bit[ind];
  29. }
  30. return ret;
  31. }
  32.  
  33. void ad(int ind, int val)
  34. {
  35. for (; ind < N; ind += (ind & (-ind)))
  36. bit[ind] += val;
  37. }
  38.  
  39. int main()
  40. {
  41. saleh;
  42. int n, q;
  43. cin >> n >> q;
  44.  
  45. vector<int> f(q);
  46. int last = 0;
  47.  
  48. for (int i = 0; i < q; i++)
  49. {
  50. int a, b;
  51. cin >> a >> b;
  52. if (a == 1)
  53. {
  54. ad(b, 1);
  55. f[i] = b;
  56. }
  57. else if (a == 2)
  58. {
  59. ad(b, -1 * (get(b) - get(b - 1)));
  60. }
  61. else
  62. {
  63.  
  64. while (b > last)
  65. {
  66. ad(f[last], -1);
  67. last++;
  68. }
  69. }
  70. cout << get(N - 1) << endl;
  71. }
  72.  
  73. return 0;
  74. }
Success #stdin #stdout 0.01s 5260KB
stdin
Standard input is empty
stdout
Standard output is empty