Advertisement
tiom4eg

day 2, D 100

Jan 10th, 2023
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.51 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. // tiom4eg's precompiler options
  3. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  4. // IO settings
  5. #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
  6. // Quick types
  7. #define ll long long
  8. #define ld long double
  9. #define ull unsigned long long
  10. #define pii pair <int, int>
  11. #define vi vector <int>
  12. #define mi vector <vector <int>>
  13. // Quick functions
  14. #define endl "\n"
  15. #define F first
  16. #define S second
  17. #define all(a) a.begin(), a.end()
  18. #define sz(a) (int)(a.size())
  19. #define pb push_back
  20. #define mp make_pair
  21. // Quick fors
  22. #define FOR(i, a, b) for (int i = a; i < b; ++i)
  23. #define FORS(i, a, b, c) for (int i = a; i < b; i += c)
  24. #define RFOR(i, a, b) for (int i = a; i >= b; --i)
  25. #define EACH(e, a) for (auto& e : a)
  26. // Pragmas
  27. #ifndef TIOM4EG
  28. #pragma GCC optimize("O3") // let the chaos begin!
  29. #pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt,tune=native")
  30. #pragma GCC comment(linker, "/stack:200000000")
  31. #endif
  32. // PBDS
  33. #include <ext/pb_ds/assoc_container.hpp>
  34. #include <ext/pb_ds/tree_policy.hpp>
  35. #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
  36. #define ook order_of_key
  37. #define fbo find_by_order
  38. using namespace __gnu_pbds;
  39. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  40. using namespace std;
  41. mt19937 rng(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count());
  42. //#define int long long
  43. const int INF = 1e9 + 7, MD = 998244353, MAX = 200, R = 1 << 19, MOD1 = 1e9 + 7, MOD2 = 1e9 + 9, MOD12 = MOD1 * MOD1, MOD22 = MOD2 * MOD2, LG = 20, B1 = 103, B2 = 107, B = 1024;
  44. const ll INFLL = 1e15 + 7;
  45.  
  46. bool operator<(const pii& a, const pii& b) { return a.S - a.F < b.S - b.F; }
  47.  
  48. struct SayGex {
  49.     vector <pii> b, t;
  50.     vector <vi> l, r;
  51.     void build() {
  52.         l.clear(), r.clear();
  53.         l.resize(sz(t) / B), r.resize(sz(t) / B);
  54.         FOR(i, 0, sz(t)) l[i / B].pb(t[i].F), r[i / B].pb(t[i].S);
  55.         EACH(e, l) sort(all(e));
  56.         EACH(e, r) sort(all(e));
  57.     }
  58.     void add(int x, int y) {
  59.         b.pb({x, y});
  60.         if (sz(b) == B) {
  61.             t.insert(t.end(), all(b)), b.clear();
  62.             sort(all(t)); // this works faster cuz prefix already sorted
  63.             build();
  64.         }
  65.     }
  66.     int get(int x, int y, int k) {
  67.         if (y - x < k - 1) return 0;
  68.         int s = 0;
  69.         EACH(e, b) s += (min(y, e.S) - max(x, e.F) >= k - 1); // count in buffer
  70.         FORS(i, 0, sz(t), B) { // count in blocks
  71.             if (t[i + B - 1].S - t[i + B - 1].F >= k - 1) FOR(j, i, i + B) s += (min(y, t[j].S) - max(x, t[j].F) >= k - 1);
  72.             else if (t[i].S - t[i].F >= k - 1) s += B - (lower_bound(all(r[i / B]), x + k - 1) - r[i / B].begin()) - (l[i / B].end() - upper_bound(all(l[i / B]), y - k + 1));
  73.         }
  74.         return s;
  75.     }
  76. } s100, s404;
  77.  
  78. signed main() {
  79.     fastIO;
  80.     int n, t, pr = 0, cp = 0; cin >> n >> t;
  81.     pii a[n];
  82.     while (n--) {
  83.         int op; cin >> op;
  84.         if (op == 1) {
  85.             int l, r; cin >> l >> r, l = l ^ (t * pr), r = r ^ (t * pr);
  86.             if (l > r) swap(l, r);
  87.             s100.add(l, r), a[cp++] = {l, r};
  88.         }
  89.         else if (op == 2) {
  90.             int p; cin >> p, --p;
  91.             s404.add(a[p].F, a[p].S);
  92.         }
  93.         else {
  94.             int l, r, k; cin >> l >> r >> k, l = l ^ (t * pr), r = r ^ (t * pr);
  95.             if (l > r) swap(l, r);
  96.             pr = s100.get(l, r, k) - s404.get(l, r, k);
  97.             cout << pr << endl;
  98.         }
  99.     }
  100. }
  101.  
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement