This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include "temp.cpp"
#include <cstdio>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x) cerr << #x <<" "; print(x); cerr << endl;
#else
#define dbg(x)
#endif
#define sz(x) (int((x).size()))
#define len(x) (int)x.length()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define clr(x) (x).clear()
#define uniq(x) x.resize(unique(all(x)) - x.begin());
#define blt __builtin_popcount
#define pb push_back
#define popf pop_front
#define popb pop_back
void print(long long t) {cerr << t;}
void print(int t) {cerr << t;}
void print(string t) {cerr << t;}
void print(char t) {cerr << t;}
void print(double t) {cerr << t;}
void print(long double t) {cerr << t;}
void print(unsigned long long t) {cerr << t;}
template <class T, class V> void print(pair <T, V> p);
template <class T> void print(vector <T> v);
template <class T> void print(set <T> v);
template <class T, class V> void print(map <T, V> v);
template <class T> void print(multiset <T> v);
template <class T, class V> void print(T v[],V n) {cerr << "["; for(int i = 0; i < n; i++) {print(v[i]); cerr << " "; } cerr << "]";}
template <class T, class V> void print(pair <T, V> p) {cerr << "{"; print(p.first); cerr << ","; print(p.second); cerr << "}";}
template <class T> void print(vector <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(set <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(multiset <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void print(map <T, V> v) {cerr << "[ "; for (auto i : v) {print(i); cerr << " ";} cerr << "]";}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define nl '\n'
// for grid problems
int dx[8] = {-1,0,1,0,1,-1,1,-1};
int dy[8] = {0,1,0,-1,1,1,-1,-1};
// lowest / (1 << 17) >= 1e5 / (1 << 18) >= 2e5 / (1 << 21) >= 1e6
void fastIO() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
}
// file in/out
void setIO(string str = "") {
fastIO();
if (str != "") {
freopen((str + ".in").c_str(), "r", stdin);
freopen((str + ".out").c_str(), "w", stdout);
}
}
// Indexed Set
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const long long N = 400005, inf = 1e17, S = 450;
pair<long long, long long> id[N];
int cnt = 1;
struct operations {
struct node {
long long l, r;
long long get() {
return r - l + 1;
};
bool operator<(node& other) {
if(get() != other.get()) {
return get() < other.get();
} else if(l < other.l) {
return l < other.l;
} else {
return r < other.r;
}
}
};
long long intersect(node a, node b) {
a.l = max(a.l, b.l);
a.r = min(a.r, b.r);
return a.r - a.l + 1;
}
vector<long long> l[S], r[S];
vector<node> segments, blocks[S];
vector<node> to_add;
void add(long long li, long long ri) {
node curr_segment;
curr_segment.l = li;
curr_segment.r = ri;
to_add.push_back(curr_segment);
if(sz(to_add) >= S) {
sort(all(to_add));
vector<node> new_segments;
int it1 = 0, it2 = 0;
while(it1 < sz(segments) || it2 < sz(to_add)) {
if(it1 == sz(segments)) {
new_segments.push_back(to_add[it2++]);
} else if(it2 == sz(to_add)) {
new_segments.push_back(segments[it1++]);
} else if(segments[it1] < to_add[it2]) {
new_segments.push_back(segments[it1++]);
} else {
new_segments.push_back(to_add[it2++]);
}
}
segments.swap(new_segments);
for(int i = 0; i < S; i++) {
blocks[i].clear();
l[i].clear(), r[i].clear();
}
for(int i = 0; i < sz(segments); i++) {
l[i / S].push_back(segments[i].l);
r[i / S].push_back(segments[i].r);
blocks[i / S].push_back(segments[i]);
}
for(int i = 0; i < S; i++) {
sort(all(l[i]));
sort(all(r[i]));
}
to_add.clear();
}
}
long long get(long long li, long long ri, long long k) {
long long answ = 0;
node curr_segment;
curr_segment.l = li;
curr_segment.r = ri;
for(int i = 0; i < S; i++) {
if(blocks[i].empty()) continue;
if(blocks[i].front().get() >= k) {
answ += sz(blocks[i]);
answ -= sz(l[i]) - (lower_bound(all(l[i]), ri - k + 2) - l[i].begin());
answ -= (upper_bound(all(r[i]), li + k - 2) - r[i].begin());
} else if(blocks[i].back().get() >= k) {
for(auto j: blocks[i]) {
if(intersect(j, curr_segment) >= k) {
answ++;
}
}
}
}
for(auto i: to_add) {
if(intersect(i, curr_segment) >= k) {
answ++;
}
}
return answ;
}
} adding, deleting;
void solve_() {
long long n, t; cin >> n >> t;
long long cnt = 1, last_ans = 0;
while(n--) {
long long tt; cin >> tt;
if(tt == 1) {
int l, r; cin >> l >> r;
l = l ^ (t * last_ans);
r = r ^ (t * last_ans);
if(l > r) {
swap(l, r);
}
id[cnt] = {l, r}; cnt++;
adding.add(l, r);
} else if(tt == 2) {
long long ind; cin >> ind;
long long l = id[ind].first, r = id[ind].second;
deleting.add(l, r);
} else {
long long l, r, k; cin >> l >> r >> k;
l = l ^ (t * last_ans);
r = r ^ (t * last_ans);
if(l > r) {
swap(l, r);
}
long long answ = adding.get(l, r, k) - deleting.get(l, r, k);
printf("%lld\n", answ);
last_ans = answ;
}
}
}
int main() {
setIO();
auto solve = [&](int test_case)-> void {
while(test_case--) {
solve_();
}
};
int test_cases = 1;
solve(test_cases);
return 0;
}
Compilation message (stderr)
segments.cpp: In function 'void setIO(std::string)':
segments.cpp:63:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | freopen((str + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:64:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
64 | freopen((str + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |