#define _CRT_SECURE_NO_WARNINGS #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i, n) for(int i=0;i<(n);i++) #define REP(i, n) for(int i=1;i<=(n);i++) #define all(V) V.begin(),V.end() typedef long long lint; typedef std::pair P; constexpr int INF = INT_MAX; constexpr lint LINF = LLONG_MAX; constexpr double eps = 1e-9; template class prique :std::priority_queue, std::greater> {}; template> class Vector { using traits = std::allocator_traits; using size_type = unsigned int; class iterator { public: using difference_type = int; using value_type = T; using pointer = T*; using reference = T&; using iterator_category = std::random_access_iterator_tag; private: T* p; public: iterator()noexcept :p(nullptr) {} iterator(Vector* base, difference_type index) noexcept :p(base->e + index) {} iterator(const iterator& i) :p(i.p) {} iterator& operator=(const iterator& i) = default; iterator& operator++() { p++; return *this; } iterator operator++(int) { iterator res = *this; p++; return res; } iterator operator+(const difference_type& x)const { return iterator(*this) += x; } iterator& operator+=(const difference_type& x) { p += x; return *this; } iterator& operator--() { p--; return *this; } iterator operator--(int) { iterator res = *this; p--; return res; } iterator operator-(const difference_type& x)const { return iterator(*this) -= x; } difference_type operator-(const iterator& i)const { return p - i.p; } iterator& operator-=(const difference_type& x) { p -= x; return *this; } reference operator*()const { return *p; } reference operator[](const difference_type& x)const { return *(p + x); } bool operator<(const iterator& i)const { return p < i.p; } bool operator<=(const iterator& i)const { return p <= i.p; } bool operator==(const iterator& i)const { return p == i.p; } bool operator>(const iterator& i)const { return p > i.p; } bool operator>=(const iterator& i)const { return p >= i.p; } bool operator!=(const iterator& i)const { return p != i.p; } }; class const_iterator { public: using difference_type = int; using value_type = T; using pointer = const T*; using reference = const T&; using iterator_category = std::random_access_iterator_tag; private: const T* p; public: const_iterator()noexcept :p(nullptr) {} const_iterator(Vector* base, difference_type index) noexcept :p(base->e + index) {} const_iterator(const iterator& i) :p(i.p) {} const_iterator(const const_iterator& i) :p(i.p) {} const_iterator& operator=(const const_iterator& i) = default; const_iterator& operator++() { p++; return *this; } const_iterator operator++(int) { const_iterator res = *this; p++; return res; } const_iterator operator+(const difference_type& x)const { return const_iterator(*this) += x; } const_iterator& operator+=(const difference_type& x) { p += x; return *this; } const_iterator& operator--() { p--; return *this; } const_iterator operator--(int) { const_iterator res = *this; p--; return res; } const_iterator operator-(const difference_type& x)const { return const_iterator(*this) -= x; } difference_type operator-(const const_iterator& i)const { return p - i.p; } const_iterator& operator-=(const difference_type& x) { p -= x; return *this; } reference operator*()const { return *p; } reference operator[](const difference_type& x)const { return *(p + x); } bool operator<(const const_iterator& i)const { return p < i.p; } bool operator<=(const const_iterator& i)const { return p <= i.p; } bool operator==(const const_iterator& i)const { return p == i.p; } bool operator>(const const_iterator& i)const { return p > i.p; } bool operator>=(const const_iterator& i)const { return p >= i.p; } bool operator!=(const const_iterator& i)const { return p != i.p; } }; using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; private: T* e; unsigned int length = 0, cap = 1; Alloc alloc; static_assert(std::is_same::value, "The allocator value type is not matched the vector value type."); static_assert(!std::is_const::value, "This library forbids containers of const elements"); public: Vector() :Vector(Alloc()) {} explicit Vector(const Alloc& a) :alloc(a) { e = alloc.allocate(cap); } explicit Vector(size_type n, const Alloc& a = Alloc()) :alloc(a) { while (cap < n)cap *= 2; e = alloc.allocate(cap); rep(i, n)emplace_back(); } explicit Vector(size_type n, const T& value, const Alloc& a = Alloc()) :alloc(a) { while (cap < n)cap *= 2; e = alloc.allocate(cap); rep(i, n)emplace_back(value); } template Vector(InputIter first, InputIter last, const Alloc& a = Alloc()) :alloc(a) { e = alloc.allocate(cap); for (InputIter i = first; i != last; i++) { emplace_back(*i); } } Vector(const Vector& x, const Alloc& a = Alloc()) :alloc(a) { while (cap < x.length)cap *= 2; length = x.length; e = alloc.allocate(cap); rep(i, x.length)traits::construct(alloc, e + i, *(x.e + i)); } Vector(Vector&& x, const Alloc& a = Alloc()) :alloc(a) { cap = x.cap; length = x.length; e = x.e; x.e = nullptr; } ~Vector() { if (e != nullptr) { rep(i, length)traits::destroy(alloc, e + i); alloc.deallocate(e, cap); } } Vector& operator=(const Vector& x) { rep(i, length)traits::destroy(alloc, e + i); alloc.deallocate(e, cap); length = x.length; cap = 1; while (cap < length)cap *= 2; e = alloc.allocate(cap); rep(i, length)traits::construct(alloc, e + i, *(x.e + i)); return *this; } Vector& operator=(Vector&& x) { rep(i, length)traits::destroy(alloc, e + i); alloc.deallocate(e, cap); cap = x.cap; length = x.length; e = x.e; x.e = nullptr; return *this; } private: void extension() { T* e_ = alloc.allocate(cap * 2); rep(i, length)traits::construct(alloc, e_ + i, *(e + i)); rep(i, length)traits::destroy(alloc, e + i); alloc.deallocate(e, cap); e = e_; cap *= 2; } void extension(size_type n) { unsigned int r = 1; while (cap * r < n)r *= 2; if (r == 1)return; T* e_ = alloc.allocate(cap * r); rep(i, length)traits::construct(alloc, e_ + i, *(e + i)); rep(i, length)traits::destroy(alloc, e + i); alloc.deallocate(e, cap); e = e_; cap *= r; } public: template void assign(InputIter first, InputIter last) { unsigned int cnt = 0; for (InputIter i = first; i != last; i++) { if (cnt == cap) { length = std::max(length, cnt); extension(); } traits::construct(alloc, e + cnt, *i); cnt++; } } void assign(size_type n, const T& value) { extension(n); std::fill(e, e + n, value); } template void emplace_back(Args&&... args) { if (length == cap)extension(); traits::construct(alloc, e + length, std::forward(args)...); length++; } void push_back(const T& value) { emplace_back(value); } void push_back(T&& value) { emplace_back(std::move(value)); } void pop_back() { traits::destroy(alloc, e + length); length--; } iterator erase(iterator pos) { const iterator res = pos; iterator t = pos; t++; for (iterator i = pos; t != end(); i++, t++) { *i = std::move(*t); } pop_back(); return res; } iterator erase(iterator first, iterator last) { const iterator res = first; typename iterator::difference_type d = last - first; for (iterator i = first; i + d != end(); i++) { *i = std::move(*(i + d)); } rep(i, d)pop_back(); return res; } void swap(Vector& x) { std::swap(length, x.length); std::swap(cap, x.cap); std::swap(e, x.e); } void clear() { while (length)pop_back(); } size_type size()const { return length; } void resize(size_type n, const T& value = T()) { extension(n); while (n < length)pop_back(); std::fill(e, e + n, value); } size_type capacity()const { return cap; } bool empty()const { return !length; } T& operator[](const unsigned int pos) { return e[pos]; } T* data() { return e; } T& front() { return *e; } T& back() { return *(e + length - 1); } iterator begin() noexcept { return iterator(this, 0); } const_iterator begin()const noexcept { return const_iterator(this, 0); } const_iterator cbegin()const noexcept { return const_iterator(this, 0); } iterator rbegin()noexcept { return reverse_iterator(this, 0); } const_iterator rbegin()const noexcept { return const_reverse_iterator(this, 0); } const_iterator crbegin()const noexcept { return const_reverse_iterator(this, 0); } iterator end() noexcept { return iterator(this, length); } const_iterator end()const noexcept { return const_iterator(this, length); } const_iterator cend()const noexcept { return const_iterator(this, length); } iterator rend()noexcept { return reverse_iterator(this, length); } const_iterator rend()const noexcept { return const_reverse_iterator(this, length); } const_iterator crend()const noexcept { return const_reverse_iterator(this, length); } }; template inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } inline lint gcd(lint a, lint b) { while (b) { lint c = a; a = b; b = c % b; } return a; } inline lint lcm(lint a, lint b) { return a / gcd(a, b) * b; } bool isprime(lint n) { if (n == 1)return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0)return false; } return true; } lint mypow(lint a, lint b) { if (!b)return 1; if (b & 1)return mypow(a, b - 1) * a; lint memo = mypow(a, b >> 1); return memo * memo; } lint modpow(lint a, lint b, lint m) { if (!b)return 1; if (b & 1)return modpow(a, b - 1, m) * a % m; lint memo = modpow(a, b >> 1, m); return memo * memo % m; } template void printArray(std::vector& vec) { rep(i, vec.size() - 1)std::cout << vec[i] << " "; std::cout << vec.back() << std::endl; } template void printArray(Vector& vec) { rep(i, vec.size() - 1)std::cout << vec[i] << " "; std::cout << vec.back() << std::endl; } template void printArray(T l, T r) { T rprev = r; rprev--; for (T i = l; i != rprev; i++) { std::cout << *i << " "; } std::cout << *rprev << std::endl; } std::string to_string(Vector& vec) { std::string res = "["; rep(i, vec.size() - 1)res += std::to_string(vec[i]) + ", "; res += std::to_string(vec.back()) + "]"; return res; } int n, k, q, c[100010], a[100010]; int parent[17][100010], depth[100010]; int nc[100010]; Vector vec[100010]; void dfs(int node, int d) { depth[node] = d; chmax(nc[node], c[node]); for (int i : vec[node]) { if (parent[0][i] == -1) { parent[0][i] = node; chmax(nc[i], nc[node]); dfs(i, d + 1); } } } int lca(int x, int y) { if (depth[x] > depth[y])std::swap(x, y); for (int i = 16; i >= 0; i--) { if ((1 << i) <= depth[y] - depth[x])y = parent[i][y]; } if (x == y)return x; for (int i = 16; i >= 0; i--) { if (parent[i][x] != parent[i][y]) { x = parent[i][x]; y = parent[i][y]; } } return parent[0][x]; } class SegTree { int n = 1; Vector node; public: SegTree(int n_) { while (n < n_)n *= 2; node.resize(2 * n - 1, -1); } void update(int a, int x) { a += n - 1; node[a] = x; while (a) { a = (a - 1) / 2; if (node[2 * a + 1] == -1 && node[2 * a + 2] == -1)node[a] = -1; else if (node[2 * a + 1] == -1)node[a] = node[2 * a + 2]; else if (node[2 * a + 2] == -1)node[a] = node[2 * a + 1]; else node[a] = lca(node[2 * a + 1], node[2 * a + 2]); } } int query(int a, int b, int k = 0, int l = 0, int r = -1) { if (r == -1)r = n; if (r <= a || b <= l)return -1; if (a <= l && r <= b)return node[k]; int vl = query(a, b, 2 * k + 1, l, (l + r) / 2); int vr = query(a, b, 2 * k + 2, (l + r) / 2, r); if (vl == -1)return vr; if (vr == -1)return vl; return lca(vl, vr); } void print() { rep(i, 2 * n - 1)std::cout << node[i] << " "; std::cout << std::endl; } }; int main() { std::cin >> n >> k >> q; REP(i, n)std::cin >> c[i]; REP(i, k)std::cin >> a[i]; rep(i, n - 1) { int e, f; std::cin >> e >> f; vec[f].push_back(e); } REP(i, n)parent[0][i] = -1; parent[0][1] = 1; dfs(1, 0); REP(i, 16) { REP(j, n) { parent[i][j] = parent[i - 1][parent[i - 1][j]]; } } SegTree st(k + 1); REP(i, k)st.update(i, a[i]); rep(i, q) { int t, x, y; std::cin >> t >> x >> y; if (t == 1)st.update(x, y); else { std::cout << nc[st.query(x, y + 1)] << std::endl; } } return 0; }