Submission #792755

# Submission time Handle Problem Language Result Execution time Memory
792755 2023-07-25T08:30:35 Z NothingXD Werewolf (IOI18_werewolf) C++17
100 / 100
684 ms 100212 KB
#include "werewolf.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef double ld;
typedef complex<ld> point;

void debug_out(){cerr << endl;}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
	cerr << H << ' ';
	debug_out(T...);
}

#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)

const int maxn = 2e5 + 10;
const int lg = 20;

int n, m, q, st[maxn], en[maxn], ver[maxn], tme, dsu[maxn], par[maxn][lg], comp[maxn];
vector<int> g[maxn], t[maxn];
set<int> val[maxn];

struct Query{
	int l, s, e, idx;
};
vector<Query> Q[maxn];

int getdsu(int v){
	return (dsu[v] == -1? v: dsu[v] = getdsu(dsu[v]));
}

void merge(int u, int v){
	if ((u = getdsu(u)) == (v = getdsu(v))) return;
	if (u < v) swap(u, v);
	dsu[u] = v;
	t[v].push_back(u);
	//debug(v, u);
}

void dfs(int v, int p = -1){
	st[v] = ++tme;
	ver[tme] = v;
	par[v][0] = p;
	for (int i = 1; i < lg; i++){
		if (par[v][i-1] != -1) par[v][i] = par[par[v][i-1]][i-1];
	}
	for (auto u: t[v]){
		dfs(u, v);
	}
	en[v] = tme;
	//debug(v, st[v], en[v]);
	//for (int i = 0; i < lg; i++) debug(i, par[v][i]);
}

void merge2(int u, int v){
	if ((u = comp[u]) == (v = comp[v])) return;
	//debug(u, v);
	if (val[u].size() > val[v].size()) swap(u, v);
	for (auto x: val[u]){
		if (ver[x] == u) continue;
		val[v].insert(x);
		comp[ver[x]] = v;
	}
	val[u].clear();
	comp[u] = comp[v];
	val[v].insert(st[u]);
}

vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R){
	memset(dsu, -1, sizeof dsu);
	memset(par, -1, sizeof par);

	n = N;
	m = X.size();
	q = S.size();
	for (int i = 0; i < m; i++){
	//	debug(X[i], Y[i]);
		g[X[i]].push_back(Y[i]);
		g[Y[i]].push_back(X[i]);
	}
	for (int i = 0; i < q; i++){
	//	debug(L[i], R[i], S[i], E[i]);
		Q[R[i]].push_back({L[i], S[i], E[i], i});
	}
	for (int i = n-1; ~i; i--){
		for (auto u: g[i]){
			if (u > i) merge(u, i);
		}
	}
	dfs(0);

	vector<int> ans(q);

	for (int i = 0; i < n; i++){
		//debug(i, st[i]);
		comp[i] = i;
		val[i].insert(st[i]);
		for (auto u: g[i]){
			if (u < i) merge2(u, i);
		}
		for (auto x : Q[i]){
		//	debug(x.l, x.s, x.e, x.idx);
			int v = x.s;
			for (int j = lg-1; ~j; j--){
				if (par[v][j] >= x.l) v = par[v][j];
			}
		//	debug(v, st[v], en[v]);
		//	debug(comp[x.e]);
			auto it = val[comp[x.e]].lower_bound(st[v]);
			if (it != val[comp[x.e]].end() && (*it) <= en[v]){
				ans[x.idx] = 1;
				//debug((*it));
			}
			else ans[x.idx] = 0; 
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 40200 KB Output is correct
2 Correct 18 ms 40148 KB Output is correct
3 Correct 19 ms 40248 KB Output is correct
4 Correct 19 ms 40160 KB Output is correct
5 Correct 20 ms 40148 KB Output is correct
6 Correct 18 ms 40276 KB Output is correct
7 Correct 18 ms 40224 KB Output is correct
8 Correct 18 ms 40148 KB Output is correct
9 Correct 21 ms 40148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 40200 KB Output is correct
2 Correct 18 ms 40148 KB Output is correct
3 Correct 19 ms 40248 KB Output is correct
4 Correct 19 ms 40160 KB Output is correct
5 Correct 20 ms 40148 KB Output is correct
6 Correct 18 ms 40276 KB Output is correct
7 Correct 18 ms 40224 KB Output is correct
8 Correct 18 ms 40148 KB Output is correct
9 Correct 21 ms 40148 KB Output is correct
10 Correct 22 ms 40860 KB Output is correct
11 Correct 22 ms 40832 KB Output is correct
12 Correct 23 ms 40924 KB Output is correct
13 Correct 22 ms 40952 KB Output is correct
14 Correct 22 ms 40780 KB Output is correct
15 Correct 23 ms 41064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 657 ms 85736 KB Output is correct
2 Correct 447 ms 87744 KB Output is correct
3 Correct 400 ms 86920 KB Output is correct
4 Correct 422 ms 86956 KB Output is correct
5 Correct 450 ms 86972 KB Output is correct
6 Correct 481 ms 87572 KB Output is correct
7 Correct 538 ms 89180 KB Output is correct
8 Correct 436 ms 87852 KB Output is correct
9 Correct 330 ms 87116 KB Output is correct
10 Correct 312 ms 85648 KB Output is correct
11 Correct 336 ms 86380 KB Output is correct
12 Correct 394 ms 88300 KB Output is correct
13 Correct 519 ms 98320 KB Output is correct
14 Correct 469 ms 98252 KB Output is correct
15 Correct 554 ms 98320 KB Output is correct
16 Correct 564 ms 98360 KB Output is correct
17 Correct 664 ms 89040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 40200 KB Output is correct
2 Correct 18 ms 40148 KB Output is correct
3 Correct 19 ms 40248 KB Output is correct
4 Correct 19 ms 40160 KB Output is correct
5 Correct 20 ms 40148 KB Output is correct
6 Correct 18 ms 40276 KB Output is correct
7 Correct 18 ms 40224 KB Output is correct
8 Correct 18 ms 40148 KB Output is correct
9 Correct 21 ms 40148 KB Output is correct
10 Correct 22 ms 40860 KB Output is correct
11 Correct 22 ms 40832 KB Output is correct
12 Correct 23 ms 40924 KB Output is correct
13 Correct 22 ms 40952 KB Output is correct
14 Correct 22 ms 40780 KB Output is correct
15 Correct 23 ms 41064 KB Output is correct
16 Correct 657 ms 85736 KB Output is correct
17 Correct 447 ms 87744 KB Output is correct
18 Correct 400 ms 86920 KB Output is correct
19 Correct 422 ms 86956 KB Output is correct
20 Correct 450 ms 86972 KB Output is correct
21 Correct 481 ms 87572 KB Output is correct
22 Correct 538 ms 89180 KB Output is correct
23 Correct 436 ms 87852 KB Output is correct
24 Correct 330 ms 87116 KB Output is correct
25 Correct 312 ms 85648 KB Output is correct
26 Correct 336 ms 86380 KB Output is correct
27 Correct 394 ms 88300 KB Output is correct
28 Correct 519 ms 98320 KB Output is correct
29 Correct 469 ms 98252 KB Output is correct
30 Correct 554 ms 98320 KB Output is correct
31 Correct 564 ms 98360 KB Output is correct
32 Correct 664 ms 89040 KB Output is correct
33 Correct 684 ms 87812 KB Output is correct
34 Correct 225 ms 75716 KB Output is correct
35 Correct 669 ms 90296 KB Output is correct
36 Correct 571 ms 87480 KB Output is correct
37 Correct 645 ms 89376 KB Output is correct
38 Correct 556 ms 88136 KB Output is correct
39 Correct 498 ms 86184 KB Output is correct
40 Correct 608 ms 99188 KB Output is correct
41 Correct 482 ms 88920 KB Output is correct
42 Correct 497 ms 87756 KB Output is correct
43 Correct 679 ms 94924 KB Output is correct
44 Correct 586 ms 89392 KB Output is correct
45 Correct 417 ms 87228 KB Output is correct
46 Correct 416 ms 86496 KB Output is correct
47 Correct 545 ms 98508 KB Output is correct
48 Correct 481 ms 98272 KB Output is correct
49 Correct 484 ms 98436 KB Output is correct
50 Correct 610 ms 98268 KB Output is correct
51 Correct 495 ms 100212 KB Output is correct
52 Correct 518 ms 100068 KB Output is correct