Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- // tiom4eg's precompiler options
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- // IO settings
- #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
- // Quick types
- #define ll long long
- #define ld long double
- #define ull unsigned long long
- #define pii pair <int, int>
- #define vi vector <int>
- #define mi vector <vector <int>>
- // Quick functions
- #define endl "\n"
- #define F first
- #define S second
- #define all(a) a.begin(), a.end()
- #define sz(a) (int)(a.size())
- #define pb push_back
- #define mp make_pair
- // Quick fors
- #define FOR(i, a, b) for (int i = a; i < b; ++i)
- #define FORS(i, a, b, c) for (int i = a; i < b; i += c)
- #define RFOR(i, a, b) for (int i = a; i >= b; --i)
- #define EACH(e, a) for (auto& e : a)
- // Pragmas
- #ifndef TIOM4EG
- #pragma GCC optimize("O3") // let the chaos begin!
- #pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt,tune=native")
- #pragma GCC comment(linker, "/stack:200000000")
- #endif
- // PBDS
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
- #define ook order_of_key
- #define fbo find_by_order
- using namespace __gnu_pbds;
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- using namespace std;
- mt19937 rng(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count());
- //#define int long long
- 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;
- const ll INFLL = 1e15 + 7;
- bool operator<(const pii& a, const pii& b) { return a.S - a.F < b.S - b.F; }
- struct SayGex {
- vector <pii> b, t;
- vector <vi> l, r;
- void build() {
- l.clear(), r.clear();
- l.resize(sz(t) / B), r.resize(sz(t) / B);
- FOR(i, 0, sz(t)) l[i / B].pb(t[i].F), r[i / B].pb(t[i].S);
- EACH(e, l) sort(all(e));
- EACH(e, r) sort(all(e));
- }
- void add(int x, int y) {
- b.pb({x, y});
- if (sz(b) == B) {
- t.insert(t.end(), all(b)), b.clear();
- sort(all(t)); // this works faster cuz prefix already sorted
- build();
- }
- }
- int get(int x, int y, int k) {
- if (y - x < k - 1) return 0;
- int s = 0;
- EACH(e, b) s += (min(y, e.S) - max(x, e.F) >= k - 1); // count in buffer
- FORS(i, 0, sz(t), B) { // count in blocks
- 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);
- 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));
- }
- return s;
- }
- } s100, s404;
- signed main() {
- fastIO;
- int n, t, pr = 0, cp = 0; cin >> n >> t;
- pii a[n];
- while (n--) {
- int op; cin >> op;
- if (op == 1) {
- int l, r; cin >> l >> r, l = l ^ (t * pr), r = r ^ (t * pr);
- if (l > r) swap(l, r);
- s100.add(l, r), a[cp++] = {l, r};
- }
- else if (op == 2) {
- int p; cin >> p, --p;
- s404.add(a[p].F, a[p].S);
- }
- else {
- int l, r, k; cin >> l >> r >> k, l = l ^ (t * pr), r = r ^ (t * pr);
- if (l > r) swap(l, r);
- pr = s100.get(l, r, k) - s404.get(l, r, k);
- cout << pr << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement