Submission #552214

#TimeUsernameProblemLanguageResultExecution timeMemory
552214ArnchSynchronization (JOI13_synchronization)C++17
100 / 100
3497 ms81440 KiB
// oooo /* har chi delet mikhad bebar ~ gitar o ba khodet nabar! ~ ;Amoo_Hasan; */ #include<bits/stdc++.h> //#pragma GCC optimize("O3,no-stack-protector,unroll-loops") //#pragma GCC target("avx2,fma") #pragma GCC optimzie("Ofast") using namespace std; typedef long long ll; typedef long double ld; #define Sz(x) int((x).size()) #define All(x) (x).begin(), (x).end() #define wtf(x) cout<<#x <<" : " <<x <<endlefii #define endl '\n' constexpr ll inf = 1e18, N = 1e6 + 10, mod = 1e9 + 7, Log = 30; struct node { int cnt, lz; node() { cnt = lz = 0; } } x[N << 2]; int u[N], v[N], h[N], st[N], fn[N], par[N][Log], tim, n, m, q; ll last[N], sum[N]; bool vis[N]; vector<int> vc, G[N]; void dfs(int x, int p = 0) { par[x][0] = p; for(int i = 1; i < Log; i++) par[x][i] = par[par[x][i - 1]][i - 1]; h[x] = h[p] + 1; st[x] = tim++; for(auto &i : G[x]) { if(i == p) continue; dfs(i, x); } fn[x] = tim; } void put(int l, int r, int v) { if(x[v].lz == 0) return; x[2 * v].cnt += x[v].lz, x[2 * v].lz += x[v].lz; x[2 * v + 1].cnt += x[v].lz, x[2 * v + 1].lz += x[v].lz; x[v].lz = 0; } void change(int l, int r, int s, int e, int val, int v) { if(r <= s || l >= e) return; if(l >= s && r <= e) { x[v].cnt += val; x[v].lz += val; return; } put(l, r, v); int mid = (l + r) >> 1; change(l, mid, s, e, val, 2 * v), change(mid, r, s, e, val, 2 * v + 1); } int get(int l, int r, int ind, int v) { if(r - l < 2) return x[v].cnt; put(l, r, v); int mid = (l + r) >> 1; if(ind < mid) return get(l, mid, ind, 2 * v); return get(mid, r, ind, 2 * v + 1); } int get_par(int x) { for(int i = Log - 1; i >= 0; i--) { int val = get(0, n, st[par[x][i]], 1); int val2 = get(0, n, st[x], 1); if(val2 == val + (h[x] - h[par[x][i]])) x = par[x][i]; } return x; } int main() { ios :: sync_with_stdio(0), cin.tie(0); cin >>n >>m >>q; for(int i = 1; i <= n - 1; i++) { cin >>u[i] >>v[i]; G[u[i]].push_back(v[i]), G[v[i]].push_back(u[i]); } dfs(1); for(int i = 1; i <= n - 1; i++) { if(h[u[i]] > h[v[i]]) swap(u[i], v[i]); } for(int i = 1; i <= n; i++) sum[i] = 1; while(m--) { int ind; cin >>ind; int ui = u[ind], vi = v[ind]; int pu = get_par(ui), pv = get_par(vi); if(!vis[ind]) { vis[ind] = 1; int bac = sum[pu] + sum[pv] - last[ind]; change(0, n, st[vi], fn[vi], 1, 1); pu = get_par(ui); sum[pu] = bac; } else { vis[ind] = 0; last[ind] = sum[pu]; change(0, n, st[vi], fn[vi], -1, 1); pu = get_par(ui), pv = get_par(vi); sum[pu] = last[ind], sum[pv] = last[ind]; } } while(q--) { int ind; cin >>ind; int p = get_par(ind); cout<<sum[p] <<endl; } return 0; }

Compilation message (stderr)

synchronization.cpp:11: warning: ignoring '#pragma GCC optimzie' [-Wunknown-pragmas]
   11 | #pragma GCC optimzie("Ofast")
      |
#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...