답안 #130606

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
130606 2019-07-15T16:55:23 Z sealnot123 늑대인간 (IOI18_werewolf) C++14
100 / 100
875 ms 125848 KB
#include "werewolf.h"

#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef double D;
typedef long double LD;
typedef vector<int> VI;
const int N = 200005, Q = 400005;
int n, q, m;
struct A{
	int q, u, t;
	bool operator <(const A& o) const{
		return t<o.t;
	}
};

vector<int> g[N], G[N], ans;
vector<A> H, WW;
int P[Q], sz[Q], ll[Q], rr[Q], p[N], dp[N], T;
int st[N], en[N];
set<int> node[N];
set<int>::iterator IT;

int fin(int i){
	if(p[i]==i) return i;
	return fin(p[i]);
}

void merg(int a, int b, bool ww){
	a = fin(a); b = fin(b);
	if(a == b) return ;
	if(dp[a]<dp[b]) swap(a,b);
	if(!ww) G[a].pb(b);
	else{
		for(int it : node[b]) node[a].insert(it);
	}
	p[b] = a;
	dp[a] += dp[b];
}

void dfs(int u){
	st[u] = ++T;
	for(int e : G[u]) dfs(e);
	en[u] = T;
}

VI check_validity(int nn, VI X, VI Y, VI S, VI E, VI L, VI R) {
 	q = SZ(S);
 	n = nn;
 	m = SZ(X);
 	ans.resize(q);
 	int i,j,k,l,a,b,c,d;
 	for(i=0;i<m;i++){
 		g[X[i]].pb(Y[i]);
 		g[Y[i]].pb(X[i]);
 	}
 	for(i=0;i<q;i++){
 		H.pb({i, S[i], L[i]});
 		WW.pb({i, E[i], R[i]});
 	}
 	sort(all(H)); sort(all(WW));
 	// human preparation
 	int nw;
 	nw = q-1;
 	for(i=0;i<n;i++) p[i]=i, dp[i]=1;
 	for(i=n-1;i>=0;i--){
 		for(int e : g[i]){
 			if(e > i) merg(i,e,false);
 		}
 		while(nw>=0 && H[nw].t == i){
 			a = fin(H[nw].u);
 			b = H[nw].q;
 			P[b] = a; 
 			sz[b] = dp[a]; 
 			nw--;
 		}
 	}
 	for(i=0;i<n;i++){
 		if(p[i]==i) dfs(i);
 	}
 	for(i=0;i<q;i++){
 		ll[i] = st[P[i]];
 		rr[i] = st[P[i]]+sz[i]-1;
 	}
 	// werewolf prepareation
 	nw=0;
 	for(i=0;i<n;i++){
 		p[i] = i; dp[i] = 1;
 		node[i].insert(st[i]);
 	}
 	for(i=0;i<n;i++){
 		for(int e : g[i]){
 			if(e < i) merg(i, e, true);
 		}
 		while(nw<q && WW[nw].t == i){
 			a = fin(WW[nw].u);
 			b = WW[nw].q;
 			IT = node[a].lower_bound(ll[b]);
 			if(IT != node[a].end() && *IT <= rr[b]) ans[b] = 1;		
 			nw++;
 		}
 	}
  	return ans;
}
/*
6 6 3
5 1
1 2
1 3
3 4
3 0
5 2
4 2 1 2
4 2 2 2
5 4 3 4
*/

Compilation message

werewolf.cpp: In function 'VI check_validity(int, VI, VI, VI, VI, VI, VI)':
werewolf.cpp:61:9: warning: unused variable 'j' [-Wunused-variable]
   int i,j,k,l,a,b,c,d;
         ^
werewolf.cpp:61:11: warning: unused variable 'k' [-Wunused-variable]
   int i,j,k,l,a,b,c,d;
           ^
werewolf.cpp:61:13: warning: unused variable 'l' [-Wunused-variable]
   int i,j,k,l,a,b,c,d;
             ^
werewolf.cpp:61:19: warning: unused variable 'c' [-Wunused-variable]
   int i,j,k,l,a,b,c,d;
                   ^
werewolf.cpp:61:21: warning: unused variable 'd' [-Wunused-variable]
   int i,j,k,l,a,b,c,d;
                     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 19192 KB Output is correct
2 Correct 19 ms 19192 KB Output is correct
3 Correct 19 ms 19192 KB Output is correct
4 Correct 19 ms 19192 KB Output is correct
5 Correct 19 ms 19192 KB Output is correct
6 Correct 19 ms 19192 KB Output is correct
7 Correct 19 ms 19192 KB Output is correct
8 Correct 24 ms 19192 KB Output is correct
9 Correct 21 ms 19196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 19192 KB Output is correct
2 Correct 19 ms 19192 KB Output is correct
3 Correct 19 ms 19192 KB Output is correct
4 Correct 19 ms 19192 KB Output is correct
5 Correct 19 ms 19192 KB Output is correct
6 Correct 19 ms 19192 KB Output is correct
7 Correct 19 ms 19192 KB Output is correct
8 Correct 24 ms 19192 KB Output is correct
9 Correct 21 ms 19196 KB Output is correct
10 Correct 26 ms 20088 KB Output is correct
11 Correct 26 ms 20220 KB Output is correct
12 Correct 27 ms 20472 KB Output is correct
13 Correct 25 ms 19960 KB Output is correct
14 Correct 25 ms 20088 KB Output is correct
15 Correct 26 ms 20216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 862 ms 115836 KB Output is correct
2 Correct 542 ms 81560 KB Output is correct
3 Correct 569 ms 87192 KB Output is correct
4 Correct 663 ms 95384 KB Output is correct
5 Correct 737 ms 96868 KB Output is correct
6 Correct 785 ms 103240 KB Output is correct
7 Correct 875 ms 125848 KB Output is correct
8 Correct 527 ms 81492 KB Output is correct
9 Correct 526 ms 87064 KB Output is correct
10 Correct 591 ms 95408 KB Output is correct
11 Correct 617 ms 96792 KB Output is correct
12 Correct 713 ms 104292 KB Output is correct
13 Correct 520 ms 80128 KB Output is correct
14 Correct 531 ms 80124 KB Output is correct
15 Correct 549 ms 80028 KB Output is correct
16 Correct 538 ms 80176 KB Output is correct
17 Correct 852 ms 125100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 19192 KB Output is correct
2 Correct 19 ms 19192 KB Output is correct
3 Correct 19 ms 19192 KB Output is correct
4 Correct 19 ms 19192 KB Output is correct
5 Correct 19 ms 19192 KB Output is correct
6 Correct 19 ms 19192 KB Output is correct
7 Correct 19 ms 19192 KB Output is correct
8 Correct 24 ms 19192 KB Output is correct
9 Correct 21 ms 19196 KB Output is correct
10 Correct 26 ms 20088 KB Output is correct
11 Correct 26 ms 20220 KB Output is correct
12 Correct 27 ms 20472 KB Output is correct
13 Correct 25 ms 19960 KB Output is correct
14 Correct 25 ms 20088 KB Output is correct
15 Correct 26 ms 20216 KB Output is correct
16 Correct 862 ms 115836 KB Output is correct
17 Correct 542 ms 81560 KB Output is correct
18 Correct 569 ms 87192 KB Output is correct
19 Correct 663 ms 95384 KB Output is correct
20 Correct 737 ms 96868 KB Output is correct
21 Correct 785 ms 103240 KB Output is correct
22 Correct 875 ms 125848 KB Output is correct
23 Correct 527 ms 81492 KB Output is correct
24 Correct 526 ms 87064 KB Output is correct
25 Correct 591 ms 95408 KB Output is correct
26 Correct 617 ms 96792 KB Output is correct
27 Correct 713 ms 104292 KB Output is correct
28 Correct 520 ms 80128 KB Output is correct
29 Correct 531 ms 80124 KB Output is correct
30 Correct 549 ms 80028 KB Output is correct
31 Correct 538 ms 80176 KB Output is correct
32 Correct 852 ms 125100 KB Output is correct
33 Correct 783 ms 93184 KB Output is correct
34 Correct 344 ms 59044 KB Output is correct
35 Correct 768 ms 85144 KB Output is correct
36 Correct 821 ms 96676 KB Output is correct
37 Correct 770 ms 85824 KB Output is correct
38 Correct 822 ms 92916 KB Output is correct
39 Correct 731 ms 77112 KB Output is correct
40 Correct 838 ms 93592 KB Output is correct
41 Correct 743 ms 87088 KB Output is correct
42 Correct 772 ms 95948 KB Output is correct
43 Correct 798 ms 85976 KB Output is correct
44 Correct 759 ms 86172 KB Output is correct
45 Correct 642 ms 77400 KB Output is correct
46 Correct 616 ms 77224 KB Output is correct
47 Correct 536 ms 80512 KB Output is correct
48 Correct 533 ms 80312 KB Output is correct
49 Correct 546 ms 80260 KB Output is correct
50 Correct 529 ms 80216 KB Output is correct
51 Correct 833 ms 93500 KB Output is correct
52 Correct 826 ms 93592 KB Output is correct