Submission #998354

#TimeUsernameProblemLanguageResultExecution timeMemory
998354fuad27Synchronization (JOI13_synchronization)C++17
100 / 100
362 ms26592 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5+10; const int lg = 20; int tin[N], tout[N]; int up[N][lg]; pair<int,int> e[N]; vector<int> child[N]; int tim=0; array<int, 2> ans[N]; int depth[N]; namespace BIT { int fen[N]; void upd(int at, int val) { at++; while(at < N) { fen[at] += val; at += at&-at; } } int query(int at) { at++; int ret = 0; while(at > 0) { ret += fen[at]; at -= at&-at; } return ret; } }; void change(int at, int val) { BIT::upd(tin[at], val); BIT::upd(tout[at], -val); } int query(int anc, int ch) { return BIT::query(tin[ch])-BIT::query(tin[anc]); } void dfs(int at, int p) { up[at][0] = p; tin[at] = tim++; for(int i = 1;i<lg;i++) { up[at][i] = up[up[at][i-1]][i-1]; } for(int i = 0;i<child[at].size();i++) { if(child[at][i] != p) { depth[child[at][i]] = depth[at]+1; dfs(child[at][i], at); } } tout[at] = tim; } int findroot(int at) { for(int i = lg-1;i>=0;i--) { if(up[at][i] == 0)continue; if(query(up[at][i], at) == depth[at]-depth[up[at][i]]) { at = up[at][i]; } } return at; } int state[N]; int main () { int n, m, q; cin >> n >> m >> q; memset(up, 0, sizeof up); for(int i = 1;i<n;i++) { cin >> e[i].first >> e[i].second; child[e[i].first].push_back(e[i].second); child[e[i].second].push_back(e[i].first); } dfs(1, 0); for(int i = 1;i<n;i++) { if(depth[e[i].first]>depth[e[i].second])swap(e[i].first, e[i].second); } for(int i = 1;i<=n;i++)ans[i][0]=1; for(int i = 0;i<m;i++) { int c; cin >> c; state[c]^=1; if(state[c] == 1) { int r = findroot(e[c].first); int v1 = ans[e[c].second][0]+ans[r][0]-ans[e[c].second][1]; change(e[c].second, 1); ans[r][0] = v1; } else { int r = findroot(e[c].second); ans[e[c].second][1] = ans[r][0]; ans[e[c].second][0] = ans[r][0]; change(e[c].second, -1); } } while(q--) { int c; cin >> c; cout << ans[findroot(c)][0] << "\n"; } }

Compilation message (stderr)

synchronization.cpp: In function 'void dfs(int, int)':
synchronization.cpp:44:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |   for(int i = 0;i<child[at].size();i++) {
      |                 ~^~~~~~~~~~~~~~~~~
#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...