Submission #1097675

#TimeUsernameProblemLanguageResultExecution timeMemory
1097675blackslexSynchronization (JOI13_synchronization)C++17
20 / 100
203 ms24152 KiB
#include<bits/stdc++.h> #define lsb(x) (x &(-x)) using namespace std; using pii = pair<int, int>; const int N = 1e5 + 5, K = 19; int n, m, q, x, y, t, tin[N], tout[N], par[N], dp[K][N], fwk[N], ans[N], lst[N]; vector<int> v[N]; bool f[N]; void upd (int idx, int val) { for (; idx < N; idx += lsb(idx)) fwk[idx] += val; } int qr (int idx) { int res = 0; for (; idx; idx -= lsb(idx)) res += fwk[idx]; return res; } void dfs (int cur, int par) { tin[cur] = ++t; ::par[cur] = dp[0][cur] = par; for (auto &e: v[cur]) { if (par == e) continue; dfs(e, cur); } tout[cur] = t; } int lca (int a) { int res = a; for (int i = K - 1; i >= 0; i--) { if (dp[i][res] && qr(tin[dp[i][res]]) == qr(tin[a])) res = dp[i][res]; } return res; } int main() { scanf("%d %d %d", &n, &m, &q); vector<pii> u(n - 1); for (auto &[x, y]: u) scanf("%d %d", &x, &y), v[x].emplace_back(y), v[y].emplace_back(x); dfs(1, 0); for (int i = 1; i < K; i++) { for (int j = 1; j <= n; j++) dp[i][j] = dp[i - 1][dp[i - 1][j]]; } for (auto &[x, y]: u) if (::par[x] == y) swap(x, y); for (int i = 1; i <= n; i++) ans[i] = 1, upd(tin[i], -1), upd(tout[i], 1); while (m--) { scanf("%d", &x); auto [y, z] = u[--x]; if (f[x]) { ans[z] = lst[z] = ans[lca(y)]; upd(tin[z], -1); upd(tout[z], -1); } else { ans[lca(y)] += ans[z] - lst[z]; upd(tin[z], 1); upd(tout[z], -1); } f[x] = !f[x]; } while (q--) { scanf("%d", &x); printf("%d\n", ans[lca(x)]); } }

Compilation message (stderr)

synchronization.cpp: In function 'int main()':
synchronization.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     scanf("%d %d %d", &n, &m, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:42:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     for (auto &[x, y]: u) scanf("%d %d", &x, &y), v[x].emplace_back(y), v[y].emplace_back(x);
      |                           ~~~~~^~~~~~~~~~~~~~~~~
synchronization.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
synchronization.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
#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...