Submission #155450

# Submission time Handle Problem Language Result Execution time Memory
155450 2019-09-28T10:32:47 Z imyujin Werewolf (IOI18_werewolf) C++17
100 / 100
1581 ms 105404 KB
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;

#define rb(x) ((x)&(-(x)))

const int MAXN = 200010;
const int MX = 1 << 20;

int N;
int u[MAXN], d[MAXN];
int dot[MAXN];
vector<int> qry[MAXN];
vector<int> ed[MAXN];
int bit[MX];

struct TREE {
	int par[20][MAXN], uni[MAXN];
	vector<int> chi[MAXN];
	int dfn[MAXN], dfr[MAXN];

	int dfs(int x, int d) {
		dfn[x] = dfr[x] = d;
		for(auto a : chi[x]) dfr[x] = dfs(a, dfr[x] + 1);
		return dfr[x];
	}

	int cnttt = 0;
	int guni(int x) { 
		//if(++cnttt < 100) printf("uni[%d] = %d, %d\n", x, uni[x], ~uni[x]);	
		return ~uni[x] ? uni[x] = guni(uni[x]) : x;
	}

	void init() {
		memset(par, 0, sizeof(par));
		memset(uni, -1, sizeof(uni));
		for(int i = N - 1; i >= 0; i--) for(auto a : ed[i]) if(a > i) {
			//printf("%d\n", a);
			int x = guni(a);
			if(x != i) {
				par[0][x] = uni[x] = i;
				chi[i].push_back(x);
			}
		}
		for(int i = 1; i < 20; i++) for(int j = 0; j < N; j++) par[i][j] = par[i - 1][par[i - 1][j]];
		dfs(0, 1);
		//for(int i = 0; i < N; i++) printf("%d ", dfn[i]);
		//printf("\n");
	}

	int gr(int x, int l) {
		for(int i = 19; i >= 0; i--) if(par[i][x] >= l) x = par[i][x];
		return x;
	}
} hm, ww;

void updbit(int x) { for(; x < MX; x += rb(x)) bit[x]++; }
int gbit(int x) {
	int ans = 0;
	for(; x; x -= rb(x)) ans += bit[x];
	return ans;
}
int gbit(int x, int y) { return gbit(y) - gbit(x - 1); }

vector<int> check_validity(int NN, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) {
	N = NN;
	int M = X.size(), Q = S.size();

	//printf("*\n");
	for(int i = 0; i < M; i++) {
		ed[X[i]].push_back(Y[i]);
		ed[Y[i]].push_back(X[i]);
	}
	hm.init();
	for(int i = 0; i < N; i++) ed[i].clear();
	for(int i = 0; i < M; i++) {
		ed[N - X[i] - 1].push_back(N - Y[i] - 1);
		ed[N - Y[i] - 1].push_back(N - X[i] - 1);
	}
	ww.init();
	for(int i = 0; i < N; i++) dot[hm.dfn[i]] = ww.dfn[N - i - 1];
	//for(int i = 1; i <= N; i++) printf("%d ", dot[i]);

	for(int i = 0; i < Q; i++) {
		int t = hm.gr(S[i], L[i]);
		qry[hm.dfn[t] - 1].push_back(- i - 1);
		qry[hm.dfr[t]].push_back(i);
		t = ww.gr(N - E[i] - 1, N - R[i] - 1);
		d[i] = ww.dfn[t];
		u[i] = ww.dfr[t];
	}

	vector<int> ans(Q);
	for(int i = 1; i <= N; i++) {
		updbit(dot[i]);
		for(auto a : qry[i]) {
			if(a >= 0) ans[a] += gbit(d[a], u[a]);
			else ans[-a - 1] -= gbit(d[-a - 1], u[-a - 1]);
		}
	}
	for(auto &a : ans) a = min(a,1);
	return ans;
	return X;
}
# Verdict Execution time Memory Grader output
1 Correct 47 ms 52088 KB Output is correct
2 Correct 55 ms 52088 KB Output is correct
3 Correct 49 ms 52088 KB Output is correct
4 Correct 47 ms 52088 KB Output is correct
5 Correct 47 ms 52088 KB Output is correct
6 Correct 47 ms 52060 KB Output is correct
7 Correct 48 ms 52092 KB Output is correct
8 Correct 47 ms 52052 KB Output is correct
9 Correct 47 ms 52216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 52088 KB Output is correct
2 Correct 55 ms 52088 KB Output is correct
3 Correct 49 ms 52088 KB Output is correct
4 Correct 47 ms 52088 KB Output is correct
5 Correct 47 ms 52088 KB Output is correct
6 Correct 47 ms 52060 KB Output is correct
7 Correct 48 ms 52092 KB Output is correct
8 Correct 47 ms 52052 KB Output is correct
9 Correct 47 ms 52216 KB Output is correct
10 Correct 54 ms 52732 KB Output is correct
11 Correct 55 ms 52728 KB Output is correct
12 Correct 62 ms 52728 KB Output is correct
13 Correct 62 ms 52856 KB Output is correct
14 Correct 57 ms 52748 KB Output is correct
15 Correct 55 ms 52908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1341 ms 94216 KB Output is correct
2 Correct 1114 ms 96308 KB Output is correct
3 Correct 1140 ms 94600 KB Output is correct
4 Correct 1116 ms 94292 KB Output is correct
5 Correct 1219 ms 94708 KB Output is correct
6 Correct 1272 ms 95336 KB Output is correct
7 Correct 1242 ms 94656 KB Output is correct
8 Correct 1099 ms 96264 KB Output is correct
9 Correct 612 ms 94192 KB Output is correct
10 Correct 564 ms 93604 KB Output is correct
11 Correct 657 ms 93708 KB Output is correct
12 Correct 578 ms 93476 KB Output is correct
13 Correct 1269 ms 102048 KB Output is correct
14 Correct 1190 ms 102120 KB Output is correct
15 Correct 1260 ms 102100 KB Output is correct
16 Correct 1338 ms 102084 KB Output is correct
17 Correct 1314 ms 94544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 52088 KB Output is correct
2 Correct 55 ms 52088 KB Output is correct
3 Correct 49 ms 52088 KB Output is correct
4 Correct 47 ms 52088 KB Output is correct
5 Correct 47 ms 52088 KB Output is correct
6 Correct 47 ms 52060 KB Output is correct
7 Correct 48 ms 52092 KB Output is correct
8 Correct 47 ms 52052 KB Output is correct
9 Correct 47 ms 52216 KB Output is correct
10 Correct 54 ms 52732 KB Output is correct
11 Correct 55 ms 52728 KB Output is correct
12 Correct 62 ms 52728 KB Output is correct
13 Correct 62 ms 52856 KB Output is correct
14 Correct 57 ms 52748 KB Output is correct
15 Correct 55 ms 52908 KB Output is correct
16 Correct 1341 ms 94216 KB Output is correct
17 Correct 1114 ms 96308 KB Output is correct
18 Correct 1140 ms 94600 KB Output is correct
19 Correct 1116 ms 94292 KB Output is correct
20 Correct 1219 ms 94708 KB Output is correct
21 Correct 1272 ms 95336 KB Output is correct
22 Correct 1242 ms 94656 KB Output is correct
23 Correct 1099 ms 96264 KB Output is correct
24 Correct 612 ms 94192 KB Output is correct
25 Correct 564 ms 93604 KB Output is correct
26 Correct 657 ms 93708 KB Output is correct
27 Correct 578 ms 93476 KB Output is correct
28 Correct 1269 ms 102048 KB Output is correct
29 Correct 1190 ms 102120 KB Output is correct
30 Correct 1260 ms 102100 KB Output is correct
31 Correct 1338 ms 102084 KB Output is correct
32 Correct 1314 ms 94544 KB Output is correct
33 Correct 1459 ms 96248 KB Output is correct
34 Correct 440 ms 86764 KB Output is correct
35 Correct 1581 ms 98436 KB Output is correct
36 Correct 1397 ms 96512 KB Output is correct
37 Correct 1454 ms 97648 KB Output is correct
38 Correct 1428 ms 96984 KB Output is correct
39 Correct 1533 ms 103080 KB Output is correct
40 Correct 1240 ms 105404 KB Output is correct
41 Correct 798 ms 95664 KB Output is correct
42 Correct 588 ms 93932 KB Output is correct
43 Correct 1539 ms 102268 KB Output is correct
44 Correct 974 ms 96360 KB Output is correct
45 Correct 779 ms 101028 KB Output is correct
46 Correct 831 ms 100756 KB Output is correct
47 Correct 1229 ms 102216 KB Output is correct
48 Correct 1184 ms 102032 KB Output is correct
49 Correct 1173 ms 102512 KB Output is correct
50 Correct 1255 ms 102128 KB Output is correct
51 Correct 1114 ms 104992 KB Output is correct
52 Correct 1018 ms 104800 KB Output is correct