Submission #623600

#TimeUsernameProblemLanguageResultExecution timeMemory
623600HanksburgerSynchronization (JOI13_synchronization)C++17
100 / 100
234 ms20544 KiB
#include <bits/stdc++.h> using namespace std; int par[100005][17], bit[100005], ok[100005], in[100005], out[100005], a[100005], b[100005], n, m, q, t; vector<pair<int, int> > edge; vector<int> adj[100005]; void update(int x, int y) { for (int i=x; i<=n; i+=i&(-i)) bit[i]+=y; } int query(int x) { int ans=0; for (int i=x; i; i-=i&(-i)) ans+=bit[i]; return ans; } int findPar(int u) { for (int i=16; i>=0; i--) if (query(in[u])==query(in[par[u][i]])) u=par[u][i]; return u; } void dfs(int u, int p) { par[u][0]=p; for (int i=1; i<=16; i++) par[u][i]=par[par[u][i-1]][i-1]; in[u]=++t; for (int v:adj[u]) if (v!=p) dfs(v, u); out[u]=t+1; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> q; for (int i=1; i<n; i++) { int u, v; cin >> u >> v; edge.push_back({u, v}); adj[u].push_back(v); adj[v].push_back(u); } dfs(1, 1); for (int i=1; i<=n; i++) { update(in[i], 1); update(out[i], -1); a[i]=1; } for (int i=1; i<=m; i++) { int x, u, v, w; cin >> x; u=edge[x-1].first; v=edge[x-1].second; if (par[u][0]==v) swap(u, v); w=findPar(u); if (ok[x]) { a[v]=b[v]=a[w]; update(in[v], 1); update(out[v], -1); } else { a[w]+=a[v]-b[v]; update(in[v], -1); update(out[v], 1); } ok[x]^=1; } for (int i=1; i<=q; i++) { int x; cin >> x; cout << a[findPar(x)] << '\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...
#Verdict Execution timeMemoryGrader output
Fetching results...