답안 #296947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
296947 2020-09-11T05:37:24 Z ChrisT 늑대인간 (IOI18_werewolf) C++17
100 / 100
1258 ms 120188 KB
#include <bits/stdc++.h> 
#include "werewolf.h"
using namespace std;
const int MN = 2e5 + 3;
struct Query {
	int l,r,l2,r2,id;
};
vector<int> check_validity (int n, vector<int> x, vector<int> y, vector<int> s, vector<int> e, vector<int> l, vector<int> r) {
	int m = (int)x.size(), qq = (int)s.size(), LOG = __lg(n) + 1;
	vector<vector<int>> aaa(n+1); array<vector<vector<int>>,2> adj;
	for (int j = 0; j < 2; j++) adj[j].resize(n+1);
	vector<int> ret(qq);
	for (int i = 0; i < m; i++) {
		aaa[++x[i]].push_back(++y[i]);
		aaa[y[i]].push_back(x[i]);
	}
	vector<int> p(n+1);
	iota(p.begin(),p.end(),0); //1 is for >=, 0 is for <=
	const auto find = [&] (int x, const auto &find_ref) -> int {
		return p[x] == x ? x : p[x] = find_ref(p[x],find_ref);
	};
	const auto merge = [&] (int a, int b, bool lt) {
		if ((a = find(a,find)) == (b = find(b,find))) return;
		if ((a > b) ^ lt) swap(a,b);
		p[a] = b; adj[lt][b].push_back(a);
	};
	for (int i = n; i >= 1; i--) for (int j : aaa[i]) if (j > i) merge(i,j,1);
	iota(p.begin(),p.end(),0);
	for (int i = 1; i <= n; i++) for (int j : aaa[i]) if (j < i) merge(i,j,0);
	int tt = 0; array<vector<int>,2> st,ed,which; array<vector<vector<int>>,2> jmp, par;
	for (int i = 0; i < 2; i++) st[i].resize(n+1), ed[i].resize(n+1), which[i].resize(n+1), jmp[i].resize(n+1,vector<int>(LOG));
	const auto dfs = [&] (int cur, int p, int id, const auto &dfs_ref) -> void {
		 which[id][st[id][cur] = ++tt] = cur;
		 for (int i : adj[id][cur]) if (i != p) {
			 jmp[id][i][0] = cur;
			 for (int j = 1; j < LOG; j++)
				jmp[id][i][j] = jmp[id][jmp[id][i][j-1]][j-1];
			dfs_ref(i,cur,id,dfs_ref);
		 }
		 ed[id][cur] = tt;
	};
	dfs(1,-1,1,dfs);
	tt = 0;
	dfs(n,-1,0,dfs);
	const auto lift = [&] (int cur, int id, int x) { 
		for (int j = LOG - 1; ~j; j--)
			if (jmp[id][cur][j] && (jmp[id][cur][j] == x || (id ^ (jmp[id][cur][j] < x))))
				cur = jmp[id][cur][j];
		return cur;
	};
	vector<Query> queries(qq);
	for (int i = 0; i < qq; i++) {
		int golt = lift(++e[i],0,++r[i]), gogt = lift(++s[i],1,++l[i]);
		queries[i] = {st[0][golt],ed[0][golt],st[1][gogt],ed[1][gogt],i};
	}
	vector<int> tree(n*2);
	auto update = [&tree,&n] (int i, int v) {
		for (tree[i += n - 1] = v; i > 1; i >>= 1) 
			tree[i>>1] = max(tree[i],tree[i^1]);
	};
	auto query = [&tree,&n] (int l, int r) {
		int ret = 0;
		for (l += n-1, r += n; l < r; l >>= 1, r >>= 1) {
			if (l&1) ret = max(ret,tree[l++]);
			if (r&1) ret = max(ret,tree[--r]);
		}
		return ret;
	};
	sort(queries.begin(),queries.end(),[&](const Query &a, const Query &b){return a.r < b.r;});
	int pp = 1;
	for (Query &q : queries) {
		while (pp <= q.r) {
			update(st[1][which[0][pp]],pp);
			++pp;
		}
		ret[q.id] = query(q.l2,q.r2) >= q.l;
	}
	return ret;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 416 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 416 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 8 ms 1792 KB Output is correct
11 Correct 8 ms 1664 KB Output is correct
12 Correct 7 ms 1664 KB Output is correct
13 Correct 8 ms 2048 KB Output is correct
14 Correct 8 ms 1920 KB Output is correct
15 Correct 9 ms 1792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 849 ms 99448 KB Output is correct
2 Correct 1080 ms 106360 KB Output is correct
3 Correct 917 ms 101752 KB Output is correct
4 Correct 797 ms 99960 KB Output is correct
5 Correct 806 ms 99704 KB Output is correct
6 Correct 845 ms 99576 KB Output is correct
7 Correct 848 ms 99320 KB Output is correct
8 Correct 1039 ms 106488 KB Output is correct
9 Correct 756 ms 101880 KB Output is correct
10 Correct 633 ms 99704 KB Output is correct
11 Correct 667 ms 99832 KB Output is correct
12 Correct 727 ms 99448 KB Output is correct
13 Correct 1105 ms 113016 KB Output is correct
14 Correct 1120 ms 113144 KB Output is correct
15 Correct 1106 ms 113144 KB Output is correct
16 Correct 1105 ms 113144 KB Output is correct
17 Correct 845 ms 99448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 416 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 8 ms 1792 KB Output is correct
11 Correct 8 ms 1664 KB Output is correct
12 Correct 7 ms 1664 KB Output is correct
13 Correct 8 ms 2048 KB Output is correct
14 Correct 8 ms 1920 KB Output is correct
15 Correct 9 ms 1792 KB Output is correct
16 Correct 849 ms 99448 KB Output is correct
17 Correct 1080 ms 106360 KB Output is correct
18 Correct 917 ms 101752 KB Output is correct
19 Correct 797 ms 99960 KB Output is correct
20 Correct 806 ms 99704 KB Output is correct
21 Correct 845 ms 99576 KB Output is correct
22 Correct 848 ms 99320 KB Output is correct
23 Correct 1039 ms 106488 KB Output is correct
24 Correct 756 ms 101880 KB Output is correct
25 Correct 633 ms 99704 KB Output is correct
26 Correct 667 ms 99832 KB Output is correct
27 Correct 727 ms 99448 KB Output is correct
28 Correct 1105 ms 113016 KB Output is correct
29 Correct 1120 ms 113144 KB Output is correct
30 Correct 1106 ms 113144 KB Output is correct
31 Correct 1105 ms 113144 KB Output is correct
32 Correct 845 ms 99448 KB Output is correct
33 Correct 944 ms 100760 KB Output is correct
34 Correct 425 ms 35448 KB Output is correct
35 Correct 1083 ms 105336 KB Output is correct
36 Correct 908 ms 100728 KB Output is correct
37 Correct 1054 ms 104004 KB Output is correct
38 Correct 954 ms 101880 KB Output is correct
39 Correct 976 ms 119524 KB Output is correct
40 Correct 1258 ms 112632 KB Output is correct
41 Correct 877 ms 103024 KB Output is correct
42 Correct 742 ms 100600 KB Output is correct
43 Correct 1190 ms 112120 KB Output is correct
44 Correct 973 ms 103960 KB Output is correct
45 Correct 877 ms 120188 KB Output is correct
46 Correct 934 ms 119544 KB Output is correct
47 Correct 1127 ms 113156 KB Output is correct
48 Correct 1085 ms 113016 KB Output is correct
49 Correct 1098 ms 113144 KB Output is correct
50 Correct 1099 ms 113016 KB Output is correct
51 Correct 1147 ms 112376 KB Output is correct
52 Correct 1142 ms 112648 KB Output is correct