This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)((x).size())
#define pb push_back
#define fr first
#define sc second
#define pw(x) (1ll << x)
using namespace std;
using namespace __gnu_pbds;
#define int long long
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef unsigned long long ull;
template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
const int N = 2e5 + 100;
const int buben = 1700;
const int nb = N / buben + 2;
struct segment {
int l, r;
segment (int l = 0, int r = 0) : l(l), r(r) {}
inline int len () { return r - l + 1; }
inline bool operator < (segment &x) {
if (len() != x.len()) return len() < x.len();
return make_pair(l, r) < make_pair(x.l, x.r);
}
};
inline int inter (const segment &a, const segment &b) {
return max(0ll, min(a.r, b.r) - max(a.l, b.l) + 1);
}
struct sex {
vector <segment> buf;
vector <segment> ful;
vector <int> lb[nb], rb[nb];
inline void add (int l, int r) {
segment seg (l, r); buf.pb(seg);
if (sz(buf) == buben) {
sort(all(buf));
vector <segment> mt; mt.reserve(sz(ful) + sz(buf));
int uk1 = 0, uk2 = 0;
while (uk1 < sz(ful) || uk2 < sz(buf)) {
if (uk1 == sz(ful)) mt.pb(buf[uk2++]);
else if (uk2 == sz(buf)) mt.pb(ful[uk1++]);
else if (ful[uk1] < buf[uk2]) mt.pb(ful[uk1++]);
else mt.pb(buf[uk2++]);
}
ful.swap(mt); buf.clear();
for (int i = 0; i < nb; ++i) lb[i].clear(), rb[i].clear();
for (int i = 0; i < sz(ful); ++i) {
lb[i / buben].pb(ful[i].l);
rb[i / buben].pb(ful[i].r);
}
for (int i = 0; i < nb; ++i) {
sort(all(lb[i]));
sort(all(rb[i]));
}
}
}
inline int get (int l, int r, int k) {
int res = 0;
segment seg (l, r);
for (segment x : buf) res += inter(x, seg) >= k;
for (int L = 0, i = 0; L < sz(ful); L += buben, ++i) {
int R = min(sz(ful), L + buben) - 1;
if (ful[L].len() >= k) {
res += R - L + 1;
res -= sz(lb[i]) - (lower_bound(all(lb[i]), r - k + 2) - lb[i].begin());
res -= upper_bound(all(rb[i]), l + k - 2) - rb[i].begin();
}
else if (ful[R].len() >= k) {
for (int j = L; j <= R; ++j) res += inter(ful[j], seg) >= k;
}
}
return res;
}
};
inline void solve () {
int q, T; cin >> q >> T;
vector <pii> seg (q); int uk = 0;
int lst = 0;
sex in, out;
while (q--) {
int t; cin >> t;
if (t == 1) {
int l, r; cin >> l >> r;
l = (l ^ (T * lst)), r = (r ^ (T * lst)); if (l > r) swap(l, r);
seg[uk++] = {l, r};
in.add(l, r);
}
if (t == 2) {
int id; cin >> id; --id;
auto [l, r] = seg[id];
out.add(l, r);
}
if (t == 3) {
int l, r, k; cin >> l >> r >> k;
l = (l ^ (T * lst)), r = (r ^ (T * lst)); if (l > r) swap(l, r);
lst = in.get(l, r, k) - out.get(l, r, k);
cout << lst << endl;
}
}
}
signed main ()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // LOCAL
int t = 1; // cin >> t;
while (t--) solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |