답안 #292676

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
292676 2020-09-07T11:41:33 Z _7_7_ 늑대인간 (IOI18_werewolf) C++14
100 / 100
2120 ms 213324 KB
#include "werewolf.h"
#include <bits/stdc++.h>                                           
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;  
typedef unsigned long long ull;         
typedef vector < pii > vpii;                                   	
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;
 
typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
 
const int inf = 1e9, maxn = 2e5 + 48, mod = 998244353, N = 4e5 + 12;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 300;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = acos(-1);
const ll INF = 1e18;

int n, m, q, p[N], tin[N][2], tout[N][2], timer;
vi g[N], gg[N], G[N];

struct node {
	node *l, *r;
	int sum;

	node () {
		l = r = NULL;
		sum = 0;
	}

	node (int x) {
		l = r = NULL;
		sum = x;
	}

	node (node *L, node *R) {
		l = L, r = R;
		sum = (!l ? 0 : l->sum) + (!r ? 0 : r->sum);	
	}
};

typedef node* pnode;
pnode root[N];

pnode build1 (int tl = 1, int tr = n) {
	if (tl == tr) 
		return new node(0);
	int tm = (tl + tr) >> 1;
	return new node(build1(tl, tm), build1(tm + 1, tr));
}

int get (pnode t, int l, int r, int tl = 1, int tr = n) {
	if (l > r || tl > r || l > tr)
		return 0;

	if (l <= tl && tr <= r)
		return t->sum;
	
	int tm = (tl + tr) >> 1;
	return get(t->l, l, r, tl, tm) + get(t->r, l, r, tm + 1, tr);
}

pnode update (pnode t, int pos, int x, int tl = 1, int tr = n) {
	if (tl == tr) 
		return new node(t->sum + x);

	int tm = (tl + tr) >> 1;
	if (pos <= tm)
		return new node(update(t->l, pos, x, tl, tm), t->r);
	return new node(t->l, update(t->r, pos, x, tm + 1, tr));
}



int get (int v) {
	return p[v] == v ? v : p[v] = get(p[v]);              	
}


void build () {
	timer = 0;
	for (int i = 0; i < n; ++i) {
		p[i] = i;                
		gg[i].clear();
		G[i].clear();
	}                
} 

void dfs (int v, int i) {
	tin[v][i] = ++timer;
	for (auto to : gg[v])
		dfs(to, i);
	tout[v][i] = timer;
}

vi check_validity (int _n, vi x, vi y, vi s, vi e, vi l, vi r) {
	n = _n;
	m = sz(x);
	q = sz(l);

	for (int i = 0; i < m; ++i) {
		if (x[i] > y[i])
			swap(x[i], y[i]);
		g[x[i]].pb(y[i]);
		g[y[i]].pb(x[i]);
	}

	build();
	for (int i = 0; i < q; ++i) 
		G[l[i]].pb(i);

	for (int i = n - 1; i >= 0; --i) {
		for (auto j : g[i]) {
			if (get(i) == get(j) || j < i)
				continue;

			gg[i].pb(get(j));
			p[get(j)] = i;	
		}

		for (auto j : G[i]) 
			s[j] = get(s[j]);
	}
	dfs(0, 0);

	build();
	for (int i = 0; i < q; ++i)
		G[r[i]].pb(i);

	for (int i = 0; i < n; ++i) {
		for (auto j : g[i]) {
			if (get(i) == get(j) || j > i)
				continue;

			gg[i].pb(get(j));
			p[get(j)] = i;
		}         

		for (auto j : G[i]) 
			e[j] = get(e[j]);
	}
	
	
	
	dfs(n - 1, 1);	
	
	build();
	root[0] = build1();
	for (int i = 0; i < n; ++i) 
		G[tin[i][0]].pb(i);

	for (int i = 1; i <= n; ++i) {
		root[i] = root[i - 1];
		for (auto j : G[i])
			root[i] = update(root[i], tin[j][1], 1);	
	}


	vi E;
	for (int i = 0; i < q; ++i) { 
  		E.pb(min(1, get(root[tout[s[i]][0]], tin[e[i]][1], tout[e[i]][1]) - get(root[tin[s[i]][0] - 1], tin[e[i]][1], tout[e[i]][1])));		
	}
	
	return E;
}
               	
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 28544 KB Output is correct
2 Correct 20 ms 28544 KB Output is correct
3 Correct 20 ms 28544 KB Output is correct
4 Correct 19 ms 28544 KB Output is correct
5 Correct 20 ms 28544 KB Output is correct
6 Correct 20 ms 28544 KB Output is correct
7 Correct 20 ms 28544 KB Output is correct
8 Correct 20 ms 28544 KB Output is correct
9 Correct 20 ms 28544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 28544 KB Output is correct
2 Correct 20 ms 28544 KB Output is correct
3 Correct 20 ms 28544 KB Output is correct
4 Correct 19 ms 28544 KB Output is correct
5 Correct 20 ms 28544 KB Output is correct
6 Correct 20 ms 28544 KB Output is correct
7 Correct 20 ms 28544 KB Output is correct
8 Correct 20 ms 28544 KB Output is correct
9 Correct 20 ms 28544 KB Output is correct
10 Correct 29 ms 30592 KB Output is correct
11 Correct 29 ms 30584 KB Output is correct
12 Correct 29 ms 30588 KB Output is correct
13 Correct 29 ms 30720 KB Output is correct
14 Correct 29 ms 30720 KB Output is correct
15 Correct 31 ms 30720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1208 ms 195296 KB Output is correct
2 Correct 1354 ms 198772 KB Output is correct
3 Correct 1252 ms 196404 KB Output is correct
4 Correct 1150 ms 195444 KB Output is correct
5 Correct 1148 ms 195564 KB Output is correct
6 Correct 1190 ms 195452 KB Output is correct
7 Correct 984 ms 196700 KB Output is correct
8 Correct 1352 ms 198900 KB Output is correct
9 Correct 1164 ms 197304 KB Output is correct
10 Correct 829 ms 196232 KB Output is correct
11 Correct 870 ms 196264 KB Output is correct
12 Correct 969 ms 195704 KB Output is correct
13 Correct 1068 ms 200012 KB Output is correct
14 Correct 1100 ms 200044 KB Output is correct
15 Correct 1074 ms 200180 KB Output is correct
16 Correct 1051 ms 199924 KB Output is correct
17 Correct 995 ms 196472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 28544 KB Output is correct
2 Correct 20 ms 28544 KB Output is correct
3 Correct 20 ms 28544 KB Output is correct
4 Correct 19 ms 28544 KB Output is correct
5 Correct 20 ms 28544 KB Output is correct
6 Correct 20 ms 28544 KB Output is correct
7 Correct 20 ms 28544 KB Output is correct
8 Correct 20 ms 28544 KB Output is correct
9 Correct 20 ms 28544 KB Output is correct
10 Correct 29 ms 30592 KB Output is correct
11 Correct 29 ms 30584 KB Output is correct
12 Correct 29 ms 30588 KB Output is correct
13 Correct 29 ms 30720 KB Output is correct
14 Correct 29 ms 30720 KB Output is correct
15 Correct 31 ms 30720 KB Output is correct
16 Correct 1208 ms 195296 KB Output is correct
17 Correct 1354 ms 198772 KB Output is correct
18 Correct 1252 ms 196404 KB Output is correct
19 Correct 1150 ms 195444 KB Output is correct
20 Correct 1148 ms 195564 KB Output is correct
21 Correct 1190 ms 195452 KB Output is correct
22 Correct 984 ms 196700 KB Output is correct
23 Correct 1352 ms 198900 KB Output is correct
24 Correct 1164 ms 197304 KB Output is correct
25 Correct 829 ms 196232 KB Output is correct
26 Correct 870 ms 196264 KB Output is correct
27 Correct 969 ms 195704 KB Output is correct
28 Correct 1068 ms 200012 KB Output is correct
29 Correct 1100 ms 200044 KB Output is correct
30 Correct 1074 ms 200180 KB Output is correct
31 Correct 1051 ms 199924 KB Output is correct
32 Correct 995 ms 196472 KB Output is correct
33 Correct 1545 ms 202944 KB Output is correct
34 Correct 429 ms 62320 KB Output is correct
35 Correct 1829 ms 205424 KB Output is correct
36 Correct 1469 ms 202356 KB Output is correct
37 Correct 1871 ms 204532 KB Output is correct
38 Correct 1672 ms 202872 KB Output is correct
39 Correct 1553 ms 211392 KB Output is correct
40 Correct 1504 ms 212140 KB Output is correct
41 Correct 1664 ms 204028 KB Output is correct
42 Correct 1099 ms 202908 KB Output is correct
43 Correct 2120 ms 209152 KB Output is correct
44 Correct 1873 ms 204500 KB Output is correct
45 Correct 1448 ms 212348 KB Output is correct
46 Correct 1540 ms 212212 KB Output is correct
47 Correct 1141 ms 206392 KB Output is correct
48 Correct 1134 ms 206240 KB Output is correct
49 Correct 1149 ms 206400 KB Output is correct
50 Correct 1157 ms 206256 KB Output is correct
51 Correct 1241 ms 213324 KB Output is correct
52 Correct 1165 ms 213236 KB Output is correct