Submission #75006

# Submission time Handle Problem Language Result Execution time Memory
75006 2018-09-08T03:11:11 Z ainta Werewolf (IOI18_werewolf) C++17
100 / 100
1850 ms 146652 KB
#include "werewolf.h"
#include<algorithm>
#include<vector>
#define N_ 201000
#define M_ 401000
using namespace std;


int n, m, Q, UF[N_], par[N_][2][20], Num[N_][2], Ed[N_][2], cnt, ReNum[N_][2];
vector<int> UU[N_], DD[N_];
vector<int> T[N_][2];

int Find(int a) {
	if (a == UF[a])return a;
	return UF[a] = Find(UF[a]);
}

void DFS(int a, int ck) {
	Num[a][ck] = ++cnt;
	ReNum[cnt][ck] = a;
	for (auto &x : T[a][ck]) {
		par[x][ck][0] = a;
		DFS(x, ck);
	}
	Ed[a][ck] = cnt;
}

struct PST {
	int l, r, s;
}IT[N_*20];
int Root[N_], cc;

void Put(int rt, int cur, int b, int e, int x) {
	IT[cur] = IT[rt];
	if (b == e) {
		IT[cur].s++;
		return;
	}
	int m = (b + e) >> 1;
	cc++;
	if (x <= m) {
		IT[cur].l = cc;
		Put(IT[rt].l, IT[cur].l, b, m, x);
	}
	else {
		IT[cur].r = cc;
		Put(IT[rt].r, IT[cur].r, m + 1, e, x);
	}
	IT[cur].s = IT[IT[cur].l].s + IT[IT[cur].r].s;
}

int Sum(int nd, int b, int e, int s, int l) {
	if (b == s && e == l)return IT[nd].s;
	int m = (b + e) >> 1, r = 0;
	if (s <= m) r += Sum(IT[nd].l, b, m, s, min(m, l));
	if (l > m)r += Sum(IT[nd].r, m + 1, e, max(m + 1, s), l);
	return r;
}

std::vector<int> check_validity(int N, std::vector<int> X, std::vector<int> Y,
                                std::vector<int> S, std::vector<int> E,
                                std::vector<int> L, std::vector<int> R) {
	n = N;
	m = X.size();
	Q = S.size();
	int i, j;
	for (i = 0; i < n; i++)UF[i] = i;
	for (i = 0; i < m; i++) {
		int x = X[i], y = Y[i];
		if (x > y)swap(x, y);
		UU[x].push_back(y);
		DD[y].push_back(x);
	}
	for (i = 0; i < n; i++) {
		for (auto &x : DD[i]) {
			int y = Find(x);
			if (y == i)continue;
			T[i][0].push_back(y);
			UF[y] = i;
		}
	}
	for (i = 0; i < n; i++)UF[i] = i;
	for (i = n - 1; i >= 0; i--) {
		for (auto &x : UU[i]) {
			int y = Find(x);
			if (y == i)continue;
			T[i][1].push_back(y);
			UF[y] = i;
		}
	}
	cnt = 0;
	DFS(n - 1, 0);
	cnt = 0;
	DFS(0, 1);
	par[n - 1][0][0] = n - 1;
	par[0][1][0] = 0;
	for (i = 0; i < 18; i++) {
		for (j = 0; j < n; j++) {
			par[j][0][i + 1] = par[par[j][0][i]][0][i];
			par[j][1][i + 1] = par[par[j][1][i]][1][i];
		}
	}


	for (i = 1; i <= n; i++) {
		Root[i] = ++cc;
		int x = ReNum[i][0];
		Put(Root[i - 1], Root[i], 1, n, Num[x][1]);
	}

	vector<int>ret;

	for (i = 0; i < Q; i++) {
		int x = S[i], y = E[i];
		for (j = 18; j >= 0; j--) {
			if (par[x][1][j] >= L[i])x = par[x][1][j];
			if (par[y][0][j] <= R[i])y = par[y][0][j];
		}
		if (Sum(Root[Ed[y][0]], 1, n, Num[x][1], Ed[x][1]) - Sum(Root[Num[y][0] - 1], 1, n, Num[x][1], Ed[x][1]) > 0)ret.push_back(1);
		else ret.push_back(0);
	}
	return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 19320 KB Output is correct
2 Correct 20 ms 19408 KB Output is correct
3 Correct 19 ms 19408 KB Output is correct
4 Correct 19 ms 19444 KB Output is correct
5 Correct 19 ms 19608 KB Output is correct
6 Correct 19 ms 19608 KB Output is correct
7 Correct 19 ms 19608 KB Output is correct
8 Correct 21 ms 19608 KB Output is correct
9 Correct 20 ms 19608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 19320 KB Output is correct
2 Correct 20 ms 19408 KB Output is correct
3 Correct 19 ms 19408 KB Output is correct
4 Correct 19 ms 19444 KB Output is correct
5 Correct 19 ms 19608 KB Output is correct
6 Correct 19 ms 19608 KB Output is correct
7 Correct 19 ms 19608 KB Output is correct
8 Correct 21 ms 19608 KB Output is correct
9 Correct 20 ms 19608 KB Output is correct
10 Correct 27 ms 20904 KB Output is correct
11 Correct 29 ms 20904 KB Output is correct
12 Correct 26 ms 20936 KB Output is correct
13 Correct 32 ms 21220 KB Output is correct
14 Correct 28 ms 21236 KB Output is correct
15 Correct 31 ms 21236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1038 ms 128384 KB Output is correct
2 Correct 1222 ms 134200 KB Output is correct
3 Correct 1075 ms 134200 KB Output is correct
4 Correct 1000 ms 134200 KB Output is correct
5 Correct 1022 ms 134200 KB Output is correct
6 Correct 1054 ms 134200 KB Output is correct
7 Correct 966 ms 134200 KB Output is correct
8 Correct 1168 ms 134240 KB Output is correct
9 Correct 866 ms 134240 KB Output is correct
10 Correct 781 ms 134240 KB Output is correct
11 Correct 829 ms 134240 KB Output is correct
12 Correct 783 ms 134240 KB Output is correct
13 Correct 1138 ms 144692 KB Output is correct
14 Correct 1206 ms 144692 KB Output is correct
15 Correct 1198 ms 144692 KB Output is correct
16 Correct 1165 ms 144692 KB Output is correct
17 Correct 936 ms 144692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 19320 KB Output is correct
2 Correct 20 ms 19408 KB Output is correct
3 Correct 19 ms 19408 KB Output is correct
4 Correct 19 ms 19444 KB Output is correct
5 Correct 19 ms 19608 KB Output is correct
6 Correct 19 ms 19608 KB Output is correct
7 Correct 19 ms 19608 KB Output is correct
8 Correct 21 ms 19608 KB Output is correct
9 Correct 20 ms 19608 KB Output is correct
10 Correct 27 ms 20904 KB Output is correct
11 Correct 29 ms 20904 KB Output is correct
12 Correct 26 ms 20936 KB Output is correct
13 Correct 32 ms 21220 KB Output is correct
14 Correct 28 ms 21236 KB Output is correct
15 Correct 31 ms 21236 KB Output is correct
16 Correct 1038 ms 128384 KB Output is correct
17 Correct 1222 ms 134200 KB Output is correct
18 Correct 1075 ms 134200 KB Output is correct
19 Correct 1000 ms 134200 KB Output is correct
20 Correct 1022 ms 134200 KB Output is correct
21 Correct 1054 ms 134200 KB Output is correct
22 Correct 966 ms 134200 KB Output is correct
23 Correct 1168 ms 134240 KB Output is correct
24 Correct 866 ms 134240 KB Output is correct
25 Correct 781 ms 134240 KB Output is correct
26 Correct 829 ms 134240 KB Output is correct
27 Correct 783 ms 134240 KB Output is correct
28 Correct 1138 ms 144692 KB Output is correct
29 Correct 1206 ms 144692 KB Output is correct
30 Correct 1198 ms 144692 KB Output is correct
31 Correct 1165 ms 144692 KB Output is correct
32 Correct 936 ms 144692 KB Output is correct
33 Correct 1355 ms 144692 KB Output is correct
34 Correct 412 ms 144692 KB Output is correct
35 Correct 1646 ms 144692 KB Output is correct
36 Correct 1311 ms 144692 KB Output is correct
37 Correct 1600 ms 144692 KB Output is correct
38 Correct 1506 ms 144692 KB Output is correct
39 Correct 1380 ms 146460 KB Output is correct
40 Correct 1229 ms 146460 KB Output is correct
41 Correct 1259 ms 146460 KB Output is correct
42 Correct 844 ms 146460 KB Output is correct
43 Correct 1850 ms 146460 KB Output is correct
44 Correct 1535 ms 146460 KB Output is correct
45 Correct 1221 ms 146652 KB Output is correct
46 Correct 1444 ms 146652 KB Output is correct
47 Correct 1115 ms 146652 KB Output is correct
48 Correct 1112 ms 146652 KB Output is correct
49 Correct 1166 ms 146652 KB Output is correct
50 Correct 1102 ms 146652 KB Output is correct
51 Correct 1119 ms 146652 KB Output is correct
52 Correct 1124 ms 146652 KB Output is correct