Submission #520295

# Submission time Handle Problem Language Result Execution time Memory
520295 2022-01-29T08:27:17 Z new_acc Werewolf (IOI18_werewolf) C++14
100 / 100
1301 ms 257668 KB
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
const int N=6e5+10;
const int L=20;
const int SS=1<<20;
vector<int>graf[N];
int seg[SS*2+10],jump[N][L+1];
int val[N][L+1];
vector<pair<int,int> >tr[N];
pair<int,int>pp[N];
int fau[N],num[N];
vector<pair<int,int> >tr2[N];
int jump2[N][L+1];
int val2[N][L+1];
int li;
int pre[N];
int m;
int naj[N],naj2[N];
vector<int>zap[N];
void add(int a,int ind){
	seg[ind+=SS]=a;
	for(ind>>=1;ind>0;ind>>=1) seg[ind]=max(seg[ind*2],seg[ind*2+1]);
}
int Query(int a,int b){
	int res=0;
	for(a+=SS-1,b+=SS+1;(a>>1)!=(b>>1);a>>=1,b>>=1){
		if(!(a&1)) res=max(res,seg[a+1]);
		if(b&1) res=max(res,seg[b-1]);
	}
	return res;
}
void dfs(int v,int o,int x=INT_MAX){
	jump[v][0]=o;
	val[v][0]=x;
	for(int i=1;i<=L;i++) jump[v][i]=jump[jump[v][i-1]][i-1],val[v][i]=min(val[v][i-1],val[jump[v][i-1]][i-1]);
	li++;
	pp[v].fi=li;
	for(auto u:tr[v]){
		if(u.fi==o) continue;
		dfs(u.fi,v,u.se);
	}
	pp[v].se=li;
}
int zn(int a,int c){
	int res=a;
	for(int i=L;i>=0;i--)
		if(val[a][i]>=c) res=jump[a][i],a=jump[a][i];
	return res;
}
int Find(int a){
	if(fau[a]==a) return a;
	return fau[a]=Find(fau[a]);
}
void Union(int a,int b,int c,int xd){
	a=Find(a),b=Find(b);
	if(a==b) return;
	tr[xd].push_back({num[b],c}),tr[xd].push_back({num[a],c});
	fau[a]=b;
	num[b]=xd;
}
void Union2(int a,int b,int c,int xd){
	a=Find(a),b=Find(b);
	if(a==b) return;
	tr2[xd].push_back({num[b],c}),tr2[xd].push_back({num[a],c});
	fau[a]=b;
	num[b]=xd;
}
void dfs2(int v,int o,int x=0){
	jump2[v][0]=o,val2[v][0]=x;
	if(v<=m) pre[++li]=v;
	else ++li;
	for(int i=1;i<=L;i++) jump2[v][i]=jump2[jump2[v][i-1]][i-1],val2[v][i]=max(val2[v][i-1],val2[jump2[v][i-1]][i-1]);
	naj2[v]=INT_MAX;
	int xd=li;
	for(auto u:tr2[v]){
		if(u.fi==o) continue;
		dfs2(u.fi,v,u.se);
		naj2[v]=min(naj2[v],naj2[u.fi]);
		naj[v]=max(naj[v],naj[u.fi]);
	}
	if(naj[v]==0) naj2[v]=xd,naj[v]=xd;
}
int zn2(int a,int c){
	int res=a;
	for(int i=L;i>=0;i--)
		if(val2[a][i]<=c) res=jump2[a][i],a=jump2[a][i];
	return res;
}
vector<int> check_validity(int n,vector<int> x,vector<int> y,vector<int> s,vector<int> e,vector<int> l, vector<int> r){
	m=n;
	vector<int>res(s.size());
	for(int i=0;i<(int)s.size();i++) s[i]++,e[i]++,l[i]++,r[i]++;
	for(int i=0;i<(int)x.size();i++) x[i]++,y[i]++,graf[x[i]].push_back(y[i]),graf[y[i]].push_back(x[i]);
	int wsk=n;
	for(int i=1;i<=n;i++) fau[i]=i,num[i]=i;
	for(int i=n;i>=1;i--){
		for(auto u:graf[i])
			if(u>i&&Find(i)!=Find(u)) Union(i,u,i,++wsk);
	}
	for(int i=1;i<=n;i++) fau[i]=i,num[i]=i;
	dfs(wsk,wsk);
	wsk=n,li=0;
	for(int i=1;i<=n;i++){
		for(auto u:graf[i])
			if(u<i&&Find(i)!=Find(u)) Union2(i,u,i,++wsk);
	}
	dfs2(wsk,wsk);
	for(int i=0;i<(int)s.size();i++){
		int xd=zn2(e[i],r[i]);
		zap[naj[xd]].push_back(i);
	}
	for(int i=1;i<=wsk;i++){
		if(pre[i]==0) continue;
		add(i,pp[pre[i]].fi);
		for(auto u:zap[i]){
			int lew=naj2[zn2(e[u],r[u])];
			int w=zn(s[u],l[u]);
			int xd=Query(pp[w].fi,pp[w].se);
			if(xd>=lew) res[u]=1;
			else res[u]=0;
		}
	}

	return res;
}
/*int main(){
	//vector<int> v=check_validity(4,{1,2,3,4,3,5},{1,2,3,4,0,2},{4,4,5},{2,2,4},{1,2,3},{2,2,4});
	//for(auto u:v) cout<<u<<"\n";
}	*/
# Verdict Execution time Memory Grader output
1 Correct 31 ms 56772 KB Output is correct
2 Correct 27 ms 56868 KB Output is correct
3 Correct 28 ms 56772 KB Output is correct
4 Correct 26 ms 56788 KB Output is correct
5 Correct 27 ms 56856 KB Output is correct
6 Correct 26 ms 56772 KB Output is correct
7 Correct 26 ms 56784 KB Output is correct
8 Correct 26 ms 56908 KB Output is correct
9 Correct 26 ms 56784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 56772 KB Output is correct
2 Correct 27 ms 56868 KB Output is correct
3 Correct 28 ms 56772 KB Output is correct
4 Correct 26 ms 56788 KB Output is correct
5 Correct 27 ms 56856 KB Output is correct
6 Correct 26 ms 56772 KB Output is correct
7 Correct 26 ms 56784 KB Output is correct
8 Correct 26 ms 56908 KB Output is correct
9 Correct 26 ms 56784 KB Output is correct
10 Correct 42 ms 59552 KB Output is correct
11 Correct 34 ms 59492 KB Output is correct
12 Correct 33 ms 59484 KB Output is correct
13 Correct 33 ms 59764 KB Output is correct
14 Correct 35 ms 59760 KB Output is correct
15 Correct 35 ms 59596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 908 ms 241136 KB Output is correct
2 Correct 1142 ms 248048 KB Output is correct
3 Correct 898 ms 242744 KB Output is correct
4 Correct 823 ms 240148 KB Output is correct
5 Correct 837 ms 240136 KB Output is correct
6 Correct 884 ms 240608 KB Output is correct
7 Correct 850 ms 239972 KB Output is correct
8 Correct 1059 ms 247992 KB Output is correct
9 Correct 652 ms 242640 KB Output is correct
10 Correct 588 ms 239796 KB Output is correct
11 Correct 629 ms 239808 KB Output is correct
12 Correct 760 ms 239748 KB Output is correct
13 Correct 1301 ms 246808 KB Output is correct
14 Correct 1227 ms 246604 KB Output is correct
15 Correct 1256 ms 246600 KB Output is correct
16 Correct 1247 ms 246768 KB Output is correct
17 Correct 831 ms 240060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 56772 KB Output is correct
2 Correct 27 ms 56868 KB Output is correct
3 Correct 28 ms 56772 KB Output is correct
4 Correct 26 ms 56788 KB Output is correct
5 Correct 27 ms 56856 KB Output is correct
6 Correct 26 ms 56772 KB Output is correct
7 Correct 26 ms 56784 KB Output is correct
8 Correct 26 ms 56908 KB Output is correct
9 Correct 26 ms 56784 KB Output is correct
10 Correct 42 ms 59552 KB Output is correct
11 Correct 34 ms 59492 KB Output is correct
12 Correct 33 ms 59484 KB Output is correct
13 Correct 33 ms 59764 KB Output is correct
14 Correct 35 ms 59760 KB Output is correct
15 Correct 35 ms 59596 KB Output is correct
16 Correct 908 ms 241136 KB Output is correct
17 Correct 1142 ms 248048 KB Output is correct
18 Correct 898 ms 242744 KB Output is correct
19 Correct 823 ms 240148 KB Output is correct
20 Correct 837 ms 240136 KB Output is correct
21 Correct 884 ms 240608 KB Output is correct
22 Correct 850 ms 239972 KB Output is correct
23 Correct 1059 ms 247992 KB Output is correct
24 Correct 652 ms 242640 KB Output is correct
25 Correct 588 ms 239796 KB Output is correct
26 Correct 629 ms 239808 KB Output is correct
27 Correct 760 ms 239748 KB Output is correct
28 Correct 1301 ms 246808 KB Output is correct
29 Correct 1227 ms 246604 KB Output is correct
30 Correct 1256 ms 246600 KB Output is correct
31 Correct 1247 ms 246768 KB Output is correct
32 Correct 831 ms 240060 KB Output is correct
33 Correct 1099 ms 243472 KB Output is correct
34 Correct 317 ms 89808 KB Output is correct
35 Correct 1226 ms 248608 KB Output is correct
36 Correct 1010 ms 242416 KB Output is correct
37 Correct 1212 ms 247320 KB Output is correct
38 Correct 1086 ms 243460 KB Output is correct
39 Correct 1065 ms 256464 KB Output is correct
40 Correct 1178 ms 251264 KB Output is correct
41 Correct 867 ms 244900 KB Output is correct
42 Correct 703 ms 240604 KB Output is correct
43 Correct 1121 ms 252484 KB Output is correct
44 Correct 977 ms 246024 KB Output is correct
45 Correct 822 ms 257668 KB Output is correct
46 Correct 869 ms 257320 KB Output is correct
47 Correct 1241 ms 246984 KB Output is correct
48 Correct 1299 ms 246660 KB Output is correct
49 Correct 1230 ms 246860 KB Output is correct
50 Correct 1246 ms 246576 KB Output is correct
51 Correct 1111 ms 251556 KB Output is correct
52 Correct 1089 ms 251600 KB Output is correct