Submission #861212

#TimeUsernameProblemLanguageResultExecution timeMemory
861212Trisanu_DasBirthday gift (IZhO18_treearray)C++17
56 / 100
4030 ms22356 KiB
#include <bits/stdc++.h> using namespace std; int n, m, q, par[200005], g[200005] = {-1}, a[200005]; vector<int> adj[200005]; void dfs(int u, int p) { g[u] = g[p] + 1; par[u] = p; for(auto v : adj[u]) if(v != p) dfs(v, u); } int lca(int v, int u) { if(g[v] > g[u]) return lca(par[v], u); if(g[v] < g[u]) return lca(v, par[u]); if(v != u) return lca(par[v], u); return v; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> q; for (int i = 1; i < n; i++){ int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } for (int i = 1; i < m + 1; i++) cin >> a[i]; dfs(1, 0); while(q--){ int op; cin >> op; if(op == 1){ int idx, val; cin >> idx >> val; a[idx] = val; } else { int l, r, v, ptr_l = -1, ptr_r = -1; cin >> l >> r >> v; for (int u = l; u <= r; u++){ if(u != r && lca(a[u], a[u + 1]) == v){ ptr_l = u; ptr_r = u + 1; break; } else if(a[u] == v){ ptr_l = u; ptr_r = u; break; } } cout << ptr_l << ' ' << ptr_r << '\n'; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...