Submission #1129672

#TimeUsernameProblemLanguageResultExecution timeMemory
1129672zhasynBirthday gift (IZhO18_treearray)C++17
100 / 100
1322 ms78992 KiB
#include <bits/stdc++.h> #define pb push_back #define pf push_front using namespace std; #define F first #define S second typedef long long ll; #define pii pair <int, int> #define pll pair <ll, ll> typedef long double ld; const ll N = 2 * 1e5 + 100, M = 500 + 10, len = 315, inf = 1e18; const ll mod = 998244353; ll um(ll a, ll b){ return (1LL * a * b) % mod; } ll subr(ll a, ll b){ return ((1LL * a - b) % mod + mod) % mod; } ll bp(ll x, ll step){ ll res = 1; while(step){ if(step & 1) res = um(res, x); x = um(x, x); step /= 2; } return res; } ll inv(ll x){ return bp(x, mod - 2); } int tin[N], tout[N], timer, a[N], up[N][22]; vector <int> q[N]; void dfs(int v, int p = 0){ tin[v] = ++timer; up[v][0] = p; for(int i = 1; i <= 20; i++){ up[v][i] = up[up[v][i - 1]][i - 1]; } for(auto u : q[v]){ if(u == p) continue; dfs(u, v); } tout[v] = timer; } bool upper(int a, int b){ return tin[a] <= tin[b] && tout[b] <= tout[a]; } int lca(int a, int b){ if(upper(a, b)) return a; if(upper(b, a)) return b; for(int i = 20; i >= 0; i--){ if(upper(up[a][i], b) || up[a][i] == 0) continue; a = up[a][i]; } return up[a][0]; } set <pii> st[N]; int main() { //ios_base::sync_with_stdio(false); //cin.tie(nullptr); //cout.tie(nullptr); int n, m, qr; cin >> n >> m >> qr; for(int i = 0, a, b; i < n - 1; i++){ cin >> a >> b; q[a].pb(b); q[b].pb(a); } for(int i = 1; i <= n; i++){ st[i].insert({INT_MAX, INT_MAX}); } dfs(1); for(int i = 1; i <= m; i++){ cin >> a[i]; st[a[i]].insert({i, i}); } for(int i = 1; i < m; i++){ st[lca(a[i], a[i + 1])].insert({i, i + 1}); //cout << a[i] << " "<< a[i + 1] << " "<< lca(a[i], a[i + 1]) << endl; } for(int i = 0, code, l, r, x, pos; i < qr; i++){ cin >> code; if(code == 1){ cin >> pos >> x; st[a[pos]].erase({pos, pos}); if(pos < m){ st[lca(a[pos], a[pos + 1])].erase({pos, pos + 1}); st[lca(x, a[pos + 1])].insert({pos, pos + 1}); //cout << a[pos] << " " << a[pos + 1] << " " << lca(a[pos], a[pos + 1]) << endl; } if(pos > 1){ st[lca(a[pos - 1], a[pos])].erase({pos - 1, pos}); st[lca(a[pos - 1], x)].insert({pos - 1, pos}); } st[x].insert({pos, pos}); a[pos]= x; } else{ cin >> l >> r >> x; auto k = st[x].lower_bound({l, 0}); pii res = *k; if(res.S <= r) cout << res.F << " "<< res.S << endl; else cout << "-1 -1\n"; } } // 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...