#include using namespace std; using ll = long long; template using Pa = pair; template using vec = vector; template using vvec = vector>; template class SegmentTree{ private: int sz; vector seg; const F op; const Monoid e; public: SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){ sz = 1; while(sz<=n) sz <<= 1; seg.assign(2*sz,e); } void set(int k, const Monoid &x){ seg[k+sz] = x; } void build(){ for(int i=sz-1;i>0;i--){ seg[i] = op(seg[2*i],seg[2*i+1]); } } void update(int k,const Monoid &x){ k += sz; seg[k] = x; while(k>>=1){ seg[k] = op(seg[2*k],seg[2*k+1]); } } Monoid query(int l,int r){ Monoid L = e,R = e; for(l+=sz,r+=sz;l>=1,r>>=1){ if(l&1) L = op(L,seg[l++]); if(r&1) R = op(seg[--r],R); } return op(L,R); } Monoid operator[](const int &k)const{ return seg[k+sz]; } }; class LeastCommonAncestor{ private: vector> v; vector> parent; vector depth; int h = 0; void dfs(int n,int m,int d){ parent[0][n] = m; depth[n] = d; for(auto x:v[n]){ if(x!=m) dfs(x,n,d+1); } } public: LeastCommonAncestor(int N,int root,vector>& tree){ while((1<>(h,vector(N,0)); depth = vector(N,0); dfs(root,-1,0); for(int j=0;j+1depth[m]) swap(n,m); for(int j=0;j> j&1) m = parent[j][m]; } if(n==m) return n; for(int j=h-1;j>=0;j--){ if(parent[j][n]!=parent[j][m]){ n = parent[j][n]; m = parent[j][m]; } } return parent[0][n]; } int dep(int n){return depth[n];} }; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N,K,Q; cin >> N >> K >> Q; vec C(N),A(K); for(int i=0;i> C[i]; for(int i=0;i> A[i]; A[i]--; } vvec g(N); for(int i=0;i> a >> b; a--; b--; g[b].push_back(a); } LeastCommonAncestor LCA(N,0,g); auto dfs = [&](auto&& self,int cur,int par,int val)->void{ C[cur] = max(C[cur],val); for(auto& to:g[cur]) if(to!=par){ self(self,to,cur,C[cur]); } }; dfs(dfs,0,-1,-1); auto op = [&](int a,int b){ if(a==-1) return b; if(b==-1) return a; return LCA.lca(a,b); }; SegmentTree seg(K,op,-1); for(int i=0;i> t >> a >> b; a--; b--; if(t==1){ seg.update(a,b); }else{ // cerr << seg.query(a,b+1) << " "; cout << C[seg.query(a,b+1)] << "\n"; } } }