Title Description
Since the topic lazy person so there is no background.
An infinitely long $ 01 $ sequence, initially full of $ 0 $, each time selecting a range $ [l, r] $ operation, there are three operations:
$ \ bullet. 1 \ L \ R & lt $ a $ [l, r] $ all the elements to become $ 1 $.
$ \ bullet 2 \ l \ r $ a $ [l, r] $ all elements into $ 0 $.
$ \ bullet 3 \ l \ r $ a $ [l, r] $ all elements exclusive $ 1 or $.
After each operation asked the leftmost position at which $ 0 $.
Input Format
A first line number $ m $, represents the sequence length and the number of operations.
Next $ m $ rows of three numbers $ ty \ l \ r $, one operation is described.
Output Format
Total $ m $ output line, the line output $ i $ a $ i represents the number of answers after $ operations.
Sample
Sample input:
3
1 3 4
3 1 6
2 1 3
Sample output:
1
3
1
Data range and tips
$ N-order is $ $ \ max (r) $.
For the test point $ 1 \ sim 4 $: $ n, m \ leqslant 10 ^ 3 $.
For the test point $ 5 \ sim 6 $: 1 $ operation only $.
For the test point $ 7 \ sim 10 $: $ 1, $ operation only.
For the test point $ 11 \ sim 15 $: $ n \ leqslant 10 ^ 5 $.
For the test point $ 16 \ sim 20 $: no special restrictions.
For all data, $ n \ leqslant 10 ^ { 18}, m \ leqslant 10 ^ 5 $.
answer
Look at the data range, it is certainly to be discrete, and discrete but also need to pay attention when the $ l + 1 $ and $ r + 1 $ discrete.
In the case of operating only $ 1,2 $, we can maintain directly with the tree line.
So consider the case $ 3 $ how we can deal with.
If some sections are the same, we can directly turn it over, then $ return $.
But doing so can be easily swap cards, say $ 0101010 ...... $ sequence is, every time performing operations $ 3 $, then get caught into $ n ^ 2 $.
But for this to $ A $ Keduo Li tree can be out of the question, which is irrelevant.
Time complexity: $ \ Theta (n) \ sim \ Theta (n ^ 2) $.
Expectations score: $ 100 $ points.
Actual score: $ 100 $ points.
Code time
#include<bits/stdc++.h>
#define L(x) x<<1
#define R(x) x<<1|1
#define inf 0x3f3f3f3f
using namespace std;
map<long long,long long> mp;
struct rec{int ty;long long l,r;}e[200001];
int m;
int n;
long long pre[5000000];
long long trsam[10000000],trans[10000000],lz[10000000];
void pushup(int x)
{
trans[x]=min(trans[L(x)],trans[R(x)]);
trsam[x]=(trsam[L(x)]==trsam[R(x)])?trsam[L(x)]:-1;
}
void pushdown(int x,int l,int r)
{
if(lz[x]==-1)return;
int mid=(l+r)>>1;
lz[L(x)]=lz[R(x)]=trsam[L(x)]=trsam[R(x)]=lz[x];
if(!trsam[L(x)])trans[L(x)]=l;
else trans[L(x)]=inf;
if(!trsam[R(x)])trans[R(x)]=mid+1;
else trans[R(x)]=inf;
lz[x]=-1;
}
void build(int x,int l,int r)
{
trans[x]=inf;
lz[x]=-1;
if(l==r)
{
trans[x]=l;
return;
}
int mid=(l+r)>>1;
build(L(x),l,mid);
build(R(x),mid+1,r);
pushup(x);
}
void change(int x,int l,int r,int L,int R,int opt)
{
if(R<l||r<L)return;
if(L<=l&&r<=R&&trsam[x]!=-1)
{
switch(opt)
{
case 1:trsam[x]=1;lz[x]=1;break;
case 2:trsam[x]=0;lz[x]=0;break;
case 3:trsam[x]^=1;lz[x]=trsam[x];break;
}
if(!trsam[x])trans[x]=l;
else trans[x]=inf;
return;
}
int mid=(l+r)>>1;
pushdown(x,l,r);
change(L(x),l,mid,L,R,opt);
change(R(x),mid+1,r,L,R,opt);
pushup(x);
}
int main()
{
scanf("%d",&m);
for(int i=1;i<=m;i++)
scanf("%d%lld%lld",&e[i].ty,&e[i].l,&e[i].r);
for(int i=1;i<=m;++i)
{
pre[i*4-3]=e[i].l, pre[i*4-2]=e[i].r;
pre[i*4-1]=e[i].l+1, pre[i*4]=e[i].r+1;
}
pre[m*4+1]=1;
sort(pre+1,pre+m*4+2);
n=unique(pre+1,pre+m*4+2)-pre-1;
for(int i=1;i<=m;++i)
{
mp[lower_bound(pre+1,pre+n+1,e[i].r+1)-pre]=e[i].r+1;
mp[lower_bound(pre+1,pre+n+1,e[i].l+1)-pre]=e[i].l+1;
long long now=e[i].l;
e[i].l=lower_bound(pre+1,pre+n+1,e[i].l)-pre;
mp[e[i].l]=now;
now=e[i].r;
e[i].r=lower_bound(pre+1,pre+n+1,e[i].r)-pre;
mp[e[i].r]=now;
}
mp[1]=1;
build(1,1,n);
for(int i=1;i<=m;++i)
{
change(1,1,n,e[i].l,e[i].r,e[i].ty);
printf("%lld\n",mp[trans[1]]);
}
return 0;
}
rp++