Submission #577772

#TimeUsernameProblemLanguageResultExecution timeMemory
577772Do_you_copySynchronization (JOI13_synchronization)C++14
100 / 100
315 ms27020 KiB
#include <bits/stdc++.h> #define taskname "test" #define fi first #define se second #define pb push_back #define faster ios_base::sync_with_stdio(0); cin.tie(0); using namespace std; using ll = long long; using pii = pair <int, int>; ll min(const ll &a, const ll &b){ return (a < b) ? a : b; } ll max(const ll &a, const ll &b){ return (a > b) ? a : b; } const ll Mod = 1000000007; const int maxN = 1e5 + 1; int n, m, q, cnt, k; int lift[maxN][18]; int child[maxN]; bool open[maxN]; int newidx[maxN]; int last[maxN]; int ans[maxN]; struct TEdge{ int u, v; }; int a[maxN + 1]; TEdge e[maxN]; vector <int> adj[maxN]; int lastval; void dfs(int u, int p, int deg){ a[++cnt] = deg - lastval; newidx[u] = cnt; lastval = deg; lift[u][0] = max(1, p); for (int i = 1; i <= k; ++i){ lift[u][i] = max(lift[lift[u][i - 1]][i - 1], 1); } for (const int &i: adj[u]){ if (i != p){ dfs(i, u, deg + 1); child[u] += child[i] + 1; } } } int bit[maxN]; void update(int i, int v){ //binary indexed tree while (i <= n){ bit[i] += v; i += i & (-i); } } int kid(int u, int v){ return (child[u] > child[v]) ? v : u; } int get(int i){ int tem = 0; while (i > 0){ tem += bit[i]; i -= i & (-i); } return tem; } int findancestor(int u){ for (int i = k; i >= 0; --i){ if (get(newidx[lift[u][i]]) == get(newidx[u])){ u = lift[u][i]; } } return u; } void Init(){ cin >> n >> m >> q; fill (ans + 1, ans + n + 1, 1); k = log2(n) + 1; for (int i = 1; i < n; ++i){ cin >> e[i].u >> e[i].v; adj[e[i].u].pb(e[i].v); adj[e[i].v].pb(e[i].u); } dfs(1, 0, 1); for (int i = 1; i <= n; ++i) update(i, a[i]); while (m--){ int i; cin >> i; open[i] = !open[i]; int v = kid(e[i].u, e[i].v); int l = newidx[v]; int r = l + child[v]; if (open[i]){ update(l, -1); update(r + 1, 1); int p = findancestor(v); ans[p] += ans[v] - last[v]; } else{ int p = findancestor(v); update(l, 1); update(r + 1, -1); last[v] = ans[v] = ans[p]; } } while (q--){ int x; cin >> x; cout << ans[findancestor(x)] << "\n"; } } int main(){ if (fopen(taskname".txt", "r")){ freopen(taskname".txt", "r", stdin); } faster //freopen(taskname.inp, "r", stdin) //freopen(taskname.out, "w", stdout) Init(); }

Compilation message (stderr)

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