제출 #1285746

#제출 시각아이디문제언어결과실행 시간메모리
1285746thaibeo123동기화 (JOI13_synchronization)C++20
0 / 100
134 ms22104 KiB
#include <bits/stdc++.h> using namespace std; #define NAME "A" #define ll long long #define fi first #define se second #define pb push_back #define all(x) x.begin(), x.end() #define MASK(x) (1ll << (x)) #define BIT(x, i) (((x) >> (i)) & 1) const int N = 3e5 + 5; const int LG = 18; struct FenwickTree { int n; vector<int> fen; FenwickTree() {} FenwickTree(int n): n(n), fen(n + 5) {} void update(int x, int v) { for (int i = x; i <= n; i += i & -i) { fen[i] += v; } } int get(int x) { int res = 0; for (int i = x; i > 0; i -= i & -i) { res += fen[i]; } return res; } }; int n, m, q, timer; int tin[N], tout[N], hi[N], L[N][21], last[N], ans[N]; bool state[N]; FenwickTree fen; vector<int> g[N]; pair<int, int> e[N]; int root(int x) { int res = x; for (int i = LG; i >= 0; i--) { if (L[x][i] == 0) continue; if (fen.get(tin[x]) - fen.get(tin[L[x][i]]) == 0) { res = L[x][i]; } } return res; } void dfs(int u, int par) { hi[u] = hi[par] + 1; tin[u] = ++timer; L[u][0] = par; for (int i = 1; i <= LG; i++) { L[u][i] = L[L[u][i - 1]][i - 1]; } for (int v : g[u]) { if (v == par) continue; dfs(v, u); } tout[u] = timer; } void input() { cin >> n >> m >> q; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; g[u].pb(v); g[v].pb(u); e[i] = {u, v}; } } void solve() { dfs(1, 0); fen = FenwickTree(n); for (int i = 1; i < n; i++) { if (hi[e[i].fi] > hi[e[i].se]) { swap(e[i].fi, e[i].se); } fen.update(tin[i + 1], 1); fen.update(tout[i + 1] + 1, -1); } for (int i = 1; i <= n; i++) { ans[i] = 1; } while (m--) { int cur; cin >> cur; state[cur] = state[cur] ^ 1; int u = e[cur].fi, v = e[cur].se; if (state[cur] == 1) { fen.update(tin[v], -1); fen.update(tout[v] + 1, 1); ans[root(u)] += ans[v] - last[v]; } else { fen.update(tin[v], 1); fen.update(tout[v] + 1, -1); last[v] = ans[v] = ans[root(u)]; } } while (q--) { int x; cin >> x; cout << ans[root(x)] << "\n"; } } signed main() { if (fopen(NAME".INP", "r")) { freopen(NAME".INP", "r", stdin); freopen(NAME".OUT", "w", stdout); } cin.tie(0)->sync_with_stdio(0); input(); solve(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

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