https://www.luogu.com.cn/problem/P6492
思路:类比维护连续的1.模板
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+100;
typedef int LL;
struct Tree{
LL l,r,pre,suf,sum;
}tree[maxn*4];
LL a[maxn];
LL rmax(LL A,LL B,LL C){
return max(A,max(B,C));
}
void push_up(LL p){
tree[p].pre=tree[p*2].pre;
tree[p].suf=tree[p*2+1].suf;
tree[p].sum=max(tree[p*2].sum,tree[p*2+1].sum);
if(a[tree[p*2].r]!=a[tree[p*2+1].l]) tree[p].sum=max(tree[p].sum,tree[p*2].suf+tree[p*2+1].pre);
if(tree[p*2].pre==tree[p*2].r-tree[p*2].l+1&&a[tree[p*2].r]!=a[tree[p*2+1].l]) tree[p].pre+=tree[p*2+1].pre;
if(tree[p*2+1].suf==tree[p*2+1].r-tree[p*2+1].l+1&&a[tree[p*2].r]!=a[tree[p*2+1].l]) tree[p].suf+=tree[p*2].suf;
}
void build(LL p,LL l,LL r){
tree[p].l=l;tree[p].r=r;tree[p].pre=tree[p].suf=tree[p].sum=1;
if(l==r) {return;}
LL mid=(l+r)>>1;
build(p*2,l,mid);build(p*2+1,mid+1,r);
push_up(p);
}
void modify(LL p,LL l,LL r){
if(tree[p].l==tree[p].r){
if(a[tree[p].l]==1){
a[tree[p].r]=0;
}
else if(a[tree[p].l]==0){
a[tree[p].l]=1;
}
return;
}
LL mid=(tree[p].l+tree[p].r)>>1;
if(l<=mid) modify(p*2,l,r);
if(r>mid) modify(p*2+1,l,r);
push_up(p);
}
LL query(LL p,LL l,LL r){
return tree[p].sum;
}
int main(void)
{
cin.tie(0);std::ios::sync_with_stdio(false);
LL n,m;cin>>n>>m;
for(LL i=1;i<=n;i++){
a[i]=1;
}
build(1,1,n);
while(m--){
LL x;cin>>x;
modify(1,x,x);
cout<<query(1,1,n)<<endl;
}
return 0;
}