Submission #240162

# Submission time Handle Problem Language Result Execution time Memory
240162 2020-06-18T09:51:15 Z Knps4422 Synchronization (JOI13_synchronization) C++14
50 / 100
344 ms 23676 KB
//#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 = 200005;
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[2*nmax];
pii ed[nmax];
int up[nmax][17];
int old[nmax], cur[nmax], active[nmax];
void update(int pos , int val){
	for(;pos <= 2*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);
}

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;
	}
	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;
	}

	dfs(1,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);
		}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);
		}
		active[ei] ^= 1;
	}
	forn(i,q){
		cin >> a;
		cout << cur[find_root(a)] << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Incorrect 7 ms 5120 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 132 ms 20984 KB Output is correct
2 Correct 116 ms 20728 KB Output is correct
3 Correct 119 ms 23032 KB Output is correct
4 Correct 122 ms 23160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 8 ms 5120 KB Output is correct
4 Correct 7 ms 5120 KB Output is correct
5 Correct 8 ms 5120 KB Output is correct
6 Correct 10 ms 5248 KB Output is correct
7 Correct 27 ms 6904 KB Output is correct
8 Correct 344 ms 23288 KB Output is correct
9 Correct 313 ms 23288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 324 ms 23288 KB Output is correct
2 Correct 179 ms 23544 KB Output is correct
3 Correct 176 ms 23672 KB Output is correct
4 Correct 178 ms 23676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5120 KB Output is correct
2 Correct 7 ms 5024 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Incorrect 9 ms 5120 KB Output isn't correct
5 Halted 0 ms 0 KB -