Advertisement
SorahISA

3-max-booker

Apr 10th, 2023
737
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.61 KB | None | 0 0
  1. #pragma GCC optimize("Ofast", "unroll-loops")
  2. // #pragma GCC target("avx")
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. #define int int64_t
  7. #define double __float80
  8. using pii = pair<int, int>;
  9. template <typename T> using Prior = std::priority_queue<T>;
  10. template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;
  11.  
  12. // #define X first
  13. // #define Y second
  14. #define eb emplace_back
  15. #define ef emplace_front
  16. #define ee emplace
  17. #define pb pop_back
  18. #define pf pop_front
  19. #define ALL(x) begin(x), end(x)
  20. #define RALL(x) rbegin(x), rend(x)
  21. #define SZ(x) ((int)(x).size())
  22.  
  23. #define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
  24. template <typename T> void _do(T &&_t) {cerr << _t << "\n";}
  25. template <typename T, typename ...U> void _do(T &&_t, U &&..._u) {cerr << _t << ", ", _do(_u...);}
  26.  
  27. template <typename T, typename U> bool chmin(T &lhs, U rhs) {return lhs > rhs ? lhs = rhs, 1 : 0;}
  28. template <typename T, typename U> bool chmax(T &lhs, U rhs) {return lhs < rhs ? lhs = rhs, 1 : 0;}
  29.  
  30. const int maxc = 1 << 24;
  31.  
  32. struct BIT {
  33.     vector<int> bit;
  34.    
  35.     void init() {
  36.         bit.assign(maxc, 0);
  37.     }
  38.    
  39.     void add(int idx, int val) {
  40.         if (idx == 0) return;
  41.         while (idx < maxc) {
  42.             bit[idx] += val;
  43.             idx += idx & -idx;
  44.         }
  45.     }
  46.    
  47.     int sum(int idx, int ans = 0) {
  48.         while (idx) {
  49.             ans += bit[idx];
  50.             idx -= idx & -idx;
  51.         }
  52.         return ans;
  53.     }
  54.    
  55.     int query(int qL) {
  56.         return sum(maxc-1) - sum(qL-1);
  57.     }
  58. };
  59.  
  60. void solve() {
  61.     int N; cin >> N;
  62.    
  63.     BIT bit1, bit2; bit1.init(), bit2.init();
  64.     vector<int> cnt(maxc, 0);
  65.     for (int q = 1; q <= N; ++q) {
  66.         string op; cin >> op;
  67.        
  68.         if (op == "B") {
  69.             int idx; cin >> idx;
  70.             bit1.add(cnt[idx], -1);
  71.             bit2.add(cnt[idx], -cnt[idx]);
  72.             ++cnt[idx];
  73.             bit1.add(cnt[idx], 1);
  74.             bit2.add(cnt[idx], cnt[idx]);
  75.         }
  76.        
  77.         if (op == "C") {
  78.             int idx; cin >> idx;
  79.             if (!cnt[idx]) continue;
  80.             bit1.add(cnt[idx], -1);
  81.             bit2.add(cnt[idx], -cnt[idx]);
  82.             --cnt[idx];
  83.             bit1.add(cnt[idx], 1);
  84.             bit2.add(cnt[idx], cnt[idx]);
  85.         }
  86.        
  87.         if (op == "P") {
  88.             int val; cin >> val;
  89.             cout << bit1.query(val) << " " << bit2.query(val) << "\n";
  90.         }
  91.     }
  92. }
  93.  
  94. int32_t main() {
  95.     fastIO();
  96.    
  97.     int t = 1; // cin >> t;
  98.     for (int _ = 1; _ <= t; ++_) {
  99.         solve();
  100.     }
  101.    
  102.     return 0;
  103. }
  104.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement