Submission #865769

#TimeUsernameProblemLanguageResultExecution timeMemory
865769vjudge1Birthday gift (IZhO18_treearray)C++98
0 / 100
34 ms66136 KiB
// Bolatulu #include <bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; typedef double db; #define int long long #define kanagattandirilmagandiktarinizdan ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); #define pb push_back #define F first #define S second #define md (tl+tr)/2 #define TL v+v,tl,md #define TR v+v+1,md+1,tr #pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3") using namespace std; int binpow(int a,int n,int M) { if (n==0) return 1; if (n%2!=0) return (a * binpow(a,n-1,M))%M; int z=binpow(a,n/2,M); return (z*z)%M; } const ll INF = 1e18; const int N = 1e6+7; const int M = 1e9+7; const ll HZ = 1e5; const int MAX = INT_MAX; const int MIN = INT_MIN; const db pi = 3.141592653; const int P=31; int n,m,q,tin[N],tout[N],t,up[20][N],a[N]; vector <int> g[N]; void dfs(int v,int p) { tin[v] = ++t; up[0][v] = p; for (auto now: g[v]) { if (now == p) continue; dfs(now, v); } tout[v] = ++t; } bool parent(int a,int b) { return tin[a] <= tin[b] and tout[b] <= tout[a]; } void prepare(int pw) { if (pw == 20) return; for (int i = 1; i <= n; i++) up[pw][i] = up[up[pw - 1][i]][i]; prepare(pw + 1); } int lca(int a,int b) { if (parent(a, b)) return a; if (parent(b, a)) return b; for (int i = 19; i >= 0; i--) if (up[i][a] and !parent(up[i][a], b)) a = up[i][a]; return up[0][a]; } void solve() { cin >> n >> m >> q; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; g[u].push_back(v), g[v].push_back(u); } dfs(1, 0), prepare(1); vector<set<int>> d(n + 1), s(n + 1); for (int i = 1; i <= m; i++) { cin >> a[i]; if (i > 1) d[lca(a[i - 1], a[i])].insert(i - 1); s[a[i]].insert(i); } while (q--) { int tp, l, r, v; cin >> tp; if (tp == 1) { cin >> l >> v; if (l > 1) d[lca(a[l - 1], a[l])].erase(l - 1), d[lca(a[l - 1], v)].insert(l - 1); if (l < m) d[lca(a[l], a[l + 1])].erase(l), d[lca(v, a[l + 1])].insert(l); s[a[l]].erase(l), s[v].insert(l); a[l] = v; } else { cin >> l >> r >> v; if (!s[v].empty() and s[v].lower_bound(l) != s[v].end() and *s[v].lower_bound(l) <= r) cout << *s[v].lower_bound(l) << ' ' << *s[v].lower_bound(l) << '\n'; else if (!d[v].empty() and d[v].lower_bound(l) != d[v].end() and *d[v].lower_bound(l) <= r - 1) cout << *d[v].lower_bound(l) << ' ' << *d[v].lower_bound(l) + 1 << '\n'; else cout << -1 << ' ' << -1 << '\n'; } } } signed main() { // freopen("lca.in", "r", stdin); // freopen("lca.out", "w", stdout); kanagattandirilmagandiktarinizdan int test = 1, count = 1; // cin >> test; while (test--) { // cout << "Case " << count << ":\n"; solve(); if (test) // cout << '\n'; count++; } 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...