Submission #314593

# Submission time Handle Problem Language Result Execution time Memory
314593 2020-10-20T12:05:16 Z tengiz05 Werewolf (IOI18_werewolf) C++17
0 / 100
791 ms 524288 KB
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5, inf = 1e9;
int n, sz, m, timer=0;
int depth[N];
int a[N];
vector<int> edges[N];
void dfs(int u, int p, int d = 0){
	a[u]=timer,timer++;
	depth[u] = d;
	for(auto v : edges[u]){
		if(v == p)continue;
		dfs(v, u, d+1);
	}
}
struct segtree {
	struct Node{
		int mn, mx;
	};
	vector<Node> t;
	Node neutral = {inf, 0};
	void build(){
		sz=1;
		while(sz<n)sz<<=1;
		t.assign(sz*2, neutral);
		for(int i=0;i<n;i++){
			t[a[i]+sz] = {i, i};
		}for(int i=sz-1;i>0;i--){
			t[i] = {min(t[i*2].mn, t[i*2+1].mn), max(t[i*2].mx, t[i*2+1].mx)};
		}
	}
	
	int f_less(int l, int r, int L, int R, int node, int x){
		if(L >= r || R <= l)return sz;
		if(R-L == 1){
			if(L >= l && t[node].mn < x)return L;
			else return sz;
		}int mid = (L+R)/2;
		if(L >= l && R <= r){
			if(t[node*2].mn < x)return f_less(l, r, L, mid, node*2, x);
			else return f_less(l, r, mid, R, node*2+1, x);
		}return min(f_less(l, r, L, mid, node*2, x), 
		            f_less(l, r, mid, R, node*2+1, x));
	}int f_less(int l, int x){return f_less(l, sz, 0, sz, 1, x);}
	
	int f_great(int l, int r, int L, int R, int node, int x){
		if(L >= r || R <= l)return sz;
		if(R-L == 1){
			if(L >= l && t[node].mx > x)return L;
			else return sz;
		}int mid = (L+R)/2;
		if(L >= l && R <= r){
			if(t[node*2].mx > x)return f_great(l, r, L, mid, node*2, x);
			else return f_great(l, r, mid, R, node*2+1, x);
		}return min(f_great(l, r, L, mid, node*2, x),
		            f_great(l, r, mid, R, node*2+1, x));
	}int f_great(int l, int x){return f_great(l, sz, 0, sz, 1, x);}
	
//903475834u1ify98pw75ruehruiae7893yu524hfuiayw78ryhweajkrasfasfasdfsddasf4589i7889he6ghwerg
	
	int l_less(int l, int r, int L, int R, int node, int x){
		if(L >= r || R <= l)return 0;
		if(R-L == 1){
			if(R <= r && t[node].mn < x)return L;
			else return 0;
		}int mid = (L+R)/2;
		if(L >= l && R <= r){
			if(t[node*2+1].mn < x)return l_less(l, r, mid, R, node*2+1, x);
			else return l_less(l, r, L, mid, node*2, x);
		}return max(l_less(l, r, L, mid, node*2, x), 
		            l_less(l, r, mid, R, node*2+1, x));
	}int l_less(int r, int x){return l_less(0, r, 0, sz, 1, x);}
	
	int l_great(int l, int r, int L, int R, int node, int x){
		if(L >= r || R <= l)return 0;
		if(R-L == 1){
			if(R <= r && t[node].mx > x)return L;
			else return 0;
		}int mid = (L+R)/2;
		if(L >= l && R <= r){
			if(t[node*2+1].mx > x)return l_great(l, r, mid, R, node*2+1, x);
			else return l_great(l, r, L, mid, node*2, x);
		}return max(l_great(l, r, L, mid, node*2, x),
		            l_great(l, r, mid, R, node*2+1, x));
	}int l_great(int r, int x){return l_great(0, r, 0, sz, 1, x);}
}seg;

// =================================================================

vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) {
	n = N;
	m = X.size();
	for(int i=0;i<m;i++){
		edges[X[i]].push_back(Y[i]);
		edges[Y[i]].push_back(X[i]);
	}
	dfs(0, 0);
	int mxdep = 0, inddep = 0;
	for(int i=0;i<n;i++){
		if(depth[i] > mxdep)mxdep=depth[i], inddep = i;
	}timer=0;
	dfs(inddep, inddep);
	seg.build();
	int Q = S.size();
//	for(int i=0;i<n;i++)cout << a[i] << ' ';cout << '\n';
	vector<int> ans;
	for(int i=0;i<Q;i++){
		int start = a[S[i]], end = a[E[i]];
		int l = L[i], r = R[i];
		int ans1 = 1;
		if(start <= end){
		//	cout << "f";
			int ff = seg.f_less(start, l)-1;
			int ss = seg.l_great(end, r)+1;
			if(ff < ss)ans1 = 0;
		}else {
		//	cout << "s";
			int ff = seg.l_less(start, l)+1;
			int ss = seg.f_great(end, r)-1;
		//	cout << S[i] << " : " << E[i] << ";;;;   " << start << " : " << end << ";   " << ff << ' ' << ss << "\n\n";
			if(ff > ss)ans1 = 0;
		}//if((abs(start-end) <= 1 && !(S[i] <= r&&S[i]>=l||E[i] <= r&&E[i]>=l)))ans1 = 0;
		ans.push_back(ans1);
	//	cout << i << ' ' << ans1 << '\n';
	}return ans;
}

/*

6 6 3
5 1
1 2
1 3
3 4
3 0
5 2
4 2 1 2
4 2 2 2
5 4 3 4

*/

/*

5 4 5
0 1
1 3
0 4
3 2
1 4 2 3
1 4 1 3
1 4 0 3
1 4 0 4
1 2 2 3

*/




# Verdict Execution time Memory Grader output
1 Runtime error 349 ms 524288 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 349 ms 524288 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 791 ms 41584 KB Output is correct
2 Correct 717 ms 39388 KB Output is correct
3 Correct 735 ms 39452 KB Output is correct
4 Correct 733 ms 39536 KB Output is correct
5 Correct 742 ms 39384 KB Output is correct
6 Correct 772 ms 39408 KB Output is correct
7 Correct 755 ms 39408 KB Output is correct
8 Correct 680 ms 39524 KB Output is correct
9 Incorrect 573 ms 39396 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 349 ms 524288 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -