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 fi first
#define se second
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mpp make_pair
#define ve vector
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll inf = 1e18; const int iinf = 1e9;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline bool chmin(T& a, T b) { return (a > b ? a = b, 1 : 0); }
template <typename T> inline bool chmax(T& a, T b) { return (a < b ? a = b, 1 : 0); }
constexpr int N = 2e5 + 100;
constexpr int b = 2100;
int n;
ve<pii> segs;
ve<int> s[N / b], st[N / b];
inline void reset(const set<pii> &bodek) {
for (int i = 0; i <= (n - 1) / b; ++i) s[i].clear(), st[i].clear();
n = sz(bodek); int ptr = 0; segs.clear(); segs.resize(n);
for (auto &[r, l] : bodek) segs[ptr++] = {r, l};
for (int i = 0; i < n; ++i) { auto &[r, l] = segs[i]; s[i / b].pb(l), st[i / b].pb(-(r - l + 1)); }
for (int i = 0; i <= (n - 1) / b; ++i) sort(all(s[i])), sort(all(st[i]));
}
inline void debug() {
cout << "segments:" << '\n';
for (int i = 0; i < n; ++i) {
auto &[r, l] = segs[i];
cout << l << " " << r << '\n';
}
for (int i = 0; i <= (n - 1) / b; ++i) {
cout << "block " << i << ": ";
for (auto &le : s[i]) cout << le << " ";
cout << '\n';
}
cout << '\n';
}
inline int cnts(int id, int x) { return upper_bound(all(s[id]), x) - s[id].begin(); }
inline int cnts1(int id, int x) { return upper_bound(all(st[id]), x) - st[id].begin(); }
inline int get1(int pos, int x) {
int ans = 0;
pos = lower_bound(all(segs), mpp(pos, -1)) - segs.begin();
if (pos == sz(segs)) return 0;
int bl = pos / b;
for (int i = bl + 1; i <= (n - 1) / b; ++i) ans += cnts(i, x);
for (int i = pos; i < min(n, (bl + 1) * b); ++i) ans += segs[i].se <= x;
return ans;
}
inline int get2(int l, int r, int x) {
l = lower_bound(all(segs), mpp(l, -1)) - segs.begin();
r = upper_bound(all(segs), mpp(r, INT_MAX)) - segs.begin() - 1;
if (l > r) return 0;
int lb = l / b, rb = r / b;
if (lb == rb) {
int ans = 0;
for (int i = l; i <= r; ++i) {
ans += (segs[i].fi - segs[i].se + 1 >= x);
} return ans;
}
int ans = 0;
for (int i = lb + 1; i <= rb - 1; ++i) ans += cnts1(i, -x);
for (int i = l; i < (lb + 1) * b; ++i) ans += (segs[i].fi - segs[i].se + 1 >= x);
for (int i = r; i >= rb * b; --i) ans += (segs[i].fi - segs[i].se + 1 >= x);
return ans;
}
inline int answer(int l, int r, int k) {
if (r - l + 1 < k) return 0;
int ans = 0;
ans += get1(r + 1, r - k + 1);
ans += get2(l + k - 1, r, k);
return ans;
}
inline int isec(int l, int r, int l1, int r1) {
return max(0, min(r, r1) - max(l, l1) + 1);
}
inline void solve() {
int q, t;
cin >> q >> t;
int ID = 0;
ve<int> tr(q);
ve<array<int,4>> que(q);
for (int i = 0; i < q; ++i) {
int e;
cin >> e;
que[i][0] = e;
if (e == 1) cin >> que[i][1] >> que[i][2], tr[ID++] = i;
else if (e == 2) cin >> que[i][1], --que[i][1];
else cin >> que[i][1] >> que[i][2] >> que[i][3];
}
int last = 0;
ve<int> del(q), gdel(q);
for (int l = 0; l < q; l += b) {
set<pii> sgs;
int r = min(q - 1, l + b - 1);
fill(all(del), 0);
for (int i = 0; i <= r; ++i) if (que[i][0] == 2) del[tr[que[i][1]]] = 1;
for (int i = 0; i < l; ++i) if (que[i][0] == 1) {
if (!del[i]) {
auto &[_, l, r, __] = que[i];
sgs.insert({r, l});
}
}
reset(sgs);
for (int i = l; i <= r; ++i) {
auto &[e, le, re, k] = que[i];
if (e == 1 || e == 3) {
le ^= (t * last), re ^= (t * last);
if (le > re) swap(le, re);
}
if (e == 3) {
int ans = answer(le, re, k);
for (int j = l; j <= r; ++j) {
auto &[E, L, R, K] = que[j];
if (E == 1 && !del[j] && j < i) ans += isec(le, re, L, R) >= k;
else if (E == 2) { int J = tr[L];
if (J < i && !gdel[J]) ans += isec(le, re, que[J][1], que[J][2]) >= k;
}
}
cout << (last = ans) << '\n';
// debug();
}
else if (e == 2) gdel[tr[le]] = 1;
}
}
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int q = 1; // cin >> q;
while (q--) solve();
cerr << fixed << setprecision(3) << "Time execution: " << (double)clock() / CLOCKS_PER_SEC << endl;
}
# | 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... |