Submission #35780

#TimeUsernameProblemLanguageResultExecution timeMemory
35780UncleGrandpa925Synchronization (JOI13_synchronization)C++14
30 / 100
373 ms25276 KiB
/*input 5 6 3 1 2 1 3 2 4 2 5 1 2 1 4 4 3 1 4 5 */ #include <bits/stdc++.h> using namespace std; #define sp ' ' #define endl '\n' #define fi first #define se second #define mp make_pair #define int long long #define N 100005 #define bit(x,y) ((x>>y)&1LL) #define na(x) (#x) << ":" << x ostream& operator << (ostream &os, vector<int>&x) { for (int i = 0; i < x.size(); i++) os << x[i] << sp; return os; } ostream& operator << (ostream &os, pair<int, int> x) { cout << x.fi << sp << x.se << sp; return os; } ostream& operator << (ostream &os, vector<pair<int, int> >&x) { for (int i = 0; i < x.size(); i++) os << x[i] << endl; return os; } int n, m, q; vector<vector<int> > a(N); vector<pair<int, int> > edge; bool state[N]; int sta[N], en[N]; int pos[2 * N]; int Time = 0; int f[8 * N]; int last[N]; int ans[N]; void dfs(int u, int p) { sta[u] = ++Time; pos[Time] = u; for (auto v : a[u]) { if (v == p) continue; dfs(v, u); } en[u] = ++Time; } void init(int k, int l, int r) { if (l == r) { f[k] = en[pos[l]]; return; } int mid = (l + r) / 2; init(k * 2, l, mid); init(k * 2 + 1, mid + 1, r); f[k] = max(f[k * 2], f[k * 2 + 1]); } void update(int k, int l, int r, int pos, int val) { if (r < pos || pos < l) return; if (l == r && pos == l) { f[k] = val; return; } int mid = (l + r) / 2; update(k * 2, l, mid, pos, val); update(k * 2 + 1, mid + 1, r, pos, val); f[k] = max(f[k * 2], f[k * 2 + 1]); } int find(int k, int l, int r, int L, int R, int base) { if (r < L || R < l || f[k] <= base) return -1; if (l == r) return l; int mid = (l + r) / 2; int rec = find(k * 2 + 1, mid + 1, r, L, R, base); if (rec == -1) rec = find(k * 2, l, mid, L, R, base); return rec; } int get(int k, int l, int r, int L, int R) { if (r < L || R < l) return -1; if (L <= l && r <= R) return f[k]; int mid = (l + r) / 2; return max(get(k * 2, l, mid, L, R), get(k * 2 + 1, mid + 1, r, L, R)); } int findroot(int u) { int rec = find(1, 1, 2 * n, 1, sta[u], sta[u]); if (rec == -1) return 1; return pos[rec]; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> q; edge.push_back(mp(-1, -1)); for (int i = 1; i <= n - 1; i++) { int u, v; cin >> u >> v; edge.push_back(mp(u, v)); a[u].push_back(v); a[v].push_back(u); } dfs(1, 1); for (int i = 1; i <= n; i++) { ans[i] = 1; if (sta[edge[i].fi] > sta[edge[i].se]) swap(edge[i].fi, edge[i].se); } init(1, 1, 2 * n); for (int i = 1; i <= m; i++) { int e; cin >> e; int u = edge[e].fi; int v = edge[e].se; u = findroot(u); if (!state[e]) { ans[u] = ans[u] + ans[v] - last[v]; update(1, 1, 2 * n, sta[v], sta[v]); } else { last[v] = ans[v] = ans[u]; update(1, 1, 2 * n, sta[v], en[v]); } state[e] ^= 1; } for (int i = 1; i <= n; i++) ans[i] = ans[findroot(i)]; for (int i = 1; i <= q; i++) { int u; cin >> u; cout << ans[u] << endl; } }

Compilation message (stderr)

synchronization.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<long long int>&)':
synchronization.cpp:22:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << sp;
                    ^
synchronization.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<std::pair<long long int, long long int> >&)':
synchronization.cpp:30:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << endl;
                    ^
#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...