Submission #886037

#TimeUsernameProblemLanguageResultExecution timeMemory
886037Zero_OPSynchronization (JOI13_synchronization)C++14
100 / 100
339 ms37204 KiB
#include<bits/stdc++.h> using namespace std; #define range(v) begin(v), end(v) #define compact(v) v.erase(unique(range(v)), end(v)) template<class T> bool minimize(T& a, T b){ if(a > b) return a = b, true; return false; } template<class T> bool maximize(T& a, T b){ if(a < b) return a = b, true; return false; } typedef long long ll; typedef unsigned long long ull; typedef long double ld; const int N = 2e5 + 5; int n, m, q, tin[N], tout[N], lift[20][N], h[N], res[N], info[N], timerDFS; vector<int> g[N]; pair<int, int> e[N]; bool actived[N]; void dfsEuler(int u, int e){ tin[u] = ++timerDFS; res[u] = 1; for(int v : g[u]) if(v != e){ h[v] = h[u] + 1; lift[0][v] = u; for(int i = 1; i <= 17; ++i){ lift[i][v] = lift[i - 1][lift[i - 1][v]]; } dfsEuler(v, u); } tout[u] = ++timerDFS; } int bit[N]; void update(int id, int val){ for(; id <= timerDFS; id += id & (-id)){ bit[id] += val; } } int query(int id){ int s = 0; for(; id > 0; id -= id & (-id)){ s += bit[id]; } return s; } int binLift(int u){ for(int i = 17; i >= 0; --i){ if(h[u] - (1 << i) >= 0){ int p = lift[i][u]; if(h[u] - h[p] == query(tin[u]) - query(tin[p])){ u = lift[i][u]; } } } return u; } void Zero_OP(){ 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); e[i] = {u, v}; } dfsEuler(1, 1); for(int i = 1; i < n; ++i){ if(lift[0][e[i].first] == e[i].second){ swap(e[i].first, e[i].second); } } while(m--){ int pos; cin >> pos; int u = e[pos].first, v = e[pos].second, upper = binLift(u); if(actived[pos]){ res[v] = info[pos] = res[upper]; update(tin[v], -1); update(tout[v], 1); } else{ res[upper] += res[v] - info[pos]; update(tin[v], 1); update(tout[v], -1); } actived[pos] ^= 1; } while(q--){ int u; cin >> u; u = binLift(u); cout << res[u] << '\n'; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #define task "antuvu" if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } Zero_OP(); return 0; }

Compilation message (stderr)

synchronization.cpp: In function 'int main()':
synchronization.cpp:119:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  119 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:120:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  120 |         freopen(task".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...