#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define pb push_back
#define endi puts("");
const int N = 1e6+12,INF=1e18+7;
set <int> s;
multiset <pair<int,pii> > m;
pii p[N];
int der[N];
void build(int v,int l,int r){
if (l == r){
der[v] = l;
ret ;
}
else {
int m = l+r>>1;
build(v<<1,l,m);
build((v<<1)+1,m+1,r);
der[v] = min(der[v<<1],der[(v<<1)+1]);
}
}
void update(int v,int l,int r,int x,int y){
if (l == x && r == x){
der[v] = y;
ret ;
}
else {
int m = l+r>>1;
if (m < x){
update((v<<1)+1,m+1,r,x,y);
}
else {
update(v<<1,l,m,x,y);
}
der[v] = min(der[v<<1],der[(v<<1)+1]);
}
}
int fun(pii a,pii b){
if (min(a,b) == b)swap(a,b);
if (b.sc <= a.sc){
ret b.sc-b.fr+1;
}
if (b.fr <= a.sc){
ret a.sc-b.fr+1;
}
ret 0;
}
main(){
int n,t,i,j,lastans=0;
scan2(n,t)
build(1,1,200000);
for (j=1;j<=n;++j){
int type;
scan1(type)
if (type == 1){
int x = der[1],l,r;
scan2(l,r)
update(1,1,200000,x,INF);
l = (l^(t*lastans));
r = (r^(t*lastans));
if (l > r)swap(l,r);
p[x] = {l,r};
m.insert({x,{l,r}});
}
if (type == 2){
int id;
scan1(id)
update(1,1,200000,id,id);
m.erase({id,{p[id].fr,p[id].sc}});
}
if (type == 3){
int l,r,k,ans=0;
scan3(l,r,k)
l = (l^(t*lastans));
r = (r^(t*lastans));
if (l > r)swap(l,r);
for (auto it: m){
pii x = it.sc;
if (fun({l,r},x) >= k)ans++;
}
cout <<ans<<"\n";
lastans=ans;
}
}
}
Compilation message
segments.cpp: In function 'void build(long long int, long long int, long long int)':
segments.cpp:26:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
26 | int m = l+r>>1;
| ~^~
segments.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int)':
segments.cpp:39:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
39 | int m = l+r>>1;
| ~^~
segments.cpp: At global scope:
segments.cpp:62:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
62 | main(){
| ^
segments.cpp: In function 'int main()':
segments.cpp:63:13: warning: unused variable 'i' [-Wunused-variable]
63 | int n,t,i,j,lastans=0;
| ^
segments.cpp:10:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
10 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
segments.cpp:64:5: note: in expansion of macro 'scan2'
64 | scan2(n,t)
| ^~~~~
segments.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
9 | #define scan1(a) scanf("%lld",&a);
| ~~~~~^~~~~~~~~~~
segments.cpp:68:9: note: in expansion of macro 'scan1'
68 | scan1(type)
| ^~~~~
segments.cpp:10:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
10 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
segments.cpp:71:13: note: in expansion of macro 'scan2'
71 | scan2(l,r)
| ^~~~~
segments.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
9 | #define scan1(a) scanf("%lld",&a);
| ~~~~~^~~~~~~~~~~
segments.cpp:81:13: note: in expansion of macro 'scan1'
81 | scan1(id)
| ^~~~~
segments.cpp:11:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
11 | #define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:87:13: note: in expansion of macro 'scan3'
87 | scan3(l,r,k)
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4460 KB |
Output is correct |
2 |
Correct |
4 ms |
4460 KB |
Output is correct |
3 |
Incorrect |
24 ms |
4588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5057 ms |
8684 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5052 ms |
6708 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5051 ms |
6712 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4460 KB |
Output is correct |
2 |
Correct |
4 ms |
4460 KB |
Output is correct |
3 |
Incorrect |
24 ms |
4588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4460 KB |
Output is correct |
2 |
Correct |
4 ms |
4460 KB |
Output is correct |
3 |
Incorrect |
24 ms |
4588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |