传送门

好珂怕……

树分块是什么东西啊……感觉好暴力……

直接贴一下好了->这里

 //minamoto
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[<<],*p1=buf,*p2=buf;
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,:;}
inline int read(){
#define num ch-'0'
char ch;bool flag=;int res;
while(!isdigit(ch=getc()))
(ch=='-')&&(flag=true);
for(res=num;isdigit(ch=getc());res=res*+num);
(flag)&&(res=-res);
#undef num
return res;
}
char sr[<<],z[];int C=-,Z;
inline void Ot(){fwrite(sr,,C+,stdout),C=-;}
inline void print(int x){
if(C><<)Ot();if(x<)sr[++C]=,x=-x;
while(z[++Z]=x%+,x/=);
while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=,SIZE=;
int head[N],Next[N<<],ver[N<<],tot;
inline void add(int u,int v){
ver[++tot]=v,Next[tot]=head[u],head[u]=tot;
}
int n,m,cnt,w[N],bh[N],bt,fa[N],belong[N],bn[N<<],bv[N<<];
struct Block{
vector<int> a;
Block(){a.clear();}
inline void ins(int x){
a.push_back(x);
for(int i=a.size()-;i;--i)
if(a[i-]>a[i]) swap(a[i-],a[i]);else break;
}
inline void update(int x,int k){
int pos=lower_bound(a.begin(),a.end(),x)-a.begin();
a[pos]=k;
for(int i=pos;i;--i)
if(a[i-]>a[i]) swap(a[i-],a[i]);else break;
for(int i=pos,s=a.size()-;i<s;++i)
if(a[i]>a[i+]) swap(a[i],a[i+]);else break;
}
inline int query(int x){
return a.end()-upper_bound(a.begin(),a.end(),x);
}
}bl[N];
inline void add_bl(int u,int v){
bv[++bt]=v,bn[bt]=bh[u],bh[u]=bt;
}
void dfs(int u,int f){
fa[u]=f;
if(bl[belong[f]].a.size()==SIZE){
belong[u]=++cnt;
bl[cnt].ins(w[u]);
add_bl(belong[f],cnt);
}
else{
belong[u]=belong[f],bl[belong[u]].ins(w[u]);
}
for(int i=head[u];i;i=Next[i]){
if(ver[i]!=f) dfs(ver[i],u);
}
}
int dfsbl(int u,int k){
int ans=bl[u].query(k);
for(int i=bh[u];i;i=bn[i])
ans+=dfsbl(bv[i],k);
return ans;
}
int dfsans(int u,int k){
int ans=w[u]>k?:;
for(int i=head[u];i;i=Next[i]){
int v=ver[i];
if(v==fa[u]) continue;
if(belong[v]==belong[u]) ans+=dfsans(v,k);
else ans+=dfsbl(belong[v],k);
}
return ans;
}
int main(){
//freopen("testdata.in","r",stdin);
n=read();
for(int i=;i<n;++i){
int u=read(),v=read();add(u,v),add(v,u);
}
for(int i=;i<=n;++i) w[i]=read();
dfs(,);
m=read();
int ans=;
while(m--){
int opt=read(),u=read(),x=read();
u^=ans,x^=ans;
switch(opt){
case :ans=dfsans(u,x);print(ans);break;
case :bl[belong[u]].update(w[u],x);w[u]=x;break;
case :{
w[++n]=x,add(u,n),fa[n]=u;
if(bl[belong[u]].a.size()==SIZE){
belong[n]=++cnt,bl[cnt].ins(w[n]);
add_bl(belong[u],cnt);
}
else{
belong[n]=belong[u],bl[belong[n]].ins(w[n]);
}
break;
}
}
}
Ot();
return ;
}
05-23 22:57