BZOJ4551: [Tjoi2016&Heoi2016]树
Description
Input
Output
输出一个正整数,表示结果
Sample Input
1 2
1 3
2 4
2 5
Q 2
C 2
Q 2
Q 5
Q 3
Sample Output
2
2
1
#include
#include
#include
#define LSON rt<<1
#define RSON rt<<1|1
#define DATA(x) b[x].data
#define LSIDE(x) b[x].l
#define RSIDE(x) b[x].r
#define MAXN 100010
using namespace std;
int n,m,c=1,d=1;
int head[MAXN],deep[MAXN],size[MAXN],son[MAXN],fa[MAXN],top[MAXN],id[MAXN],nid[MAXN];
struct node1{int next,to;
}a[MAXN<<1];
struct node2{int data,l,r;
}b[MAXN<<2];
inline int read(){int date=0,w=1;char c=0;while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}while(c>='0'&&c<='9'){date=date*10+c-'0';c=getchar();}return date*w;
}
inline void add(int x,int y){a[c].to=y;a[c].next=head[x];head[x]=c++;a[c].to=x;a[c].next=head[y];head[y]=c++;
}
void dfs1(int rt){son[rt]=0;size[rt]=1;for(int i=head[rt];i;i=a[i].next){int will=a[i].to;if(!deep[will]){deep[will]=deep[rt]+1;fa[will]=rt;dfs1(will);size[rt]+=size[will];if(size[son[rt]]>1;buildtree(l,mid,LSON);buildtree(mid+1,r,RSON);pushup(rt);
}
void update(int l,int r,int rt){int mid;if(l<=LSIDE(rt)&&RSIDE(rt)<=r){DATA(rt)=l;return;}mid=LSIDE(rt)+RSIDE(rt)>>1;if(l<=mid)update(l,r,LSON);if(mid>1;if(l<=mid)ans=max(ans,query(l,r,LSON));if(middeep[y])swap(x,y);s=max(s,query(id[x],id[y],1));printf("%d
",nid[s]);return;
}
void work(){char ch[2];int x;while(m--){scanf("%s",ch);x=read();if(ch[0]=='C')update(id[x],id[x],1);if(ch[0]=='Q')work1(1,x);}
}
void init(){int x,y;n=read();m=read();for(int i=1;i