fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7.  
  8. typedef long long ll;
  9. typedef pair<int,int> ii;
  10. typedef vector<int> vi;
  11.  
  12. #define fi first
  13. #define se second
  14. #define mp make_pair
  15. #define pb push_back
  16.  
  17. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
  18.  
  19. map<int,int> fen[100001];
  20.  
  21. int type[100001];
  22. int t[100001];
  23. int x[100001];
  24. pbds times;
  25.  
  26. const int N = 100001;
  27.  
  28. void add(int idx ,int val){
  29. while (idx <= N){
  30. fen[idx][val]++;
  31. idx += (idx & -idx);
  32. }
  33. }
  34.  
  35. void remove(int idx ,int val){
  36. while (idx <= N){
  37. fen[idx][val]--;
  38. idx += (idx & -idx);
  39. }
  40. }
  41.  
  42. int read(int idx, int val){
  43. int sum = 0;
  44. while (idx > 0){
  45. sum += fen[idx][val];
  46. idx -= (idx & -idx);
  47. }
  48. return sum;
  49. }
  50.  
  51. int main()
  52. {
  53. ios_base::sync_with_stdio(false); cin.tie(0);
  54. int n;
  55. cin >> n;
  56. int a, b, c;
  57. for(int i = 0; i < n; i++)
  58. {
  59. cin >> a >> b >> c;
  60. type[i] = a;
  61. t[i] = b;
  62. x[i] = c;
  63. times.insert(b);
  64. }
  65. for(int i = 0; i < n; i++)
  66. {
  67. a = type[i];
  68. b = times.order_of_key(t[i])+1;
  69. c = x[i];
  70. if(a == 1) add(b, c);
  71. if(a == 2) remove(b, c);
  72. if(a == 3) cout << read(b, c) << '\n';
  73. }
  74. return 0;
  75. }
Success #stdin #stdout 0s 6932KB
stdin
6
1 1 5
3 5 5
1 2 5
3 6 5
2 3 5
3 7 5
stdout
1
2
1