#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+3;
const int crit = 2000;
int i,j,p,q,n,m,k,L,R,A,B,lans,id,lb[maxn],rb[maxn],block[maxn],minlen[maxn],t,curlen;
vector < pair <int,int> > cur,all;
vector < pair <int,int> > levi[100],desni[100];//n/crit
int removed[maxn];
void insert(int l,int r,int nom)
{
cur.push_back({r-l+1,nom});
if(cur.size()==crit)
{
vector <pair <int,int>> neww;
for(i=0; i<all.size()/crit; i++)
levi[i].clear(),desni[i].clear(),minlen[i] = -1;
for(auto i:cur)
neww.push_back(i);
for(auto i:all)
neww.push_back(i);
cur.clear();
all.clear();
for(auto i:neww)
{
if(!removed[i.second])
all.push_back(i);
}
///build the structure
sort(all.rbegin(),all.rend());
int bl = 0;
int br = 0;
int Min = 1e7;
for(auto i:all)
{
levi[bl].push_back({lb[i.second],i.second});
desni[bl].push_back({rb[i.second],i.second});
Min = min(Min,i.first);
block[i.second] = bl;
br++;
if(br==crit)
{
minlen[bl] = Min;
Min = 1e7;
bl++;
br = 0;
}
}
for(i=0; i<all.size()/crit; i++)
{
sort(levi[i].begin(),levi[i].end());
sort(desni[i].begin(),desni[i].end());
}
}
}
void remove(int id)
{
removed[id] = true;
if(block[id]==-1)
return ;
p = block[id];
vector < pair <int,int> > newws;
for(auto i:levi[p])
if(i.second!=id)newws.push_back(i);
levi[p] = newws;
newws.clear();
for(auto i:desni[p])
if(i.second!=id)newws.push_back(i);
desni[p] = newws;
}
int solve(int l,int r,int k)
{
int ans = 0;
for(auto i:cur)
{
if(removed[i.second])
continue;
//cout<<lb[i.second]<<" "<<rb[i.second]<<" "<<l<<" "<<r<<" "<<k<<endl;
if(min(rb[i.second],r)-max(lb[i.second],l)+1>=k)
ans++;
}
for(i=0; i<all.size()/crit; i++)
{
if(minlen[i]==-1)break;
if(minlen[i]<k)
{
///iterative check
j = i;
for(auto i:levi[j])
{
if(removed[i.second])
continue;
if(min(rb[i.second],r)-max(lb[i.second],l)+1>=k)
ans++;
}
break;
}
ans+=levi[i].size();
p = 0;
///indexed from 0
p += lower_bound(desni[i].begin(),desni[i].end(), make_pair(l+k-1,-1))-desni[i].begin();
p += levi[i].size()-(lower_bound(levi[i].begin(),levi[i].end(), make_pair(r-k+2,-1))-levi[i].begin());
ans-=p;
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>t;
for(i=0; i<=n; i++)
block[i] = -1,minlen[i] = -1;
lans = 0;
while(n--)
{
int type;
cin>>type;
if(type==1)
{
cin>>A>>B;
L = A^(t*lans);
R = B^(t*lans);
if(L>R)swap(L,R);
curlen++;
lb[curlen] = L;
rb[curlen] = R;
insert(L,R,curlen);
}
else if(type==2)
{
cin>>id;
remove(id);
}
else
{
cin>>A>>B>>k;
L = A^(t*lans);
R = B^(t*lans);
if(L>R)swap(L,R);
lans = solve(L,R,k);
cout<<lans<<endl;
}
}
return 0;
}
/**
6 1
1 1 2
3 2 4 2
1 3 5
3 2 3 1
2 1
3 0 3 1
6 0
1 3 10
1 3 5
3 6 10 6
2 1
1 3 10
3 6 4 2
*/
Compilation message
segments.cpp: In function 'void insert(int, int, int)':
segments.cpp:16:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for(i=0; i<all.size()/crit; i++)
| ~^~~~~~~~~~~~~~~~
segments.cpp:51:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(i=0; i<all.size()/crit; i++)
| ~^~~~~~~~~~~~~~~~
segments.cpp: In function 'int solve(int, int, int)':
segments.cpp:86:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for(i=0; i<all.size()/crit; i++)
| ~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
5 ms |
2396 KB |
Output is correct |
4 |
Correct |
4 ms |
2396 KB |
Output is correct |
5 |
Incorrect |
7 ms |
2652 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
735 ms |
4760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
89 ms |
2944 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
84 ms |
2900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
5 ms |
2396 KB |
Output is correct |
4 |
Correct |
4 ms |
2396 KB |
Output is correct |
5 |
Incorrect |
7 ms |
2652 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
5 ms |
2396 KB |
Output is correct |
4 |
Correct |
4 ms |
2396 KB |
Output is correct |
5 |
Incorrect |
7 ms |
2652 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |