Submission #167654

#TimeUsernameProblemLanguageResultExecution timeMemory
167654atoizBirthday gift (IZhO18_treearray)C++14
0 / 100
36 ms29432 KiB
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define FORA(i, a) for (auto &i : a) #define FORB(i, a, b) for (int i = a; i >= b; --i) #define SZ(a) ((int) a.size()) #define ALL(a) a.begin(), a.end() const int MAXN = 200007, LOG = 19; set<pair<int, int>> pairs[MAXN]; vector<int> G[MAXN]; int anc[LOG][MAXN], dep[MAXN], A[MAXN]; int N, M, Q; int get_lca(int u, int v) { if (dep[u] < dep[v]) swap(u, v); FORB(j, LOG - 1, 0) if (dep[u] - (1 << j) >= dep[v]) u = anc[j][u]; if (u == v) return u; FORB(j, LOG - 1, 0) if (anc[j][u] != anc[j][v]) u = anc[j][u], v = anc[j][v]; return anc[0][u]; } void dfs(int u, int p) { for (int v : G[u]) if (v != p) { anc[0][v] = u; FOR(i, 1, LOG - 1) anc[i][v] = anc[i - 1][anc[i - 1][v]]; dep[v] = dep[u] + 1; dfs(v, u); } } void rem(int u, int i, int j) { pairs[u].erase(pairs[u].find(pair<int, int>(i, j))); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> M >> Q; FOR(_, 0, N - 2) { int u, v; cin >> u >> v; G[u].push_back(v); G[v].push_back(u); } dfs(1, 0); FOR(i, 1, M) cin >> A[i]; FOR(i, 1, M) pairs[A[i]].emplace(i, i); FOR(i, 1, M - 1) pairs[get_lca(A[i], A[i + 1])].emplace(i, i + 1); FOR(_, 0, Q - 1) { int type; cin >> type; if (type == 1) { int i, u; cin >> i >> u; rem(A[i], i, i); pairs[u].emplace(i, i); if (i > 1) { rem(get_lca(A[i - 1], A[i]), i - 1, i); pairs[get_lca(A[i - 1], u)].emplace(i - 1, i); } if (i < N) { rem(get_lca(A[i], A[i + 1]), i, i + 1); pairs[get_lca(u, A[i + 1])].emplace(i, i + 1); } A[i] = u; } else { int l, r, u; cin >> l >> r >> u; auto it = pairs[u].lower_bound(pair<int, int>(l, l)); if (it == pairs[u].end() || it->second > r) { cout << "-1 -1\n"; } else { cout << it->first << ' ' << it->second << '\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...