求助 两年没写代码了qwq
  • 板块CF1017G The Tree
  • 楼主IhpEcVns
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/12/22 01:53
  • 上次更新2024/12/22 11:36:49
查看原帖
求助 两年没写代码了qwq
534425
IhpEcVns楼主2024/12/22 01:53
#include<bits/stdc++.h>
#define M int m=l+r>>1;
#define 左 u*2
#define 右 u*2+1
#define C(u,l,r)g[u]=1,s[u]={l-r-1,-1};
#define H if(g[u]){g[u]=0;C(左,l,m);C(右,m+1,r);}
#define U s[u]=s[左]+s[右];
#define X(a)auto a=[&](auto O,int u,int l,int r)->
#define Y(a)auto a=[&](auto O,int u)->void
int main(){
	using namespace std;
	int n,q,o,x,L,R;cin>>n>>q;++n;
	vector<int>T(n),f(n),F(n),z(n);
	{
	    vector<basic_string<int>>G(n);vector<int>s(n);
		for(int i=2;i<n;++i)cin>>f[i],G[f[i]]+=i;
	    Y(d){
			for(z[u]=1;int&v:G[u])
				if(O(O,v),z[u]+=z[v],z[v]>z[s[u]])s[u]=v;
	    };d(d,1);
		Y(D){
			static int t=0;
			int o=s[u];T[u]=++t;
			if(!o)return;
			F[o]=F[u],O(O,o);
			for(int&v:G[u])if(v^o)O(O,F[v]=v);
		};F[1]=1;D(D,1);
	}
	struct S{
		int a,b;
		S(int a=-1,int b=-1):a(a),b(b){}
		S operator+(const S&B){
			return S(a+B.a,max(B.b,b+B.a));
		}
	};
	vector<S>s(n*4);vector<bool>g(n*4);--n;
	X(B)void{
		if(l==r)return;M
		O(O,左,l,m);O(O,右,m+1,r);U
	};B(B,1,1,n);
	X(A)void{
		if(l==r){s[u].a+=R,s[u].b+=R;return;}M H
		L>m?O(O,右,m+1,r):O(O,左,l,m);U
	};
	X(D)void{
		if(L<=l&&r<=R){C(u,l,r);return;}M H
		if(L<=m)O(O,左,l,m);if(m<R)O(O,右,m+1,r);U
	};
	X(Q)S{
		if(L<=l&&r<=R)return s[u];M H S s{0,-1};
		if(L<=m)s=s+O(O,左,l,m);if(m<R)s=s+O(O,右,m+1,r);
		return s;
	};
	auto y=[&](int x){
		S y{0,-1};
		while(x)R=T[x],L=T[F[x]],y=y+Q(Q,1,1,n),x=f[F[x]];
		return y.b;
	};
	while(q--){
		cin>>o>>x;
		if(o==1)L=T[x],R=1,A(A,1,1,n);
		if(o==2)
			L=T[x],R=T[x]+z[x]-1,D(D,1,1,n),
			R=-1-y(x),L=T[x],A(A,1,1,n);
		if(o==3)puts(y(x)>=0?"black":"white");
	}
}
2024/12/22 01:53
加载中...