답안 #995360

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
995360 2024-06-08T22:58:56 Z vjudge1 동기화 (JOI13_synchronization) C++17
0 / 100
168 ms 262144 KB
#include <iostream>
#include <vector>
#include <bitset>
#define rep(a,b,c) for(int a=b; a<c; a++)
#define repa(a,b) for(auto a:b)
#define ll long long
#define pb push_back
#define endl "\n"
#define pii pair<int, int>
#define fi first
#define se second
#define mid ((l+r)>>1)

using namespace std;

struct segtree{
	segtree *left, *right;
	int l, r, v=0;
	segtree(int x, int y): l(x), r(y){
		if(l==r) return;
		left = new segtree(l,mid);
		right= new segtree(mid+1,r);
	}
	void update(int x){
		if(r<x || x<l) return;
		if(x<=l && r<=x){
			v^=1;
			return;
		}
		left->update(x);
		right->update(x);
		v=((left->v)&(right->v));
	}
	int query(int x, int y){
		if(r<x || y<l) return 1;
		if(x<=l && r<=y) return v;
		return ((left->query(x,y))&(right->query(x,y)));
	}
};

const int lim=1e5+2;
int sz[lim], tin[lim], root[lim], par[lim], hvy[lim], node[lim], timer;
vector<int> adj[lim];
bitset<lim> vnode[lim];
segtree ST(0,lim);

void sztree(int u, int p){
	sz[u]=1;
	hvy[u]=lim-1;
	par[u]=p;
	repa(v,adj[u]){
		if(v==p) continue;
		sztree(v,u);
		sz[u]+=sz[v];
		if(sz[hvy[u]]<sz[v]) hvy[u]=v;
	}
}

void dfs_hld(int u, int p){
	tin[u]=timer++;
	node[tin[u]]=u;
	repa(v,adj[u]){
		if(v!=hvy[u]) continue;
		root[v]=root[u];
		dfs_hld(v,u);
	}
	repa(v,adj[u]){
		if(v==hvy[u] || v==p) continue;
		root[v]=v;
		dfs_hld(v,u);
	}
}

int query(int u){
	while(ST.query(tin[root[u]],tin[u])) u=par[u];
	//PINCHE BINARIA COMO NO ME SALGA ME PEGO UN TIRO
	int l, r;
	l=tin[root[u]],r=tin[u];
	while(l<=r){
		if(ST.query(mid,r)) r=mid-1;
		else l=mid+1;
	}
	if(r<tin[u]) return node[r];
	else return u;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, m, q, u, v;
	cin>>n>>m>>q;
	pii edges[n];
	rep(i,1,n+1) vnode[i].set(i);
	rep(i,1,n){
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
		edges[i]={u,v};
	}
	sztree(1,0);
	rep(i,1,n) if(par[edges[i].fi]!=edges[i].se) swap(edges[i].fi,edges[i].se);
	root[1]=1;
	dfs_hld(1,0);
	while(m--){
		cin>>u;
		u=edges[u].fi;
		v=query(u);
		if(v!=u) vnode[u]|=vnode[v];
		ST.update(tin[u]);
		v=query(u);
		if(v!=u) vnode[v]|=vnode[u];
	}
	while(q--){
		cin>>u;
		v=query(u);
		if(v!=u) vnode[u]|=vnode[v];
		cout<<vnode[u].count()<<endl;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 13916 KB Output is correct
2 Correct 7 ms 14068 KB Output is correct
3 Correct 7 ms 13916 KB Output is correct
4 Correct 7 ms 13916 KB Output is correct
5 Correct 9 ms 15964 KB Output is correct
6 Correct 11 ms 26276 KB Output is correct
7 Correct 65 ms 137560 KB Output is correct
8 Correct 70 ms 137560 KB Output is correct
9 Correct 76 ms 137564 KB Output is correct
10 Runtime error 36 ms 262144 KB Execution killed with signal 9
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 35 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 13916 KB Output is correct
2 Correct 7 ms 13916 KB Output is correct
3 Correct 8 ms 16040 KB Output is correct
4 Correct 8 ms 15964 KB Output is correct
5 Correct 8 ms 15960 KB Output is correct
6 Correct 27 ms 26564 KB Output is correct
7 Correct 168 ms 138644 KB Output is correct
8 Runtime error 35 ms 262144 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 34 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 13916 KB Output is correct
2 Correct 7 ms 13916 KB Output is correct
3 Correct 7 ms 13896 KB Output is correct
4 Correct 9 ms 15964 KB Output is correct
5 Correct 18 ms 26460 KB Output is correct
6 Correct 124 ms 137564 KB Output is correct
7 Runtime error 37 ms 262144 KB Execution killed with signal 9
8 Halted 0 ms 0 KB -