제출 #447328

#제출 시각아이디문제언어결과실행 시간메모리
447328tranxuanbachBirthday gift (IZhO18_treearray)C++17
0 / 100
15 ms24012 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define endl '\n' #define fi first #define se second #define For(i, l, r) for (int i = l; i < r; i++) #define ForE(i, l, r) for (int i = l; i <= r; i++) #define FordE(i, l, r) for (int i = l; i >= r; i--) #define Fora(v, a) for (auto v: a) #define bend(a) a.begin(), a.end() #define isz(a) ((signed)a.size()) using ll = long long; using ld = long double; using pii = pair <int, int>; using vi = vector <int>; using vpii = vector <pii>; using vvi = vector <vi>; const int N = 2e5 + 5, M = __lg(N) + 2; int n, m, q; vi adj[N]; int a[N]; int h[N]; int ctrtime, tin[N], tout[N]; pii sptable[M][N]; void dfs_tour(int u, int p){ tin[u] = tout[u] = ++ctrtime; sptable[0][ctrtime] = {h[u], u}; Fora(&v, adj[u]){ if (v == p){ continue; } h[v] = h[u] + 1; dfs_tour(v, u); tout[u] = ++ctrtime; sptable[0][ctrtime] = {h[u], u}; } } int lca(int u, int v){ int l = min(tin[u], tin[v]), r = max(tout[u], tout[v]), z = __lg(r - l + 1); return min(sptable[z][l], sptable[z][r - (1 << z) + 1]).se; } set <int> stt1[N], stt2[N]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen(".inp", "r", stdin); // freopen(".out", "w", stdout); cin >> n >> m >> q; For(i, 1, n){ int u, v; cin >> u >> v; adj[u].emplace_back(v); adj[v].emplace_back(u); } ForE(i, 1, m){ cin >> a[i]; } dfs_tour(1, 1); For(j, 1, M){ ForE(i, 1, ctrtime - (1 << j) + 1){ sptable[j][i] = min(sptable[j - 1][i], sptable[j - 1][i + (1 << (j - 1))]); } } ForE(i, 1, n){ stt1[a[i]].insert(i); } ForE(i, 2, n){ stt2[lca(a[i - 1], a[i])].insert(i); } while (q--){ int que; cin >> que; if (que == 1){ int pos, u; cin >> pos >> u; stt1[a[pos]].erase(pos); if (pos > 1){ stt2[lca(a[pos - 1], a[pos])].erase(pos); } if (pos < n){ stt2[lca(a[pos], a[pos + 1])].erase(pos + 1); } a[pos] = u; stt1[a[pos]].insert(pos); if (pos > 1){ stt2[lca(a[pos - 1], a[pos])].insert(pos); } if (pos < n){ stt2[lca(a[pos], a[pos + 1])].insert(pos + 1); } } else{ int l, r, u; cin >> l >> r >> u; set <int>::iterator itr; itr = stt1[u].lower_bound(l); if (itr != stt1[u].end() and (*itr) <= r){ cout << (*itr) << ' ' << (*itr) << endl; continue; } itr = stt2[u].lower_bound(l + 1); if (itr != stt2[u].end() and (*itr) <= r){ cout << (*itr) - 1 << ' ' << (*itr) << endl; continue; } cout << -1 << ' ' << -1 << endl; } } } /* ==================================================+ INPUT: | --------------------------------------------------| 5 4 4 1 2 3 1 3 4 5 3 4 5 2 3 2 1 3 1 1 3 5 2 3 4 5 2 1 3 1 --------------------------------------------------| ==================================================+ OUTPUT: | --------------------------------------------------| 1 3 3 3 -1 -1 --------------------------------------------------| ==================================================+ */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...