Submission #206068

# Submission time Handle Problem Language Result Execution time Memory
206068 2020-03-02T06:29:58 Z super_j6 Werewolf (IOI18_werewolf) C++14
100 / 100
1122 ms 118780 KB
#include "werewolf.h"
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
#define vi vector<int>

const int inf = 1000000007;

struct segTree{
	int l, r;
	segTree *left, *right;
	int val = inf;
	
	segTree(int a, int b){
		l = a;
		r = b;
		
		if(l != r){
			int mid = (l + r) / 2;
			left = new segTree(l, mid);
			right = new segTree(mid + 1, r);
		}
	}
	
	void add(int x, int v){
		if(x < l || r < x) return;
		if(l == r){
			val = v;
			return;
		}
		
		left->add(x, v);
		right->add(x, v);
		val = min(left->val, right->val);
	}
	
	int qry(int a, int b){
		if(b < l || r < a) return inf;
		if(a <= l && r <= b) return val;
		
		return min(left->qry(a, b), right->qry(a, b));
	}
};

const int maxn = 200000;
int n, m, q;
int s[2][maxn], rf[2][maxn];
int p[maxn], rnk[maxn], b[maxn]; 
int itl[2][maxn], itr[2][maxn], ot[2][maxn];
vector<int> graph[maxn];
vector<int> g[2][maxn], a[2][maxn], f[2][maxn];

int find(int x){
	return x == p[x] ? x : p[x] = find(p[x]);
}

int dfs(int c, int t){
	itr[t][c] = itl[t][c];
	ot[t][itl[t][c]] = c;
	for(int i : g[t][c]){
		itl[t][i] = itr[t][c] + 1;
		itr[t][c] = dfs(i, t);
	}
	return itr[t][c];
}

vi check_validity(int N, vi X, vi Y, vi S, vi E, vi L, vi R){
	n = N, m = X.size(), q = S.size();
	for(int i = 0; i < m; i++){
		graph[X[i]].push_back(Y[i]); 
		graph[Y[i]].push_back(X[i]);
	}
	for(int i = 0; i < q; i++){
		s[0][i] = S[i];
		s[1][i] = E[i];
		a[0][L[i]].push_back(i);
		a[1][R[i]].push_back(i);
	} 
	
	for(int t = 0; t < 2; t++){
		for(int i = 0; i < n; i++) p[i] = b[i] = i, rnk[i] = 0;
		for(int c = !t * (n - 1); 0 <= c && c < n; c += 2 * t - 1){
			for(int i : graph[c]){
				int x = find(c), y = find(i);
				if((t ? c <= i : c >= i) || x == y) continue;
				g[t][c].push_back(b[y]);
				if(rnk[x] < rnk[y]) swap(rnk[x], rnk[y]);
				if(rnk[x] == rnk[y]) rnk[x]++;
				p[y] = x;
				b[x] = c;
			}
			for(int i : a[t][c]){
				int x = b[find(s[t][i])];
				f[t][x].push_back(i);
				rf[t][i] = x;
			}
		}
	}
	
	dfs(0, 0);
	dfs(n - 1, 1);
	
	vector<int> ans(q);
	segTree tre(0, n - 1);
	for(int c = n - 1; c >= 0; c--){
		tre.add(itl[1][ot[0][c]], c);
		for(int i : f[0][ot[0][c]]){
			ans[i] = tre.qry(itl[1][rf[1][i]], itr[1][rf[1][i]]) <= itr[0][ot[0][c]];
		}
	}
	
	return ans;
}

/*
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	vi ans = check_validity(6, 
	{5, 1, 1, 3, 3, 5}, {1, 2, 3, 4, 0, 2},
	{4, 4, 5}, {2, 2, 4},
	{1, 2, 3}, {2, 2, 4});
	
	for(int i : ans) cout << i << endl; 

	return 0;
}
*/

Compilation message

werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:45:31: warning: 'tre.segTree::left' may be used uninitialized in this function [-Wmaybe-uninitialized]
   return min(left->qry(a, b), right->qry(a, b));
                               ^~~~~
werewolf.cpp:108:10: note: 'tre.segTree::left' was declared here
  segTree tre(0, n - 1);
          ^~~
werewolf.cpp:42:15: warning: 'tre.segTree::right' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if(b < l || r < a) return inf;
               ^
werewolf.cpp:108:10: note: 'tre.segTree::right' was declared here
  segTree tre(0, n - 1);
          ^~~
# Verdict Execution time Memory Grader output
1 Correct 26 ms 33272 KB Output is correct
2 Correct 27 ms 33272 KB Output is correct
3 Correct 27 ms 33272 KB Output is correct
4 Correct 26 ms 33272 KB Output is correct
5 Correct 27 ms 33272 KB Output is correct
6 Correct 27 ms 33272 KB Output is correct
7 Correct 26 ms 33272 KB Output is correct
8 Correct 27 ms 33276 KB Output is correct
9 Correct 26 ms 33272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 33272 KB Output is correct
2 Correct 27 ms 33272 KB Output is correct
3 Correct 27 ms 33272 KB Output is correct
4 Correct 26 ms 33272 KB Output is correct
5 Correct 27 ms 33272 KB Output is correct
6 Correct 27 ms 33272 KB Output is correct
7 Correct 26 ms 33272 KB Output is correct
8 Correct 27 ms 33276 KB Output is correct
9 Correct 26 ms 33272 KB Output is correct
10 Correct 34 ms 34424 KB Output is correct
11 Correct 34 ms 34424 KB Output is correct
12 Correct 34 ms 34424 KB Output is correct
13 Correct 33 ms 34540 KB Output is correct
14 Correct 33 ms 34552 KB Output is correct
15 Correct 34 ms 34424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1045 ms 107768 KB Output is correct
2 Correct 869 ms 108500 KB Output is correct
3 Correct 890 ms 105508 KB Output is correct
4 Correct 838 ms 104952 KB Output is correct
5 Correct 852 ms 105208 KB Output is correct
6 Correct 930 ms 106544 KB Output is correct
7 Correct 749 ms 103164 KB Output is correct
8 Correct 815 ms 108536 KB Output is correct
9 Correct 789 ms 104176 KB Output is correct
10 Correct 609 ms 102648 KB Output is correct
11 Correct 638 ms 103160 KB Output is correct
12 Correct 745 ms 103540 KB Output is correct
13 Correct 803 ms 116472 KB Output is correct
14 Correct 789 ms 116344 KB Output is correct
15 Correct 821 ms 116412 KB Output is correct
16 Correct 787 ms 116416 KB Output is correct
17 Correct 748 ms 103032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 33272 KB Output is correct
2 Correct 27 ms 33272 KB Output is correct
3 Correct 27 ms 33272 KB Output is correct
4 Correct 26 ms 33272 KB Output is correct
5 Correct 27 ms 33272 KB Output is correct
6 Correct 27 ms 33272 KB Output is correct
7 Correct 26 ms 33272 KB Output is correct
8 Correct 27 ms 33276 KB Output is correct
9 Correct 26 ms 33272 KB Output is correct
10 Correct 34 ms 34424 KB Output is correct
11 Correct 34 ms 34424 KB Output is correct
12 Correct 34 ms 34424 KB Output is correct
13 Correct 33 ms 34540 KB Output is correct
14 Correct 33 ms 34552 KB Output is correct
15 Correct 34 ms 34424 KB Output is correct
16 Correct 1045 ms 107768 KB Output is correct
17 Correct 869 ms 108500 KB Output is correct
18 Correct 890 ms 105508 KB Output is correct
19 Correct 838 ms 104952 KB Output is correct
20 Correct 852 ms 105208 KB Output is correct
21 Correct 930 ms 106544 KB Output is correct
22 Correct 749 ms 103164 KB Output is correct
23 Correct 815 ms 108536 KB Output is correct
24 Correct 789 ms 104176 KB Output is correct
25 Correct 609 ms 102648 KB Output is correct
26 Correct 638 ms 103160 KB Output is correct
27 Correct 745 ms 103540 KB Output is correct
28 Correct 803 ms 116472 KB Output is correct
29 Correct 789 ms 116344 KB Output is correct
30 Correct 821 ms 116412 KB Output is correct
31 Correct 787 ms 116416 KB Output is correct
32 Correct 748 ms 103032 KB Output is correct
33 Correct 1059 ms 108280 KB Output is correct
34 Correct 403 ms 71928 KB Output is correct
35 Correct 1094 ms 111096 KB Output is correct
36 Correct 1092 ms 108280 KB Output is correct
37 Correct 1122 ms 110180 KB Output is correct
38 Correct 1067 ms 109048 KB Output is correct
39 Correct 1012 ms 118780 KB Output is correct
40 Correct 937 ms 114140 KB Output is correct
41 Correct 925 ms 106720 KB Output is correct
42 Correct 720 ms 103288 KB Output is correct
43 Correct 1073 ms 115192 KB Output is correct
44 Correct 990 ms 107920 KB Output is correct
45 Correct 878 ms 116708 KB Output is correct
46 Correct 883 ms 116424 KB Output is correct
47 Correct 793 ms 116856 KB Output is correct
48 Correct 780 ms 116344 KB Output is correct
49 Correct 811 ms 116536 KB Output is correct
50 Correct 790 ms 116604 KB Output is correct
51 Correct 824 ms 110200 KB Output is correct
52 Correct 803 ms 110200 KB Output is correct