답안 #413635

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
413635 2021-05-29T06:53:53 Z LastRonin 늑대인간 (IOI18_werewolf) C++14
100 / 100
1898 ms 262348 KB
#include <bits/stdc++.h>
#include "werewolf.h"
#define ll long long
#define pb push_back
using namespace std;

const ll N = 3e5;


int n;
vector<int> g[N];
vector<int> nt[2][N];

struct DSU {
	ll p[N] = {0};
	ll get(ll v) {     
		return p[v] = (p[v] == v ? v : get(p[v]));
	}
} rot[2];

ll tin[2][N], tout[2][N];
ll bp[2][N][20];
int arr[2][N];

void dfs(ll v, ll p, ll t) {
	bp[t][v][0] = p;
	tin[t][v] = ++tout[t][0];
	arr[t][tin[t][v]] = v;
	for(int j = 1; j < 20; j++)
		bp[t][v][j] = bp[t][bp[t][v][j - 1]][j - 1];
	for(auto u : nt[t][v]) {
		dfs(u, v, t);	
	}		
	tout[t][v] = tout[t][0];
}

struct node {
	node *l = nullptr, *r = nullptr;
	ll sum = 0;
	node() {};
} *rt[N];

void bld(node *v, ll l = 1, ll r = n) {
	if(l == r) 
		return;
	ll m = (l + r) >> 1ll;	
	v->l = new node();
	v->r = new node();
	bld(v->l, l, m);
	bld(v->r, m + 1, r);	
}

void upd(ll p, node *v, node *u, ll l = 1, ll r = n) {
	if(l == r) {
		v->sum = 1;
		return;
	}
	ll m = (l + r) >> 1ll;
	if(p <= m) {
		v->r = u->r;
		v->l = new node();
		upd(p, v->l, u->l, l, m);
	}
	else {
		v->l = u->l;
		v->r = new node();
		upd(p, v->r, u->r, m + 1, r);
	}
	v->sum = v->l->sum + v->r->sum;
}

ll get(ll l, ll r, node *v, ll tl = 1, ll tr = n) {
	if(l > tr || tl > r)
		return 0;
	if(l <= tl && tr <= r)
		return (v->sum);
	ll m = (tl + tr) >> 1ll;
	return get(l, r, v->l, tl, m) + get(l, r, v->r, m + 1, tr);
}

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;
	for(int i = 0; i < x.size(); i++) {
		x[i]++, y[i]++;
		g[x[i]].pb(y[i]);
		g[y[i]].pb(x[i]);		
	}
	for(int i = n; i >= 1; i--) {
		rot[0].p[i] = i;
		for(auto u : g[i]) {
			if(u < i)continue;
			ll z = rot[0].get(u);
			if(z == i)continue;
			nt[0][i].pb(z);
			rot[0].p[z] = i;			 
		}
	}   
	for(int i = 1; i <= n; i++) {
		rot[1].p[i] = i;
		for(auto u : g[i]) {
			if(u > i)continue;			
			ll z = rot[1].get(u);
			if(z == i)continue;
			nt[1][i].pb(z);
			rot[1].p[z] = i;
		}
	}
	dfs(1, 0, 0), dfs(n, 0, 1);
	rt[0] = new node();
	bld(rt[0]);
	for(int i = 1; i <= n; i++) {
		rt[i] = new node();
		upd(tin[1][arr[0][i]], rt[i], rt[i - 1]);							
	}
	vector<int> sub;
	for(int i = 0; i < s.size(); i++) {
		ll vs = s[i] + 1, ve = e[i] + 1;
		ll L = l[i] + 1, R = r[i] + 1;
		for(int j = 19; j >= 0; j--) {
			if(bp[0][vs][j] >= L) 
				vs = bp[0][vs][j];
		}
		for(int j = 19; j >= 0; j--) {
			if(bp[1][ve][j] && bp[1][ve][j] <= R)
				ve = bp[1][ve][j]; 
		}
		ll l1 = tin[0][vs], r1 = tout[0][vs];
		ll l2 = tin[1][ve], r2 = tout[1][ve];
		ll h = get(l2, r2, rt[r1]) - get(l2, r2, rt[l1 - 1]);
		sub.pb((h?1:0));
	}
	return sub;                                                	
}

/*
int main() {
	int p, m, q;
	cin >> p >> m >> q;
	vector<int> x,y,l,r,s,e;
	for(int i = 1; i <= m; i++) {
		ll a, b;
		cin >> a >> b;
		x.pb(a),y.pb(b);
	}
	while(q--) {
		ll a, b, c, d;
		cin >> a >> b >> c >> d;
		l.pb(c), r.pb(d);
		s.pb(a), e.pb(b);
	}
	vector<int> ans = check_validaty(p, x, y, s, e, l, r);
	for(auto u : ans)
		cout << u << " ";
	
} */  

Compilation message

werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:83:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |  for(int i = 0; i < x.size(); i++) {
      |                 ~~^~~~~~~~~~
werewolf.cpp:116:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |  for(int i = 0; i < s.size(); i++) {
      |                 ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 21580 KB Output is correct
2 Correct 13 ms 21580 KB Output is correct
3 Correct 13 ms 21432 KB Output is correct
4 Correct 13 ms 21524 KB Output is correct
5 Correct 13 ms 21508 KB Output is correct
6 Correct 13 ms 21592 KB Output is correct
7 Correct 14 ms 21520 KB Output is correct
8 Correct 13 ms 21552 KB Output is correct
9 Correct 15 ms 21548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 21580 KB Output is correct
2 Correct 13 ms 21580 KB Output is correct
3 Correct 13 ms 21432 KB Output is correct
4 Correct 13 ms 21524 KB Output is correct
5 Correct 13 ms 21508 KB Output is correct
6 Correct 13 ms 21592 KB Output is correct
7 Correct 14 ms 21520 KB Output is correct
8 Correct 13 ms 21552 KB Output is correct
9 Correct 15 ms 21548 KB Output is correct
10 Correct 22 ms 24452 KB Output is correct
11 Correct 20 ms 24428 KB Output is correct
12 Correct 21 ms 24396 KB Output is correct
13 Correct 22 ms 24568 KB Output is correct
14 Correct 22 ms 24472 KB Output is correct
15 Correct 28 ms 24524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1144 ms 251392 KB Output is correct
2 Correct 1476 ms 254880 KB Output is correct
3 Correct 1292 ms 252556 KB Output is correct
4 Correct 1200 ms 251556 KB Output is correct
5 Correct 1090 ms 251476 KB Output is correct
6 Correct 1198 ms 251468 KB Output is correct
7 Correct 974 ms 251372 KB Output is correct
8 Correct 1425 ms 254880 KB Output is correct
9 Correct 1095 ms 252776 KB Output is correct
10 Correct 758 ms 251532 KB Output is correct
11 Correct 794 ms 251536 KB Output is correct
12 Correct 943 ms 251412 KB Output is correct
13 Correct 1316 ms 260300 KB Output is correct
14 Correct 1297 ms 260340 KB Output is correct
15 Correct 1328 ms 260268 KB Output is correct
16 Correct 1336 ms 260196 KB Output is correct
17 Correct 971 ms 251324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 21580 KB Output is correct
2 Correct 13 ms 21580 KB Output is correct
3 Correct 13 ms 21432 KB Output is correct
4 Correct 13 ms 21524 KB Output is correct
5 Correct 13 ms 21508 KB Output is correct
6 Correct 13 ms 21592 KB Output is correct
7 Correct 14 ms 21520 KB Output is correct
8 Correct 13 ms 21552 KB Output is correct
9 Correct 15 ms 21548 KB Output is correct
10 Correct 22 ms 24452 KB Output is correct
11 Correct 20 ms 24428 KB Output is correct
12 Correct 21 ms 24396 KB Output is correct
13 Correct 22 ms 24568 KB Output is correct
14 Correct 22 ms 24472 KB Output is correct
15 Correct 28 ms 24524 KB Output is correct
16 Correct 1144 ms 251392 KB Output is correct
17 Correct 1476 ms 254880 KB Output is correct
18 Correct 1292 ms 252556 KB Output is correct
19 Correct 1200 ms 251556 KB Output is correct
20 Correct 1090 ms 251476 KB Output is correct
21 Correct 1198 ms 251468 KB Output is correct
22 Correct 974 ms 251372 KB Output is correct
23 Correct 1425 ms 254880 KB Output is correct
24 Correct 1095 ms 252776 KB Output is correct
25 Correct 758 ms 251532 KB Output is correct
26 Correct 794 ms 251536 KB Output is correct
27 Correct 943 ms 251412 KB Output is correct
28 Correct 1316 ms 260300 KB Output is correct
29 Correct 1297 ms 260340 KB Output is correct
30 Correct 1328 ms 260268 KB Output is correct
31 Correct 1336 ms 260196 KB Output is correct
32 Correct 971 ms 251324 KB Output is correct
33 Correct 1482 ms 251988 KB Output is correct
34 Correct 378 ms 42288 KB Output is correct
35 Correct 1810 ms 254396 KB Output is correct
36 Correct 1405 ms 251964 KB Output is correct
37 Correct 1729 ms 253812 KB Output is correct
38 Correct 1501 ms 252532 KB Output is correct
39 Correct 1408 ms 262304 KB Output is correct
40 Correct 1303 ms 259196 KB Output is correct
41 Correct 1321 ms 253012 KB Output is correct
42 Correct 880 ms 251968 KB Output is correct
43 Correct 1898 ms 258356 KB Output is correct
44 Correct 1602 ms 253584 KB Output is correct
45 Correct 1170 ms 262348 KB Output is correct
46 Correct 1320 ms 262204 KB Output is correct
47 Correct 1305 ms 260288 KB Output is correct
48 Correct 1299 ms 260524 KB Output is correct
49 Correct 1319 ms 260476 KB Output is correct
50 Correct 1294 ms 260368 KB Output is correct
51 Correct 1201 ms 258996 KB Output is correct
52 Correct 1185 ms 259088 KB Output is correct