제출 #1119843

#제출 시각아이디문제언어결과실행 시간메모리
1119843Yang8on동기화 (JOI13_synchronization)C++17
100 / 100
270 ms33284 KiB
#include <bits/stdc++.h> #define Y8o "Synchronization" #define maxn (int) 2e5 + 5 #define ll long long #define pii pair<ll, ll> #define gb(i, j) ((i >> j) & 1) #define all(x) x.begin(), x.end() #define _left id * 2, l, mid #define _right id * 2 + 1, mid + 1, r #define fi(i, a, b) for(int i = a; i <= b; i ++) #define fid(i, a, b) for(int i = a; i >= b; i --) //#define f first //#define s second using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll GetRandom(ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rng); } void iof() { ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); if(fopen(Y8o".inp", "r")) { freopen(Y8o".inp", "r", stdin); // freopen(Y8o".out", "w", stdout); } } void ctime() { cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; } int n, m, Q; vector<int> o[maxn]; int a[maxn], c[maxn]; int in[maxn], out[maxn], cnt; int h[maxn], cha[maxn][20]; struct dl { int u, v, id; } ed[maxn]; void dfs(int u = 1, int p = 0) { in[u] = ++cnt; for(int v : o[u]) if(v != p) { h[v] = h[u] + 1, cha[v][0] = u; fi(i, 1, 17) cha[v][i] = cha[ cha[v][i - 1] ][i - 1]; dfs(v, u); } out[u] = cnt; } struct BIT { int bit[maxn]; void update(int x, int val) { while(x <= n) bit[x] += val, x += (x & -x); } int get(int x, int best = 0) { while(x > 0) best += bit[x], x -= (x & -x); return best; } } Bit; int par(int u) { fid(i, 17, 0) { if(cha[u][i] && Bit.get(in[u]) == Bit.get(in[cha[u][i]])) u = cha[u][i]; } return u; } void solve() { cin >> n >> m >> Q; fi(i, 1, n - 1) { int u, v; cin >> u >> v; o[u].push_back(v), o[v].push_back(u); ed[i] = { u, v, 0 }; } dfs(); fi(i, 1, n - 1) { int &u = ed[i].u, &v = ed[i].v; if(cha[u][0] == v) swap(u, v); Bit.update(in[v], -1), Bit.update(out[v] + 1, +1); } fi(i, 1, n) a[i] = 1, c[i] = 0; fi(i, 1, m) { int pos; cin >> pos; int u = ed[pos].u, v = ed[pos].v, &id = ed[pos].id; if(!id) { a[par(u)] += a[v] - c[v]; Bit.update(in[v], +1), Bit.update(out[v] + 1, -1); } else { a[v] = c[v] = a[par(u)]; Bit.update(in[v], -1), Bit.update(out[v] + 1, +1); } id ^= 1; } fi(i, 1, Q) { int u; cin >> u; cout << a[par(u)] << '\n'; } } int main() { iof(); int nTest = 1; // cin >> nTest; while(nTest --) { solve(); } ctime(); return 0; }

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

synchronization.cpp: In function 'void iof()':
synchronization.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(Y8o".inp", "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...