Submission #1104155

#TimeUsernameProblemLanguageResultExecution timeMemory
1104155InvMODSynchronization (JOI13_synchronization)C++14
100 / 100
222 ms26960 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e5+5; const int lg = 21; int n, m, q, timerDFS, tin[N], tout[N], h[N], par[lg][N], bit[N<<1], info[N], last_sync[N]; pair<int,int> E[N]; bool on[N]; vector<int> adj[N]; void update(int p, int val){ for(; p <= timerDFS; p += (p & (-p))) bit[p] += val; } int get(int p){ int res = 0; for(; p; p -= (p & (-p))) res += bit[p]; return res; } void dfs(int x, int p){ tin[x] = ++timerDFS; info[x] = 1; for(int v : adj[x])if(v != p){ h[v] = h[x] + 1; par[0][v] = x; for(int i = 1; i < lg; i++) par[i][v] = par[i-1][par[i-1][v]]; dfs(v, x); } tout[x] = ++timerDFS; return; } int get_par(int x){ int cur_node = x, state = get(tin[x]); for(int i = lg-1; i >= 0; i--){ if(par[i][cur_node] && get(tin[par[i][cur_node]]) == state) cur_node = par[i][cur_node]; } return cur_node; } void solve() { cin >> n >> m >> q; for(int i = 1; i < n; i++){ int u,v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); E[i] = make_pair(u, v); } dfs(1, -1); for(int i = 1; i <= n; i++){ update(tin[i], -1); update(tout[i], 1); } while(m--){ int d; cin >> d; int u = E[d].first, v = E[d].second; if(h[u] > h[v]) swap(u, v); int asc = get_par(u); if(!on[d]){ info[asc] = info[asc] + (info[v] - last_sync[v]); //cout << asc << " " << info[asc] <<"\n"; update(tin[v], 1); update(tout[v], -1); } else{ info[v] = info[asc]; last_sync[v] = info[asc]; update(tin[v], -1); update(tout[v], 1); } on[d] = on[d] ^ 1; } while(q--){ int u; cin >> u; cout << info[get_par(u)] <<"\n"; } } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "InvMOD" if(fopen(name".INP", "r")){ freopen(name".INP", "r", stdin); freopen(name".OUT", "w", stdout); } solve(); return 0; }

Compilation message (stderr)

synchronization.cpp: In function 'int32_t main()':
synchronization.cpp:105:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |         freopen(name".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:106:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |         freopen(name".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...