제출 #379386

#제출 시각아이디문제언어결과실행 시간메모리
379386syl123456Birthday gift (IZhO18_treearray)C++17
0 / 100
1 ms364 KiB
#include <bits/stdc++.h> #define all(i) i.begin(), i.end() #define rall(i) i.rbegin(), i.rend() using namespace std; typedef long long ll; typedef pair<int, int> pi; vector<vector<int>> g, pa; vector<int> d; void dfs(int i, int p) { for (int j : g[i]) if (j != p) d[j] = d[i] + 1, pa[j][0] = i, dfs(j, i); } int lca(int i, int j) { if (d[i] < d[j]) swap(i, j); for (int ii = 19; ~ii; --ii) if (d[pa[i][ii]] >= d[j]) i = pa[i][ii]; for (int ii = 19; ~ii; --ii) if (pa[i][ii] != pa[j][ii]) i = pa[i][ii], j = pa[j][ii]; return i == j ? i : pa[i][0]; } int main() { ios::sync_with_stdio(0), cin.tie(0); int n, m, q; cin >> n >> m >> q; g.resize(n), pa.assign(n, vector<int>(20)), d.resize(n); for (int i = 0; i < n - 1; ++i) { int x, y; cin >> x >> y; --x, --y; g[x].push_back(y), g[y].push_back(x); } pa[0][0] = d[0] = 0; dfs(0, 0); for (int i = 1; i < 20; ++i) for (int j = 0; j < n; ++j) pa[j][i] = pa[pa[j][i - 1]][i - 1]; int a[m]; for (int &i : a) cin >> i, --i; set<int> s[n]; for (int i = 1; i < m; ++i) s[lca(a[i], a[i - 1])].insert(i - 1); while (q--) { int ty, x, y, z; cin >> ty >> x >> y; --x, --y; if (ty == 1) { if (x) s[lca(a[x], a[x - 1])].erase(x - 1); if (x < m - 1) s[lca(a[x], a[x + 1])].erase(x); a[x] = y; if (x) s[lca(a[x], a[x - 1])].insert(x - 1); if (x < m - 1) s[lca(a[x], a[x + 1])].insert(x); } else { cin >> z; --z; int tmp = *s[z].lower_bound(x); if (tmp == *s[z].lower_bound(y)) cout << "-1 -1\n"; else cout << tmp + 1 << ' ' << tmp + 2 << '\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...