답안 #465403

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
465403 2021-08-15T21:25:05 Z dutch 늑대인간 (IOI18_werewolf) C++17
100 / 100
653 ms 60312 KB
#include <bits/stdc++.h>
using namespace std;
#include "werewolf.h"
typedef vector<int> vi;
#define vii(Z) iota(begin(Z), end(Z), 0)
 
const int Z = 2e5;
 
int Q, k, dfsTimer;
int e[Z], r[Z], lca[2][Z], st[2*Z], tL[2][Z], tR[2][Z];
vi g[2][Z], g2[Z];

int find(int u){
	return e[u] < 0 ? u : e[u] = find(e[u]);
}
 
void dfs(int u){
	tL[k][u] = ++dfsTimer;
	for(int &v : g2[u]) dfs(v);
	tR[k][u] = dfsTimer;
}
 
vi check_validity(int N, vi X, vi Y, vi S, vi E, vi L, vi R){
	Q = size(S);
	for(int i=size(X); --i>=0; ){
		if(X[i] > Y[i]) swap(X[i], Y[i]);
		g[0][Y[i]].push_back(X[i]);
		g[1][X[i]].push_back(Y[i]);
	}
	
	vi h(N); vii(h);
	vi byE(Q); vii(byE);
	vi byS(Q); vii(byS);
	int Ep = Q - 1, Sp = Q - 1;
 
	sort(begin(byS), end(byS), [&](int u, int v){ return L[u] < L[v]; });
	sort(begin(byE), end(byE), [&](int u, int v){ return R[u] > R[v]; });
 
	for(; k<2; ++k){
		iota(r, r+N, 0);
		fill(e, e+N,-1);
 
		for(int &i : h){
			if(k) while(Sp >= 0 && L[byS[Sp]] > i)
					lca[k][byS[Sp]] = r[find(S[byS[Sp]])], --Sp;
			else  while(Ep >= 0 && R[byE[Ep]] < i)
					lca[k][byE[Ep]] = r[find(E[byE[Ep]])], --Ep;

			g2[i].clear();
			int u; r[i] = i;
			for(int &v : g[k][i]){
				u = find(i), v = find(v);
				if(u != v){
					g2[i].push_back(r[v]); r[v] = i;
					if(e[u] > e[v]) swap(u, v);
					e[u] += e[v], e[v] = u;
				}
			}
		}
 
		if(k) for(int i=0; i<=Sp; ++i) lca[k][byS[i]] = h.back();
		else  for(int i=0; i<=Ep; ++i) lca[k][byE[i]] = h.back();
 
		dfsTimer = -1;
		dfs(h.back());
		reverse(begin(h), end(h));
	}
 
	vector<array<int, 3>> q(Q);
 
	for(int i=0; i<Q; ++i)
 		q[i] = {tL[0][lca[0][i]], tR[0][lca[0][i]], i};
 
	vi byL(N), res(Q); int pt = N-1;
	vii(byL);
	sort(begin(byL), end(byL), [&](int u, int v){
		return tL[0][u] < tL[0][v];
	});
	sort(rbegin(q), rend(q));
 
	fill(st, st+N+N, Z<<1);
	for(auto &[lx, rx, id] : q){
		while(pt >= 0 && tL[0][byL[pt]] >= lx){
			int i = tL[1][byL[pt]];
			for(st[i += N] = tL[0][byL[pt--]]; i/=2; )
				st[i] = min(st[2*i], st[2*i+1]);
		}
		int qL = tL[1][lca[1][id]], qR = tR[1][lca[1][id]], x = N+N;
 
		for(qL+=N, qR+=N+1; qL<qR; qL/=2, qR/=2){
			if(qL & 1) x = min(x, st[qL++]);
			if(qR & 1) x = min(x, st[--qR]);
		}
		res[id] = x <= rx;
	}
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14412 KB Output is correct
2 Correct 9 ms 14344 KB Output is correct
3 Correct 8 ms 14428 KB Output is correct
4 Correct 8 ms 14412 KB Output is correct
5 Correct 8 ms 14436 KB Output is correct
6 Correct 8 ms 14412 KB Output is correct
7 Correct 9 ms 14412 KB Output is correct
8 Correct 8 ms 14412 KB Output is correct
9 Correct 8 ms 14412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14412 KB Output is correct
2 Correct 9 ms 14344 KB Output is correct
3 Correct 8 ms 14428 KB Output is correct
4 Correct 8 ms 14412 KB Output is correct
5 Correct 8 ms 14436 KB Output is correct
6 Correct 8 ms 14412 KB Output is correct
7 Correct 9 ms 14412 KB Output is correct
8 Correct 8 ms 14412 KB Output is correct
9 Correct 8 ms 14412 KB Output is correct
10 Correct 13 ms 14924 KB Output is correct
11 Correct 14 ms 14940 KB Output is correct
12 Correct 13 ms 15068 KB Output is correct
13 Correct 13 ms 15052 KB Output is correct
14 Correct 14 ms 15052 KB Output is correct
15 Correct 14 ms 14988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 566 ms 52424 KB Output is correct
2 Correct 507 ms 55056 KB Output is correct
3 Correct 518 ms 53248 KB Output is correct
4 Correct 523 ms 52556 KB Output is correct
5 Correct 560 ms 52628 KB Output is correct
6 Correct 508 ms 52504 KB Output is correct
7 Correct 528 ms 52540 KB Output is correct
8 Correct 513 ms 54804 KB Output is correct
9 Correct 469 ms 53280 KB Output is correct
10 Correct 491 ms 52672 KB Output is correct
11 Correct 509 ms 52896 KB Output is correct
12 Correct 506 ms 52552 KB Output is correct
13 Correct 507 ms 59692 KB Output is correct
14 Correct 531 ms 59816 KB Output is correct
15 Correct 531 ms 59824 KB Output is correct
16 Correct 509 ms 59844 KB Output is correct
17 Correct 562 ms 52500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14412 KB Output is correct
2 Correct 9 ms 14344 KB Output is correct
3 Correct 8 ms 14428 KB Output is correct
4 Correct 8 ms 14412 KB Output is correct
5 Correct 8 ms 14436 KB Output is correct
6 Correct 8 ms 14412 KB Output is correct
7 Correct 9 ms 14412 KB Output is correct
8 Correct 8 ms 14412 KB Output is correct
9 Correct 8 ms 14412 KB Output is correct
10 Correct 13 ms 14924 KB Output is correct
11 Correct 14 ms 14940 KB Output is correct
12 Correct 13 ms 15068 KB Output is correct
13 Correct 13 ms 15052 KB Output is correct
14 Correct 14 ms 15052 KB Output is correct
15 Correct 14 ms 14988 KB Output is correct
16 Correct 566 ms 52424 KB Output is correct
17 Correct 507 ms 55056 KB Output is correct
18 Correct 518 ms 53248 KB Output is correct
19 Correct 523 ms 52556 KB Output is correct
20 Correct 560 ms 52628 KB Output is correct
21 Correct 508 ms 52504 KB Output is correct
22 Correct 528 ms 52540 KB Output is correct
23 Correct 513 ms 54804 KB Output is correct
24 Correct 469 ms 53280 KB Output is correct
25 Correct 491 ms 52672 KB Output is correct
26 Correct 509 ms 52896 KB Output is correct
27 Correct 506 ms 52552 KB Output is correct
28 Correct 507 ms 59692 KB Output is correct
29 Correct 531 ms 59816 KB Output is correct
30 Correct 531 ms 59824 KB Output is correct
31 Correct 509 ms 59844 KB Output is correct
32 Correct 562 ms 52500 KB Output is correct
33 Correct 582 ms 52548 KB Output is correct
34 Correct 374 ms 38484 KB Output is correct
35 Correct 605 ms 54312 KB Output is correct
36 Correct 607 ms 52972 KB Output is correct
37 Correct 602 ms 53908 KB Output is correct
38 Correct 579 ms 53388 KB Output is correct
39 Correct 492 ms 60312 KB Output is correct
40 Correct 653 ms 58912 KB Output is correct
41 Correct 561 ms 53364 KB Output is correct
42 Correct 557 ms 52988 KB Output is correct
43 Correct 612 ms 57848 KB Output is correct
44 Correct 556 ms 53864 KB Output is correct
45 Correct 470 ms 60276 KB Output is correct
46 Correct 473 ms 60228 KB Output is correct
47 Correct 507 ms 59884 KB Output is correct
48 Correct 493 ms 59820 KB Output is correct
49 Correct 504 ms 59972 KB Output is correct
50 Correct 510 ms 59860 KB Output is correct
51 Correct 607 ms 58960 KB Output is correct
52 Correct 606 ms 58908 KB Output is correct