Submission #80582

#TimeUsernameProblemLanguageResultExecution timeMemory
80582inomBirthday gift (IZhO18_treearray)C++14
56 / 100
4094 ms53160 KiB
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define sz(c) (int)(c).size() #define all(c) (c).begin(), (c).end() #define in freopen("input.txt", "r", stdin); #define out freopen("output.txt", "w", stdout); using namespace std; const int N = 2 * 1e5 + 10; const int MOD = 1e9 + 7; const int INF = 1e9; int TN = 1; int n, m, Q, l = 1; vector<int> verr[N], up[N]; int tin[N], tout[N], timer, node[N]; void dfs(int x, int pr = 1) { tin[x] = ++timer; up[x][0] = pr; for (int i = 1; i <= l; i++) { up[x][i] = up[up[x][i - 1]][i - 1]; } for (auto i: verr[x]) { if (i != pr) { dfs(i, x); } } tout[x] = ++timer; } bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; } int lca(int a, int b) { if (upper(a, b)) { return a; } else if (upper(b, a)) { return b; } for (int i = l; i >= 0; i--) { if (!upper(up[a][i], b)) { a = up[a][i]; } } return up[a][0]; } void solve() { cin >> n >> m >> Q; for (int i = 1; i < n; i++) { int x, y; cin >> x >> y; verr[x].pb(y); verr[y].pb(x); } while ((1<<l) <= n) { l++; } for (int i = 1; i <= n; i++) { up[i].resize(l + 10); } dfs(1); for (int i = 1; i <= m; i++) { cin >> node[i]; } while (Q--) { int type; cin >> type; if (type == 1) { int pos, v; cin >> pos >> v; node[pos] = v; } else { int l, r, v; cin >> l >> r >> v; bool ok = false; for (int i = l; i <= r; i++) { if (node[i] == v) { cout << i << " " << i << "\n"; ok = true; break; } } if (ok) { continue; } ok = false; for (int i = l; i < r; i++) { if (lca(node[i], node[i + 1]) == v) { cout << i << " " << i + 1 << "\n"; ok = true; break; } } if (!ok) { cout << -1 << " " << -1 << "\n"; } } } return; } signed main() { // ios_base::sync_with_stdio(0); // in; out; // cin >> TN; while (TN--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...