验证了一发自己还有水平之后就懒得写了
直接上维修数列那题的模板TAT
#include "algorithm"
#include "iostream"
#include "stdlib.h"
#include "stdio.h"
#include "math.h"
using namespace std;
const int inf= (int)1e9,N=100005;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
struct node {
node *c[2],*fa;
bool rev; int tag,siz;
int lmx,rmx,smx,sum,key;
node();
void push_up();
void push_down();
void ins(node *lc,node *rc,node *f,int _k);
} Tnull ,*null=&Tnull, *root=null;
void seq(node *x,int tot,bool rv){
if (x->tag&&tot==inf) tot=x->key;
int l=x->rev^rv,r=l^1;
if (x->c[l]!=null) printf("{ "),seq(x->c[l],tot,l),printf(" }");
if (tot==inf) printf ("[%d L=%d,R=%d,M=%d,S=%d] ",x->key,x->lmx,x->rmx,x->smx,x->sum);
else printf ("[%d L=%d,R=%d,M=%d,S=%d] ",tot,max(tot,tot*x->siz),max(tot,tot*x->siz),max(tot,tot*x->siz),tot*x->siz);
if (x->c[r]!=null) printf("{ "),seq(x->c[r],tot,l),printf(" }");
}
int ___write[N],cnt;
void check(node *x){
x->push_down();
if (x->c[0]!=null) check(x->c[0]);
___write[cnt++]=x->key;
if (x->c[1]!=null) check(x->c[1]);
}
node:: node(){
c[0]=c[1]=fa=null;
}
void node :: push_up(){
c[0]->push_down(); c[1]->push_down();
sum=c[0]->sum+c[1]->sum+key;
siz=c[0]->siz+c[1]->siz+1;
lmx=rmx=smx=-inf;
if (c[0]!=null&&c[1]!=null){
lmx=max(c[0]->lmx,c[0]->sum+key+max(c[1]->lmx,0));
rmx=max(c[1]->rmx,c[1]->sum+key+max(c[0]->rmx,0));
smx=max(max(c[0]->smx,c[1]->smx),max(c[0]->rmx,0)+max(c[1]->lmx,0)+key);
} else {
if (c[0]==null&&c[1]==null){
lmx=rmx=smx=key;
} else {
if (c[0]==null){
lmx=max(c[1]->lmx,0)+key;
rmx=max(c[1]->rmx,c[1]->sum+key);
smx=max(c[1]->smx,max(c[1]->lmx,0)+key);
} else {
lmx=max(c[0]->lmx,c[0]->sum+key);
rmx=max(c[0]->rmx,0)+key;
smx=max(c[0]->smx,max(c[0]->rmx,0)+key);
}
}
}
}
void node :: push_down(){
if (tag){
if(c[0]!=null){
c[0]->tag=1; c[0]->key=key; c[0]->sum=key*c[0]->siz;
c[0]->lmx=c[0]->rmx=c[0]->smx=max(key,key*c[0]->siz);
}
if(c[1]!=null){
c[1]->tag=1; c[1]->key=key; c[1]->sum=key*c[1]->siz;
c[1]->lmx=c[1]->rmx=c[1]->smx=max(key,key*c[1]->siz);
}
tag=0;
}
if (rev){ rev=0;
if(c[0]!=null) c[0]->rev^=1;
if(c[1]!=null) c[1]->rev^=1;
swap(c[0],c[1]); swap(lmx,rmx);
}
}
void node :: ins (node *lc,node *rc,node *f,int _k){
c[0]=lc; c[1]=rc; fa=f;
key=lmx=rmx=smx=_k;
push_up(); tag=rev=0;
}
node * build (int *x,int l){
if (l<=0) return null;
int mid=(l+1)>>1;
node * d=new node();
node *c0=build(x,mid-1);
node *c1=build(x+mid,l-mid);
if (c0!=null) c0->fa=d;
if (c1!=null) c1->fa=d;
d->ins(c0,c1,null,x[mid]);
return d;
}
node * find_rank (int rank,node *x){
x->push_down(); node* rk;
if (x->c[0]->siz+1==rank) return x;
if (x->c[0]->siz>=rank) rk=find_rank(rank,x->c[0]);
else rk=find_rank(rank-x->c[0]->siz-1,x->c[1]);
x->push_up(); return rk;
}
void rotate (node *x,node *& f){
node *y=x->fa,*z=y->fa; int l,r;
if (y->c[0]==x) l=0; else l=1; r=l^1;
if (y==f) f=x;
if (z!=null){
if(z->c[0]==y) z->c[0]=x;
else z->c[1]=x;
}
x->fa=z; y->fa=x;
if(x->c[r]!=null) x->c[r]->fa=y;
y->c[l]=x->c[r]; x->c[r]=y;
y->push_up(); x->push_up();
}
void splay (node * x, node * & f){
while (x!=f){
node *y=x->fa,*z=y->fa;
if (y!=f){
if (z->c[0]==y ^ y->c[0]==x) rotate(x,f);
else rotate(y,f);
}
rotate(x,f);
}
if(f->fa!=null) f->fa->push_up();
}
void insert (int pos,int *x,int l){
node * q=find_rank(pos,root);
node * qq=find_rank(pos+1,root);
splay (q,root); splay(qq,root->c[1]);
root->c[1]->c[0]=build(x,l); root->c[1]->c[0]->fa=root->c[1];
root->c[1]->push_up(); root->push_up();
}
void deleteit (node * x){
if (x->c[0]!=null) deleteit(x->c[0]);
if (x->c[1]!=null) deleteit(x->c[1]);
delete x;
}
void del (int pos,int tot){
node * q=find_rank(pos-1,root);
node * qq=find_rank(pos+tot-1,root);
splay (q,root); splay (qq,root->c[1]);
node * freeit=root->c[1]; root->c[1]=root->c[1]->c[1];
root->c[1]->fa=root; freeit->c[1]=null; deleteit(freeit);
root->push_up();
}
void make_same (int pos,int tot,int v){
node * q=find_rank(pos-1,root);
node * qq=find_rank(pos+tot,root);
splay (q,root); splay (qq,root->c[1]);
node * t=root->c[1]->c[0]; t->tag=1; t->key=v; t->sum=v*t->siz;
t->lmx=t->rmx=t->smx=max(v,v*t->siz); t->push_down();
root->c[1]->push_up(); root->push_up();
}
void reverse(int pos,int tot){
node * q=find_rank(pos-1,root);
node * qq=find_rank(pos+tot,root);
splay (q,root); splay (qq,root->c[1]);
node * t=root->c[1]->c[0]; t->rev^=1; t->push_down();
t->fa->push_up(); t->fa->fa->push_up();
}
int querysum(int pos,int tot){
node * q=find_rank(pos-1,root);
node * qq=find_rank(pos+tot,root);
splay (q,root); splay (qq,root->c[1]);
return root->c[1]->c[0]->sum;
}
int maxsum(){
node * q=find_rank(1,root);
node * qq=find_rank(root->siz,root);
splay (q,root); splay (qq,root->c[1]);
return root->c[1]->c[0]->smx;
}
int n,m,data[N];
int main(){
n=read(),m=read(); int i,pos,tot,j;
for (i=1;i<=n;i++) data[i]=i;
root=build(data-1,n+2);
for (i=1;i<=m;i++) {
pos=read(); tot=read();
reverse(pos+1,tot-pos+1);
}
check(root);
for (i=1;i<=n;i++) printf("%d ",___write[i]);
return 0;
}