Submission #314250

# Submission time Handle Problem Language Result Execution time Memory
314250 2020-10-19T08:57:01 Z tengiz05 Werewolf (IOI18_werewolf) C++17
Compilation error
0 ms 0 KB
#include "werewolf.h"
#include "grader.cpp"
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
const int N = 2e5+5, inf = 1e9;
int n, sz, m, timer=0, l,r;
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;
	vector<vector<int>> v;
	Node neutral = {inf, (int)-inf};
	vector<int> Merge(vector<int> &v1, vector<int> &v2){
		int i=0,j=0;
		vector<int> v;
		while(i<v1.size()&&j<v2.size()){
			if(v1[i] <= v2[j]){
				v.push_back(v1[i]);i++;
			}else {
				v.push_back(v2[j]);j++;
			}
		}for(;i<v1.size();i++)v.push_back(v1[i]);
		for(;j<v2.size();j++)v.push_back(v2[j]);
		return v;
	}
	void build(){
		sz=1;
		while(sz<n)sz<<=1;
		t.assign(sz*2, neutral);
		v.assign(sz*2, vector<int>(0));
		for(int i=0;i<n;i++){
			t[i+sz] = {a[i], a[i]};
			v[i+sz].push_back(a[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)};
			v[i] = Merge(v[i*2], v[i*2+1]);
		}
	}
	int less_x(int l, int r, int L, int R, int node, int x){
		if(L >= r || R <= l)return 0;
		int ans = 0;
		if(L >= l && R <= r){
			ans = upper_bound(all(v[node]), x)-v[node].begin()-1;
			return ans;
		}int mid = (L+R)/2;
		ans += less_x(l, r, L, mid, node*2, x);
		ans += less_x(l, r, mid, R, node*2+1, x);
		return ans;
	}int less_x(int l, int r, int x){return less_x(l, r, 0, sz, 1, x);}
	
	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(t[node].mn < x)return L;
			else return sz;
		if(L >= l && R <= r){
			int mid = (L+R)/2;
			if(t[node*2].mn < x)return f_less(l, r, L, mid, node*2, x);
			else f_less(l, r, mid, R, node*2+1, x);
		}int mid = (L+R)/2;
		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 r, int x){return f_less(l, r, 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(t[node].mx > x)return L;
			else return sz;
		if(L >= l && R <= r){
			int mid = (L+R)/2;
			if(t[node*2].mx > x)return f_great(l, r, L, mid, node*2, x);
			else f_great(l, r, mid, R, node*2+1, x);
		}int mid = (L+R)/2;
		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 r, int x){return f_great(l, r, 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(t[node].mn < x)return L;
			else return 0;
		if(L >= l && R <= r){
			int mid = (L+R)/2;
			if(t[node*2+1].mn < x)return l_less(l, r, mid, R, node*2+1, x);
			else l_less(l, r, L, mid, node*2, x);
		}int mid = (L+R)/2;
		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 l, int r, int x){return l_less(l, 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(t[node].mx > x)return L;
			else return 0;
		if(L >= l && R <= r){
			int mid = (L+R)/2;
			if(t[node*2+1].mx > x)return l_great(l, r, mid, R, node*2+1, x);
			else l_great(l, r, L, mid, node*2, x);
		}int mid = (L+R)/2;
		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 l, int r, int x){return l_great(l, 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();
	vector<int> ans;
	for(int i=0;i<Q;i++){
		int start = a[S[i]], end = a[E[i]];
		l = L[i], r = R[i];
		int ans1 = 1;
		if(start <= end){
		//	cout << "f";
			int ff = seg.f_less(start, end, l);
			int ss = seg.l_great(start,end, r);
			if(ff < ss)ans1 = 0;
			else {
				if(seg.less_x(start, ff, r) - seg.less_x(start, ff, l-1) == 0)ans1=0;
			}
		}else {
		//	cout << "s";
			swap(start, end);
			int ff = seg.l_less(start, end, l);
			int ss = seg.f_great(start,end, r);
			if(ff > ss)ans1 = 0;
			else {
				if(seg.less_x(ff, start, r) - seg.less_x(ff, start, l-1) == 0)ans1=0;
			}
		}ans.push_back(ans1);
	}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

*/




Compilation message

werewolf.cpp: In member function 'std::vector<int> segtree::Merge(std::vector<int>&, std::vector<int>&)':
werewolf.cpp:29:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   while(i<v1.size()&&j<v2.size()){
      |         ~^~~~~~~~~~
werewolf.cpp:29:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   while(i<v1.size()&&j<v2.size()){
      |                      ~^~~~~~~~~~
werewolf.cpp:35:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   }for(;i<v1.size();i++)v.push_back(v1[i]);
      |         ~^~~~~~~~~~
werewolf.cpp:36:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |   for(;j<v2.size();j++)v.push_back(v2[j]);
      |        ~^~~~~~~~~~
werewolf.cpp: In member function 'int segtree::f_less(int, int, int, int, int, int)':
werewolf.cpp:66:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   66 |   if(R-L == 1)
      |     ^
werewolf.cpp: In member function 'int segtree::f_great(int, int, int, int, int, int)':
werewolf.cpp:80:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   80 |   if(R-L == 1)
      |     ^
werewolf.cpp: In member function 'int segtree::l_less(int, int, int, int, int, int)':
werewolf.cpp:96:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   96 |   if(R-L == 1)
      |     ^
werewolf.cpp: In member function 'int segtree::l_great(int, int, int, int, int, int)':
werewolf.cpp:110:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
  110 |   if(R-L == 1)
      |     ^
/tmp/cczLLgK7.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccKho8m2.o:werewolf.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status