#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
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 |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
41 ms |
512 KB |
Output is correct |
4 |
Correct |
41 ms |
492 KB |
Output is correct |
5 |
Correct |
370 ms |
876 KB |
Output is correct |
6 |
Correct |
299 ms |
748 KB |
Output is correct |
7 |
Correct |
78 ms |
620 KB |
Output is correct |
8 |
Correct |
265 ms |
748 KB |
Output is correct |
9 |
Correct |
232 ms |
620 KB |
Output is correct |
10 |
Correct |
467 ms |
876 KB |
Output is correct |
11 |
Correct |
138 ms |
748 KB |
Output is correct |
12 |
Correct |
139 ms |
748 KB |
Output is correct |
13 |
Correct |
453 ms |
1132 KB |
Output is correct |
14 |
Correct |
211 ms |
708 KB |
Output is correct |
15 |
Correct |
44 ms |
492 KB |
Output is correct |
16 |
Correct |
44 ms |
492 KB |
Output is correct |
17 |
Correct |
124 ms |
620 KB |
Output is correct |
18 |
Correct |
388 ms |
756 KB |
Output is correct |
19 |
Correct |
126 ms |
620 KB |
Output is correct |
20 |
Correct |
142 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
567 ms |
1920 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
554 ms |
1516 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
545 ms |
1644 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
41 ms |
512 KB |
Output is correct |
4 |
Correct |
41 ms |
492 KB |
Output is correct |
5 |
Correct |
370 ms |
876 KB |
Output is correct |
6 |
Correct |
299 ms |
748 KB |
Output is correct |
7 |
Correct |
78 ms |
620 KB |
Output is correct |
8 |
Correct |
265 ms |
748 KB |
Output is correct |
9 |
Correct |
232 ms |
620 KB |
Output is correct |
10 |
Correct |
467 ms |
876 KB |
Output is correct |
11 |
Correct |
138 ms |
748 KB |
Output is correct |
12 |
Correct |
139 ms |
748 KB |
Output is correct |
13 |
Correct |
453 ms |
1132 KB |
Output is correct |
14 |
Correct |
211 ms |
708 KB |
Output is correct |
15 |
Correct |
44 ms |
492 KB |
Output is correct |
16 |
Correct |
44 ms |
492 KB |
Output is correct |
17 |
Correct |
124 ms |
620 KB |
Output is correct |
18 |
Correct |
388 ms |
756 KB |
Output is correct |
19 |
Correct |
126 ms |
620 KB |
Output is correct |
20 |
Correct |
142 ms |
620 KB |
Output is correct |
21 |
Runtime error |
567 ms |
1920 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
41 ms |
512 KB |
Output is correct |
4 |
Correct |
41 ms |
492 KB |
Output is correct |
5 |
Correct |
370 ms |
876 KB |
Output is correct |
6 |
Correct |
299 ms |
748 KB |
Output is correct |
7 |
Correct |
78 ms |
620 KB |
Output is correct |
8 |
Correct |
265 ms |
748 KB |
Output is correct |
9 |
Correct |
232 ms |
620 KB |
Output is correct |
10 |
Correct |
467 ms |
876 KB |
Output is correct |
11 |
Correct |
138 ms |
748 KB |
Output is correct |
12 |
Correct |
139 ms |
748 KB |
Output is correct |
13 |
Correct |
453 ms |
1132 KB |
Output is correct |
14 |
Correct |
211 ms |
708 KB |
Output is correct |
15 |
Correct |
44 ms |
492 KB |
Output is correct |
16 |
Correct |
44 ms |
492 KB |
Output is correct |
17 |
Correct |
124 ms |
620 KB |
Output is correct |
18 |
Correct |
388 ms |
756 KB |
Output is correct |
19 |
Correct |
126 ms |
620 KB |
Output is correct |
20 |
Correct |
142 ms |
620 KB |
Output is correct |
21 |
Runtime error |
567 ms |
1920 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
22 |
Halted |
0 ms |
0 KB |
- |