求各位大佬找错,谢谢。
查看原帖
求各位大佬找错,谢谢。
448881
PTqwq楼主2021/7/27 13:24
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=200005;
int lc[maxn<<2],rc[maxn<<2],s[maxn<<2],lv[maxn<<2],rv[maxn<<2];
void push_up(int u,int len1,int len2)
{
	lv[u]=lv[u<<1];
	rv[u]=rv[u<<1|1];
	lc[u]=rc[u<<1];
	rc[u]=rc[u<<1|1];
	s[u]=max(s[u<<1],s[u<<1|1]);
	if(rv[u<<1]!=lv[u<<1|1])
	{
		if(len1==s[u<<1])
		{
			lc[u]=max(lc[u],len1+lc[u<<1|1]);	
		}	
		if(len2==s[u<<1|1])
		{
			rc[u]=max(lc[u],len2+rc[u<<1]);
		}
		s[u]=max(s[u],rc[u<<1]+lc[u<<1|1]);
	}	
}
void build(int u,int l,int r)
{
	if(l==r)
	{
		lv[u]=rv[u]=0;
		lc[u]=rc[u]=s[u]=1;
		return;
	}
	int mid=l+r>>1;
	build(u<<1,l,mid);
	build(u<<1|1,mid+1,r);
	push_up(u,mid-l+1,r-mid);
}
void update(int u,int l,int r,int x)
{
	if(l==r)
	{
		lv[u]=rv[u]=!lv[u];
		return;
	}
	int mid=l+r>>1;
	if(x<=mid)
	{
		update(u<<1,l,mid,x);
	}
	else
	{
		update(u<<1|1,mid+1,r,x);
	}
	push_up(u,mid-l+1,r-mid);
}
signed main()
{
	//freopen("step.in.1","r",stdin);
	//freopen("step.out","w",stdout); 
	int n,q;
    cin >> n >> q;
	build(1,1,n);
	while(q--)
	{
	    int x;
		cin >> x;
		update(1,1,n,x);
		cout << s[1] << endl;
	}
	return 0;
}

一直16分。。。。。。

2021/7/27 13:24
加载中...