/ Randle /

记录详情

Runtime Error


  
# 状态 耗时 内存占用
#1 Wrong Answer 178ms 14.254 MiB
#2 Runtime Error 151ms 16.566 MiB
#3 Runtime Error 94ms 16.262 MiB
#4 Runtime Error 94ms 16.816 MiB
#5 Runtime Error 94ms 16.453 MiB
#6 Runtime Error 122ms 16.699 MiB
#7 Runtime Error 127ms 16.664 MiB
#8 Runtime Error 112ms 17.184 MiB
#9 Runtime Error 126ms 16.953 MiB

代码

#include<bits/stdc++.h>
inline const void read(int &a)
{
	a=0;char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')
	{
		a=(a<<1)+(a<<3)+c-'0';
		c=getchar();
	}
}
inline const void write(int a)
{
	if(a<0){putchar('-');a=-a;}
	if(a>=10)write(a/10);
	putchar(a%10+'0');
}
#define maxn 300001
int n,m,d=0;
int next[maxn],to[maxn],point[maxn],deep[maxn],father[maxn],son[maxn];
int num[maxn];
inline const void add(int a,int b)
{
	next[++d]=point[a];
	point[a]=d;
	to[d]=b;
}
#define lowbit(a) a&(-a)
int sum[maxn];
inline const void modify(int a,int b)
{
	while(a<=n)
	{
		sum[a]+=b;
		a+=lowbit(a);
	}
}
inline const int query(int a)
{
	int ans=0;
	while(a)
	{
		ans+=sum[a];
		a-=lowbit(a);
	}
	return ans;
}
inline const int dfs1(int p)
{
	int side=point[p];
	num[p]=1;
	while(side)
	{
		if(to[side]!=father[p])
		{
			father[to[side]]=p;
			deep[to[side]]=deep[p]+1;
			num[p]+=dfs1(to[side]);
			if(num[to[side]]>num[son[p]])son[p]=to[side];
		}
		side=next[side];
	}
	return num[p];
}
int loc[maxn],top[maxn];
int cnt=0,left[maxn],right[maxn];
inline const void dfs2(int p,int tp)
{
	loc[p]=++cnt;
	left[p]=cnt;
	top[p]=tp;
	int side=point[p];
	if(son[p])dfs2(son[p],tp);
	while(side)
	{
		if(to[side]!=father[p]&&to[side]!=son[p])
		{
			dfs2(to[side],to[side]);
		}
		side=next[side];
	}
	right[p]=cnt;
	modify(loc[p],1);modify(right[p]+1,-1);
}
int main()
{
	memset(father,0,sizeof(father));
	memset(deep,0,sizeof(deep));
	memset(point,0,sizeof(point));
	memset(sum,0,sizeof(sum));
	memset(num,0,sizeof(num));
	memset(son,0,sizeof(son));
	read(n);read(m);
	int u,v,x;
	for(int i=1;i<=n-1;i++)
	{
		read(u);read(v);
		add(u,v);add(v,u);
	}
	dfs1(1);
	dfs2(1,1);
	char c;
	int change1[maxn],change2[maxn],r=0;
	while(m)
	{
		scanf("%c",&c);
		if(c=='Q')
		{
			bool yes=true;
			read(u);read(v);
			while(top[u]!=top[v])
			{
				if(deep[top[u]]<deep[top[v]])std::swap(u,v);
				if(query(loc[u])-query(loc[top[u]]-1)<deep[u]-deep[top[u]]){yes=false;break;}
				u=father[top[u]];
			}
			if(deep[u]<deep[v])std::swap(u,v);
			if(query(loc[u])-query(loc[v]-1)<deep[u]-deep[top[u]])yes=false;
			if(!yes)puts("No");
			else puts("Yes");
		}
		if(c=='C')
		{
			read(u);read(v);
			if(deep[u]>deep[v])std::swap(u,v);
			change1[++r]=u;change2[r]=v;
			modify(loc[u],-1);modify(right[u]+1,1);
		}
		if(c=='U')
		{
			read(x);
			u=change1[x];v=change2[x];
			modify(loc[u],1);modify(right[u]+1,-1);
		}
		m--;
	}
	return 0;
}

信息

递交者
类型
递交
题目
部落冲突(数据加强)
题目数据
下载
语言
C++
递交时间
2017-10-30 19:46:11
评测时间
2017-10-30 19:46:11
评测机
分数
0
总耗时
1102ms
峰值内存
17.184 MiB