#include using namespace std; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a > G,par; vector dep; LowestCommonAncestor(){} LowestCommonAncestor(Int n):n(n),G(n),dep(n){ h=1; while((1<(n,-1)); } void add_edge(Int u,Int v){ G[u].emplace_back(v); G[v].emplace_back(u); } void dfs(Int v,Int p,Int d){ par[0][v]=p; dep[v]=d; for(Int u:G[v]) if(u!=p) dfs(u,v,d+1); } void build(Int r=0){ dfs(r,-1,0); for(Int k=0;k+1dep[v]) swap(u,v); for(Int k=0;k>k&1) v=par[k][v]; if(u==v) return u; for(Int k=h-1;k>=0;k--) if(par[k][u]!=par[k][v]) u=par[k][u],v=par[k][v]; return par[0][u]; } Int distance(Int u,Int v){ return dep[u]+dep[v]-dep[lca(u,v)]*2; } }; template struct SegmentTree{ using F = function; Int n; F f; T ti; vector dat; SegmentTree(){} SegmentTree(F f,T ti):f(f),ti(ti){} void init(Int n_){ n=1; while(n &v){ Int n_=v.size(); init(n_); for(Int i=0;i>=1) dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]); } T query(Int a,Int b){ if(a>=b) return ti; T vl=ti,vr=ti; for(Int l=a+n,r=b+n;l>=1,r>>=1) { if(l&1) vl=f(vl,dat[l++]); if(r&1) vr=f(dat[--r],vr); } return f(vl,vr); } template Int find(Int st,C &check,T &acc,Int k,Int l,Int r){ if(l+1==r){ acc=f(acc,dat[k]); return check(acc)?k-n:-1; } Int m=(l+r)>>1; if(m<=st) return find(st,check,acc,(k<<1)|1,m,r); if(st<=l&&!check(f(acc,dat[k]))){ acc=f(acc,dat[k]); return -1; } Int vl=find(st,check,acc,(k<<1)|0,l,m); if(~vl) return vl; return find(st,check,acc,(k<<1)|1,m,r); } template Int find(Int st,C &check){ T acc=ti; return find(st,check,acc,1,0,n); } }; template struct FixPoint : F{ FixPoint(F&& f):F(forward(f)){} template decltype(auto) operator()(Args&&... args) const{ return F::operator()(*this,forward(args)...); } }; template inline decltype(auto) MFP(F&& f){ return FixPoint{forward(f)}; } //INSERT ABOVE HERE signed main(){ cin.tie(0); ios::sync_with_stdio(0); Int n,k,q; cin>>n>>k>>q; vector cs(n),as(k); for(Int i=0;i>cs[i]; for(Int i=0;i>as[i],as[i]--; vector> G(n); LowestCommonAncestor lca(n); for(Int i=1;i>e>>f; e--;f--; G[f].emplace_back(e); lca.add_edge(e,f); } lca.build(0); vector ans(n); MFP([&](auto dfs,Int v,Int x)->void{ chmax(x,cs[v]); ans[v]=x; for(Int u:G[v]) dfs(u,x); })(0,-1); Int ti=-1; auto f=[&](Int u,Int v){ if(u==ti) return v; if(v==ti) return u; return lca.lca(u,v); }; SegmentTree seg(f,ti); seg.build(as); for(Int i=0;i>t; if(t==1){ Int x,y; cin>>x>>y; x--;y--; as[x]=y; seg.set_val(x,as[x]); } if(t==2){ Int l,r; cin>>l>>r; l--; cout<