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>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
const int mod = 1e9+7, N = 5005;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val);}
int n, T, m, k;
set<int> ss;
int mex(){
for(int i=1;i<=N;i++){
if(!ss.count(i))return i;
}assert(false);
}
vector<tuple<int, int, int>> v;//id, l, r
void solve(int test_case){
int i, j, q;
cin >> q >> T;
int last = 0;
while(q--){
int ty;
cin >> ty;
if(ty == 1){
int l, r;
cin >> l >> r;
l = (l^(T*last));
r = (r^(T*last));
if(l>r)swap(l,r);
int id = mex();
v.pb(make_tuple(id, l, r));
ss.insert(id);
}else if(ty == 2){
int id;
cin >> id;
if(!ss.count(id))assert(false);
int cn=0;
for(auto &X : v){
if(get<0>(X)== id){
v.erase(v.begin()+cn);
break;
}cn++;
}
}else {
int l, r;
cin >> l >> r >> k;
l = (l^(T*last));
r = (r^(T*last));
if(l>r)swap(l,r);
int ans = 0;
for(auto [id, L, R] : v){
if(L > r || R < l)continue;
int dist = min(R,r)-max(L,l)+1;
// cout << L << ' ' << R << ' ' << dist << '\n';
if(dist >= k)ans++;
}
cout << ans << '\n';
last = ans;
}
}
return;
}
signed main(){
FASTIO;
#define MULTITEST 0
#if MULTITEST
int ___T;
cin >> ___T;
for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
solve(T_CASE);
#else
solve(1);
#endif
return 0;
}
Compilation message (stderr)
segments.cpp: In function 'void solve(long long int)':
segments.cpp:23:6: warning: unused variable 'i' [-Wunused-variable]
23 | int i, j, q;
| ^
segments.cpp:23:9: warning: unused variable 'j' [-Wunused-variable]
23 | int i, j, q;
| ^
# | 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... |