Submission #495935

#TimeUsernameProblemLanguageResultExecution timeMemory
495935MukhitaliBirthday gift (IZhO18_treearray)C++17
30 / 100
4072 ms5536 KiB
//bit chass 1 #include <bits/stdc++.h> #define x first #define y second #define el "\n" #define ll long long #define pb push_back #define pll pair <ll, ll> #define pii pair <int, int> #define all(x) x.begin(), x.end() #define lcm(x,y) x * y / __gcd(x, y) #define ibase ios_base::sync_with_stdio(0), cin.tie(0) using namespace std; const int N = 2e5 + 5, inf = 1e9 + 7, M = 2e6, MM = 2e6 + 5, K = 300; const ll MI = 2e18; const double P = 3.14; int a[N], tim, tin[N], tout[N], u[N][25]; vector <int> g[N]; void dfs(int v, int pr) { tin[v] = tim++; u[v][0] = pr; for (int i = 1; i <= 24; i++) u[v][i] = u[u[v][i - 1]][i - 1]; for (int to : g[v]) { if (to != pr) dfs(to, v); } tout[v] = tim++; } bool up(int x, int y) { if (tin[x] <= tin[y] && tin[y] <= tout[x]) return 1; return 0; } int lca(int x, int y) { if (up(x, y)) return x; if (up(y, x)) return y; for (int i = 24; i >= 0; i--) { if (u[x][i] != 0 && !up(u[x][i], y)) x = u[x][i]; } return u[x][0]; } void solve() { int n, m, q; cin >> n >> m >> q; for (int i = 1, x, y; i < n; i++) { cin >> x >> y; g[x].pb(y); g[y].pb(x); } tim = 1; dfs(1, 0); tout[0] = N; for (int i = 1; i <= m; i++) cin >> a[i]; // cout << lca(2, 4) << el; while (q--) { int tp; cin >> tp; if (tp == 1) { int pos, v; cin >> pos >> v; a[pos] = v; } else { int l, r, v; bool ok = 0; cin >> l >> r >> v; for (int i = l; i <= r; i++) { int lc = a[i]; for (int j = i; j <= r; j++) { lc = lca(a[j], lc); if (lc == v) { cout << i << ' ' << j << el; ok = 1; break; } } if (ok) break; } if (!ok) cout << "-1 -1" << el; } } } int main() { ibase; int T = 1; // cin >> T; for (int i = 1; i <= T; i++) { // cout << "Case " << i << ": "; solve(); cout << el; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...