Submission #240164

#TimeUsernameProblemLanguageResultExecution timeMemory
240164Knps4422동기화 (JOI13_synchronization)C++14
100 / 100
321 ms20984 KiB
//#pragma optimization_level 3 //#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include<bits/stdc++.h> /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset; */ #define fr first #define sc second #define vec vector #define pb push_back #define pii pair<int, int> #define forr(x,y,z) for(int x = (int)y ; x <= (int)z ; ++x) #define forn(x,y) for(int x = 1; x <= (int)y; ++x) #define all(x) (x).begin(),(x).end() #define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0); using namespace std; typedef long long ll; typedef pair<ll,ll> pll; typedef unsigned int uint; typedef complex<ll> point; const int nmax = 100005; const ll linf = 1e18; const ll mod = 1e9+7; const int inf = 1e9; int n, m , q; vec < int > g[nmax]; int tin[nmax], tout[nmax], tt; int bit[nmax]; pii ed[nmax]; int up[nmax][17]; int old[nmax], cur[nmax], active[nmax]; void update(int pos , int val){ for(;pos <= n; pos += pos&-pos){ bit[pos] += val; } } int query(int pos ){ int rs = 0; for(;pos > 0 ; pos -= pos&-pos){ rs += bit[pos]; } return rs; } void dfs(int nod , int p){ tin[nod] = ++tt; up[nod][0] = p; forn(i,16){ up[nod][i] = up[up[nod][i-1]][i-1]; } for(int j : g[nod]){ if(j != p){ dfs(j,nod); } } tout[nod] = tt; update(tin[nod],1); update(tout[nod]+1,-1); } int find_root(int nod){ int p = nod; int qr = query(tin[nod]); for(int i = 16 ; i >= 0 ; i--){ if(query(tin[up[p][i]]) == qr){ p = up[p][i]; } } return p; } int a, b; int main(){ fast cin >> n >> m >> q; forn(i,n-1){ cin >> a >> b; g[a].pb(b); g[b].pb(a); ed[i] = {a,b}; active[i] = 0; } dfs(1,1); forn(i,n-1){ if(up[ed[i].fr][0]!=ed[i].sc){ swap(ed[i].fr,ed[i].sc); } } forn(i,n){ old[i] = 0; cur[i] = 1; } int ei; forn(jj,m){ cin >> ei; if(active[ei]){ int rt = find_root(ed[ei].sc); cur[ed[ei].fr] = cur[rt]; old[ed[ei].fr] = cur[rt]; update(tin[ed[ei].fr],1); update(tout[ed[ei].fr]+1,-1); }else{ int rt = find_root(ed[ei].sc); cur[rt] += cur[ed[ei].fr] - old[ed[ei].fr]; update(tin[ed[ei].fr],-1); update(tout[ed[ei].fr]+1,1); } active[ei] ^= 1; } forn(i,q){ cin >> a; cout << cur[find_root(a)] << '\n'; } }
#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...