제출 #1132022

#제출 시각아이디문제언어결과실행 시간메모리
1132022lopkusBirthday gift (IZhO18_treearray)C++20
0 / 100
11 ms25408 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 2e5 + 5; vector<int> a(N); struct Lca{ vector<int>adj[N]; int in[N]; int out[N]; int timer=1; int P[N]; int Log(int n){ int logs[n+1]; logs[1]=0; for(int i=2;i<=n;i++)logs[i]=logs[i/2]+1; return logs[n]; } int up[N][30]; void build(int n){ up[1][0]=1; for(int i=2;i<=n;i++)up[i][0]=P[i]; for(int i=1;i<=29;i++){ for(int j=1;j<=n;j++){ up[j][i]=up[up[j][i-1]][i-1]; } } } void add(int u,int v){ adj[u].push_back(v); adj[v].push_back(u); } void dfs(int x,int cale){ in[x]=timer++; P[x]=cale; for(auto it:adj[x]){ if(it!=cale)dfs(it,x); } out[x]=timer; } int in_tree(int u,int v){ return in[u]<=in[v]&&out[u]>=out[v]; } int lca(int u,int v){ if(u==v)return u; if(in_tree(u,v))return u; if(in_tree(v,u))return v; for(int i=29;i>=0;i--){ if(!in_tree(up[u][i],v)){ u=up[u][i]; } } return up[u][0]; } }lca; int n, m, q; set<int> s[N][2]; void add(int i){ if(i<=0)return; s[a[i]][1].insert(i); if(i<m){ s[lca.lca(a[i], a[i+1])][0].insert(i); } } void del(int i){ if(i<=0)return; s[a[i]][1].erase(i); if(i<m){ s[lca.lca(a[i], a[i+1])][0].erase(i); } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> q; for(int i = 1; i < n; i++) { int u, v; cin >> u >> v; lca.add(u,v); } lca.dfs(1, 0); lca.build(n); for(int i = 1; i <= m; i++) { cin >> a[i]; } for(int i = 1; i <= m; i++) { add(i); } while(q--) { int type; cin >> type; if(type == 1) { int pos, v; cin >> pos >> v; del(pos - 1); del(pos); a[pos] = v; add(pos - 1); add(pos); } else { int l, r, x; cin >> l >> r >> x; auto x1 = s[x][1].lower_bound(l); auto y = s[x][0].lower_bound(l); if(x1 != s[x][1].end() && * x1 <= r) { cout << * x1 << " " << * x1 << "\n"; continue; } if(y != s[x][0].end() && *y < r) { cout << * y << " " << * y + 1 << "\n"; continue; } cout << "- 1 - 1\n"; } } } /* 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 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...