社区讨论

16分 求调

P6492[COCI 2010/2011 #6] STEP参与者 2已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@mhjlawdp
此快照首次捕获于
2025/11/04 04:25
4 个月前
此快照最后确认于
2025/11/04 04:25
4 个月前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e5+2;
int n,t;
struct node{
	int w,l1,r1,len;
	bool L1,R1;
}c[MAXN*4];
void pushup(int u){
	int mid_cnt=0;
	if(c[u*2].R1!=c[u*2+1].L1)
		mid_cnt=c[u*2].r1+c[u*2+1].l1;
	c[u].w=max(c[u*2].w,max(c[u*2+1].w,mid_cnt));
	c[u].L1=c[u*2].L1;c[u].R1=c[u*2+1].R1;
	c[u].len=c[u*2].len+c[u*2+1].len;
	if(c[u*2].l1==c[u*2].len&&c[u*2+1].r1==c[u*2+1].len&&mid_cnt){
		c[u].l1=c[u].r1=c[u].len;
		return ;
	}
	c[u].l1=c[u*2].l1;
	if(c[u*2].l1==c[u*2].len) c[u].l1=max(mid_cnt,c[u].l1);
	c[u].r1=c[u*2+1].r1;
	if(c[u*2+1].r1==c[u*2].len) c[u].r1=max(mid_cnt,c[u].r1);
	return ;
}
void build(int u,int l,int r){
	if(l==r){
		c[u].w=c[u].len=c[u].l1=c[u].r1=1;
		c[u].L1=c[u].R1=false;
		return ;
	}
	int mid=(l+r)/2;
	build(u*2,l,mid);
	build(u*2+1,mid+1,r);
	pushup(u);
	return ;
}
void update(int u,int l,int r,int x){
	if(l==r){
		if(c[u].L1==true) c[u].L1=false;
		else c[u].L1=true;
		c[u].R1=c[u].L1;
		return ;
	}
	int mid=(l+r)/2;
	if(mid>=x) update(u*2,l,mid,x);
	else update(u*2+1,mid+1,r,x);
	pushup(u);
}
int main(){
	scanf("%d%d",&n,&t);
	build(1,1,n);
	while(t--){
		int x;
		scanf("%d",&x);
		update(1,1,n,x);
		printf("%d\n",c[1].w);
	}
	return 0;
}

回复

1 条回复,欢迎继续交流。

正在加载回复...