Submission #768758

# Submission time Handle Problem Language Result Execution time Memory
768758 2023-06-28T14:42:09 Z Baytoro Werewolf (IOI18_werewolf) C++17
49 / 100
498 ms 65412 KB
#include "werewolf.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=2e5+5;
vector<int> g[N];
int v[N],used[N],a[N];
void dfs(int x){
	a[v[x]]=x;
	for(auto it: g[x]){
		if(v[it]!=-1) continue;
		v[it]=v[x]+1;
		dfs(it);
	}
}
struct SparseTable{
	int mn[N][21],mx[N][21];
	void build(){
		for(int i=0;i<N;i++)
			mn[i][0]=mx[i][0]=a[i];
		for(int j=1;j<21;j++){
			for(int i=0;i+(1<<j)-1<N;i++){
				mn[i][j]=min(mn[i][j-1],mn[i+(1<<(j-1))][j-1]);
				mx[i][j]=max(mx[i][j-1],mx[i+(1<<(j-1))][j-1]);
			}
		}
	}
	int minn(int l, int r){
		int lg=__lg(r-l+1);
		return min(mn[l][lg],mn[r-(1<<lg)+1][lg]);
	}
	int maxx(int l, int r){
		int lg=__lg(r-l+1);
		return max(mx[l][lg],mx[r-(1<<lg)+1][lg]);
	}
} sparse;
int col[N];
void dfs1(int x, int c, vector<int> &used){
	used[x]=1;
	//cout<<x<<' '<<c<<' '<<col[x]<<endl;
	for(auto it: g[x]){
		if(used[it]) continue;
		if(c==1 && col[it]<=1) 
			dfs1(it,c,used);
		if(c==2 && col[it]>=1) 
			dfs1(it,c,used);
	}
}
vector<int> check_validity(int n, vector<int> X, vector<int> Y,
                                vector<int> S, vector<int> E,
                                vector<int> L, vector<int> R){
	for(int i=0;i<N;i++) v[i]=-1;
	int m=X.size(),q=S.size();
	//Subtask 3
	for(int i=0;i<m;i++){
		g[X[i]].pb(Y[i]);
		g[Y[i]].pb(X[i]);
	}
	
	if(n<=3000){
		vector<int> ans(q);
		for(int i=0;i<q;i++){
			if(E[i]>R[i] || S[i]<L[i]) continue;
			for(int j=0;j<n;j++){
				if(j<L[i]) col[j]=2;
				else if(j<=R[i]) col[j]=1;
				else col[j]=0;
			}
			vector<int> a(n),b(n);
			dfs1(S[i],1,a);
			dfs1(E[i],2,b);
			for(int j=L[i];j<=R[i];j++)
				if(a[j] && b[j])
					ans[i]=1;
		}
		return ans;
	}
	else{
		for(int i=0;i<n;i++){
			if(g[i].size()==1){
				v[i]=0;
				dfs(i);
				break;
			}
		}
		sparse.build();
		vector<int> ans(q);
		for(int i=0;i<q;i++){
			int l=v[S[i]],r=v[E[i]];
			if(l<r){
				//cout<<1<<endl;
				int lx=l,rx=r;
				for(int j=(1<<20);j>0;j/=2){
					if(lx+j<=r && sparse.minn(l,lx+j)>=L[i]) 
						lx+=j;
					if(rx-j>=l && sparse.maxx(rx-j,r)<=R[i])
						rx-=j;
				}
				if(rx<=lx) ans[i]=1;
			}
			if(r<l){
				//cout<<2<<endl;
				int lx=r, rx=l;
				for(int j=(1<<20);j>0;j/=2){
					if(lx+j<=l && sparse.maxx(r,lx+j)<=R[i]) 
						lx+=j;
					if(rx-j>=r && sparse.minn(rx-j,l)>=L[i])
						rx-=j;
				}
				if(rx<=lx) ans[i]=1;
			}
		}
		return ans;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 3 ms 5716 KB Output is correct
3 Correct 3 ms 5716 KB Output is correct
4 Correct 3 ms 5792 KB Output is correct
5 Correct 3 ms 5716 KB Output is correct
6 Correct 3 ms 5716 KB Output is correct
7 Correct 3 ms 5844 KB Output is correct
8 Correct 3 ms 5716 KB Output is correct
9 Correct 3 ms 5716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 3 ms 5716 KB Output is correct
3 Correct 3 ms 5716 KB Output is correct
4 Correct 3 ms 5792 KB Output is correct
5 Correct 3 ms 5716 KB Output is correct
6 Correct 3 ms 5716 KB Output is correct
7 Correct 3 ms 5844 KB Output is correct
8 Correct 3 ms 5716 KB Output is correct
9 Correct 3 ms 5716 KB Output is correct
10 Correct 212 ms 6184 KB Output is correct
11 Correct 121 ms 6160 KB Output is correct
12 Correct 20 ms 6296 KB Output is correct
13 Correct 237 ms 6204 KB Output is correct
14 Correct 149 ms 6164 KB Output is correct
15 Correct 196 ms 6348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 496 ms 65412 KB Output is correct
2 Correct 381 ms 65300 KB Output is correct
3 Correct 385 ms 65260 KB Output is correct
4 Correct 462 ms 65228 KB Output is correct
5 Correct 415 ms 65308 KB Output is correct
6 Correct 498 ms 65308 KB Output is correct
7 Correct 410 ms 65312 KB Output is correct
8 Correct 328 ms 65228 KB Output is correct
9 Correct 211 ms 65260 KB Output is correct
10 Correct 224 ms 65288 KB Output is correct
11 Correct 229 ms 65260 KB Output is correct
12 Correct 230 ms 65304 KB Output is correct
13 Correct 421 ms 65264 KB Output is correct
14 Correct 403 ms 65260 KB Output is correct
15 Correct 401 ms 65328 KB Output is correct
16 Correct 431 ms 65264 KB Output is correct
17 Correct 416 ms 65308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5716 KB Output is correct
2 Correct 3 ms 5716 KB Output is correct
3 Correct 3 ms 5716 KB Output is correct
4 Correct 3 ms 5792 KB Output is correct
5 Correct 3 ms 5716 KB Output is correct
6 Correct 3 ms 5716 KB Output is correct
7 Correct 3 ms 5844 KB Output is correct
8 Correct 3 ms 5716 KB Output is correct
9 Correct 3 ms 5716 KB Output is correct
10 Correct 212 ms 6184 KB Output is correct
11 Correct 121 ms 6160 KB Output is correct
12 Correct 20 ms 6296 KB Output is correct
13 Correct 237 ms 6204 KB Output is correct
14 Correct 149 ms 6164 KB Output is correct
15 Correct 196 ms 6348 KB Output is correct
16 Correct 496 ms 65412 KB Output is correct
17 Correct 381 ms 65300 KB Output is correct
18 Correct 385 ms 65260 KB Output is correct
19 Correct 462 ms 65228 KB Output is correct
20 Correct 415 ms 65308 KB Output is correct
21 Correct 498 ms 65308 KB Output is correct
22 Correct 410 ms 65312 KB Output is correct
23 Correct 328 ms 65228 KB Output is correct
24 Correct 211 ms 65260 KB Output is correct
25 Correct 224 ms 65288 KB Output is correct
26 Correct 229 ms 65260 KB Output is correct
27 Correct 230 ms 65304 KB Output is correct
28 Correct 421 ms 65264 KB Output is correct
29 Correct 403 ms 65260 KB Output is correct
30 Correct 401 ms 65328 KB Output is correct
31 Correct 431 ms 65264 KB Output is correct
32 Correct 416 ms 65308 KB Output is correct
33 Incorrect 208 ms 63708 KB Output isn't correct
34 Halted 0 ms 0 KB -