树剖和线段树没挂,应该是询问函数挂了,思路是找到含被修改过的节点的重链然后二分,求调
while(q--)
{
char opt;
cin>>opt;
if(opt=='C')
{
int x=read();
change(dfn[x],dfn[x],1,1);
}
if(opt=='Q')
{
ans=0;
int u=read();
ask(dfn[u],dfn[u],1);
if(ans)
{
printf("%d\n",u);
continue;
}
while(top[u]!=1)
{
ask(dfn[top[u]],dfn[u],1);
if(ans!=0) break;
u=fa[top[u]];
}
ask(1,dfn[u],1);
if(ans==0)
{
puts("1");
continue;
}
int l=dfn[top[u]],r=dfn[u],mid;
while(l<=r)
{
ans=0;
mid=(l+r)>>1;
ask(l,mid,1);
if(ans!=0) r=mid-1;
else l=mid+1;
}
printf("%d\n",l);
}
}