답안 #1087766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087766 2024-09-13T08:10:36 Z Tob 늑대인간 (IOI18_werewolf) C++14
100 / 100
439 ms 109896 KB
#include <bits/stdc++.h>
#include "werewolf.h"
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pii;
typedef vector <int> vi;

const int N = 2e5 + 7;

struct T {
	int n, tim;
	vector <vector <int> > adj;
	vector <int> par, st, en, wh;
	vector <int> pa[20];
	void init(int n_) {
		n = n_; tim = 0;
		par.clear();
		st.resize(n); en.resize(n); adj.resize(n); wh.resize(n);
		for (int i = 0; i < n; i++) par.pb(i);
		for (int i = 0; i < 20; i++) pa[i].resize(n);
	}
	int find(int x) {return (par[x] == x) ? x : (par[x] = find(par[x]));}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		par[y] = x;
		adj[x].pb(y);
	}
	void dfs(int x, int p = -1) {
		pa[0][x] = p;
		wh[tim] = x;
		st[x] = tim++;
		for (int y : adj[x]) dfs(y, x);
		en[x] = tim-1;
	}
	void fin() {
		for (int i = 1; i < 20; i++) {
			for (int j = 0; j < n; j++) {
				if (pa[i-1][j] != -1) pa[i][j] = pa[i-1][pa[i-1][j]];
				else pa[i][j] = -1;
			}
		}
	}
} tl, tr;

struct qu {
	int l, r, ix, o;
};
vector <qu> qe[N];

int fen[N];
void add(int x, int y) {for (x++; x < N; x += x & -x) fen[x] += y;}
int get(int x) {int out = 0; for (x++; x; x -= x & -x) out += fen[x]; return out;}

vi check_validity(int n, vi X, vi Y, vi S, vi E, vi L, vi R) {
	int m = X.size(), q = S.size();
	tl.init(n); tr.init(n);
	vector <vector <int> > adj(n);
	for (int i = 0; i < m; i++) {
		adj[X[i]].pb(Y[i]);
		adj[Y[i]].pb(X[i]);
	}
	for (int i = n-1; i >= 0; i--) for (auto x : adj[i]) if (x > i) tl.unite(i, x);
	for (int i = 0; i < n; i++) for (auto x : adj[i]) if (x < i) tr.unite(i, x);
	tl.dfs(0);
	tl.fin();
	tr.dfs(n-1);
	tr.fin();
	for (int i = 0; i < q; i++) {
		int x = S[i];
		for (int j = 19; j >= 0; j--) if (tl.pa[j][x] != -1 && tl.pa[j][x] >= L[i]) x = tl.pa[j][x];
		int a = tl.st[x], b = tl.en[x];
		x = E[i];
		for (int j = 19; j >= 0; j--) if (tr.pa[j][x] != -1 && tr.pa[j][x] <= R[i]) x = tr.pa[j][x];
		int c = tr.st[x], d = tr.en[x];
		if (a) qe[a-1].pb({c, d, i, -1});
		qe[b].pb({c, d, i, 1});
	}
	vector <int> a(n), res(q, 0);
	for (int i = 0; i < n; i++) a[i] = tr.st[tl.wh[i]];
	for (int i = 0; i < n; i++) {
		add(a[i], 1);
		for (auto x : qe[i]) res[x.ix] += (get(x.r)-get(x.l-1))*x.o;
	}
	for (int i = 0; i < q; i++) if (res[i]) res[i] = 1;
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5208 KB Output is correct
2 Correct 2 ms 5212 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 5212 KB Output is correct
6 Correct 2 ms 5212 KB Output is correct
7 Correct 2 ms 5212 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 2 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5208 KB Output is correct
2 Correct 2 ms 5212 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 5212 KB Output is correct
6 Correct 2 ms 5212 KB Output is correct
7 Correct 2 ms 5212 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 2 ms 5212 KB Output is correct
10 Correct 5 ms 6400 KB Output is correct
11 Correct 6 ms 6488 KB Output is correct
12 Correct 5 ms 6488 KB Output is correct
13 Correct 5 ms 6492 KB Output is correct
14 Correct 5 ms 6596 KB Output is correct
15 Correct 6 ms 6564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 356 ms 101220 KB Output is correct
2 Correct 363 ms 103240 KB Output is correct
3 Correct 345 ms 101088 KB Output is correct
4 Correct 331 ms 99808 KB Output is correct
5 Correct 335 ms 100328 KB Output is correct
6 Correct 359 ms 101224 KB Output is correct
7 Correct 309 ms 99916 KB Output is correct
8 Correct 349 ms 103240 KB Output is correct
9 Correct 261 ms 99044 KB Output is correct
10 Correct 244 ms 99652 KB Output is correct
11 Correct 253 ms 99656 KB Output is correct
12 Correct 260 ms 99800 KB Output is correct
13 Correct 388 ms 107068 KB Output is correct
14 Correct 413 ms 107068 KB Output is correct
15 Correct 390 ms 107228 KB Output is correct
16 Correct 376 ms 107068 KB Output is correct
17 Correct 302 ms 99656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5208 KB Output is correct
2 Correct 2 ms 5212 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 5212 KB Output is correct
6 Correct 2 ms 5212 KB Output is correct
7 Correct 2 ms 5212 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 2 ms 5212 KB Output is correct
10 Correct 5 ms 6400 KB Output is correct
11 Correct 6 ms 6488 KB Output is correct
12 Correct 5 ms 6488 KB Output is correct
13 Correct 5 ms 6492 KB Output is correct
14 Correct 5 ms 6596 KB Output is correct
15 Correct 6 ms 6564 KB Output is correct
16 Correct 356 ms 101220 KB Output is correct
17 Correct 363 ms 103240 KB Output is correct
18 Correct 345 ms 101088 KB Output is correct
19 Correct 331 ms 99808 KB Output is correct
20 Correct 335 ms 100328 KB Output is correct
21 Correct 359 ms 101224 KB Output is correct
22 Correct 309 ms 99916 KB Output is correct
23 Correct 349 ms 103240 KB Output is correct
24 Correct 261 ms 99044 KB Output is correct
25 Correct 244 ms 99652 KB Output is correct
26 Correct 253 ms 99656 KB Output is correct
27 Correct 260 ms 99800 KB Output is correct
28 Correct 388 ms 107068 KB Output is correct
29 Correct 413 ms 107068 KB Output is correct
30 Correct 390 ms 107228 KB Output is correct
31 Correct 376 ms 107068 KB Output is correct
32 Correct 302 ms 99656 KB Output is correct
33 Correct 381 ms 101468 KB Output is correct
34 Correct 183 ms 44224 KB Output is correct
35 Correct 394 ms 103800 KB Output is correct
36 Correct 384 ms 101868 KB Output is correct
37 Correct 412 ms 102984 KB Output is correct
38 Correct 401 ms 102312 KB Output is correct
39 Correct 404 ms 109040 KB Output is correct
40 Correct 403 ms 109656 KB Output is correct
41 Correct 309 ms 101192 KB Output is correct
42 Correct 280 ms 99136 KB Output is correct
43 Correct 390 ms 108104 KB Output is correct
44 Correct 335 ms 102832 KB Output is correct
45 Correct 300 ms 108856 KB Output is correct
46 Correct 317 ms 108128 KB Output is correct
47 Correct 398 ms 107392 KB Output is correct
48 Correct 399 ms 107232 KB Output is correct
49 Correct 368 ms 107328 KB Output is correct
50 Correct 439 ms 107076 KB Output is correct
51 Correct 364 ms 109896 KB Output is correct
52 Correct 371 ms 109712 KB Output is correct