Submission #1047529

#TimeUsernameProblemLanguageResultExecution timeMemory
1047529vladiliusSynchronization (JOI13_synchronization)C++17
100 / 100
139 ms23284 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") using namespace std; using ll = long long; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second #define arr3 array<int, 3> struct ST{ vector<int> t; int n; ST(int ns){ n = ns; t.resize(4 * n); } void upd(int v, int tl, int tr, int& p, bool& k){ if (tl == tr){ t[v] = k; return; } int tm = (tl + tr) / 2, vv = 2 * v; if (p <= tm){ upd(vv, tl, tm, p, k); } else { upd(vv + 1, tm + 1, tr, p, k); } t[v] = min(t[vv], t[vv + 1]); } void upd(int p, bool k){ upd(1, 1, n, p, k); } vector<arr3> all; void dec(int v, int tl, int tr, int& l, int& r){ if (l > tr || r < tl) return; if (l <= tl && tr <= r){ all.pb({v, tl, tr}); return; } int tm = (tl + tr) / 2, vv = 2 * v; dec(vv + 1, tm + 1, tr, l, r); dec(vv, tl, tm, l, r); } int find(int v, int tl, int tr){ if (tl == tr) return tl; int tm = (tl + tr) / 2, vv = 2 * v; if (!t[vv + 1]) return find(vv + 1, tm + 1, tr); return find(vv, tl, tm); } int find(int l, int r){ all.clear(); dec(1, 1, n, l, r); for (auto [v, tl, tr]: all){ if (!t[v]){ return find(v, tl, tr); } } return 0; } }; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, q; cin>>n>>m>>q; vector<int> g[n + 1]; vector<pii> ed = {{}}; for (int i = 1; i < n; i++){ int x, y; cin>>x>>y; ed.pb({x, y}); g[x].pb(y); g[y].pb(x); } vector<int> sz(n + 1), h(n + 1), d(n + 1), p(n + 1); function<void(int, int)> fill = [&](int v, int pr){ p[v] = pr; sz[v] = 1; d[v] = d[pr] + 1; for (int i: g[v]){ if (i == pr) continue; fill(i, v); if (sz[i] > sz[h[v]]){ h[v] = i; } sz[v] += sz[i]; } }; fill(1, 0); vector<int> head(n + 1), pos(n + 1); int timer = 0; function<void(int, int)> fill_hld = [&](int v, int k){ head[v] = k; pos[v] = ++timer; if (!h[v]) return; fill_hld(h[v], k); for (int i: g[v]){ if (pos[i]) continue; fill_hld(i, i); } }; fill_hld(1, 1); vector<int> inv(n + 1); for (int i = 1; i <= n; i++) inv[pos[i]] = i; for (int i = 1; i < ed.size(); i++){ if (d[ed[i].ff] > d[ed[i].ss]){ swap(ed[i].ff, ed[i].ss); } } vector<bool> used(n + 1); vector<int> last(n + 1), out(n + 1, 1); ST T(n); auto get = [&](int v){ while (true){ int u = T.find(pos[head[v]], pos[v]); if (u > 0) return inv[u]; v = p[head[v]]; } }; while (m--){ int p; cin>>p; auto [u, v] = ed[p]; if (used[p]){ out[v] = last[v] = out[get(u)]; T.upd(pos[v], 0); } else { out[get(u)] += (out[v] - last[v]); T.upd(pos[v], 1); } used[p] = !used[p]; } while (q--){ int x; cin>>x; cout<<out[get(x)]<<"\n"; } }

Compilation message (stderr)

synchronization.cpp: In function 'int main()':
synchronization.cpp:113:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |     for (int i = 1; i < ed.size(); i++){
      |                     ~~^~~~~~~~~~~
#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...