답안 #580786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
580786 2022-06-21T19:48:55 Z Vanilla 늑대인간 (IOI18_werewolf) C++17
49 / 100
802 ms 60560 KB
#include <bits/stdc++.h>
#include "werewolf.h"
using namespace std;
const int maxn_12 = 3e3 + 2;
const int maxn_3 = 2e5 + 2;
const int lg = 19;
vector <int> ad [maxn_3];
bitset <maxn_12> vis1, vis2;
int act[maxn_3];
int sp[2][maxn_3][lg]; // sp[0] -> min, sp[1] -> max

void dfs1 (int u, int l, int r) {
  vis1[u] = 1;
  for (int v: ad[u]) {
    if (v < l || vis1[v]) continue;
    dfs1(v, l, r);
  }
}

int dfs2 (int u, int l, int r) {
  vis2[u] = 1;
  bool b = (vis1[u]);
  for (int v: ad[u]) {
    if (v > r || vis2[v]) continue;
    b|=dfs2(v, l, r);
  }
  return b;  
}

int query0 (int l, int r) {
  int k = log2(r - l + 1);
  return min(sp[0][l][k], sp[0][r - (1 << k) + 1][k]);
}

int query1 (int l, int r) {
  int k = log2(r - l + 1);
  return max(sp[1][l][k], sp[1][r - (1 << k) + 1][k]);
}

vector<int> check_validity(int N, vector<int> X, vector<int> Y,
                                vector<int> S, vector<int> E,
                                vector<int> L, vector<int> R) {
	for (int i = 0; i < X.size(); i++){
		ad[X[i]].push_back(Y[i]);
		ad[Y[i]].push_back(X[i]);
	}
	int Q = S.size();
	vector<int> A(Q);
	if (N <= 3000 && Q <= 3000 && X.size() <= 6000) {
		for (int i = 0; i < Q; ++i) {
			vis1 = vis2 = 0;
			dfs1(S[i], L[i], R[i]);
			A[i] = dfs2(E[i], L[i], R[i]);
		}
	}
	else {
		for (int i = 0; i < N; i++){
			act[i] = -1;
		}
		for (int i = 0; i < N; i++){
			if (ad[i].size() == 1) {
				int node = i;
				act[node] = 0;
				while (1) {
					for (int v: ad[node]) {
						if (act[v] == -1) {
							act[v] = act[node] + 1;
							node = v;
							break;
						}
					}
					if (ad[node].size() == 1) break;
				}
				break;
			}
		}
		for (int i = 0; i < N; i++){
			assert(act[i] != -1);
			sp[0][act[i]][0] = i;
			sp[1][act[i]][0] = i;
		}
		for (int k = 1; k < lg; k++){
			for (int i = 0; i + (1 << k) - 1 < N; i++){
				sp[0][i][k] = min(sp[0][i][k-1], sp[0][i + (1 << (k - 1))][k-1]);
				sp[1][i][k] = max(sp[1][i][k-1], sp[1][i + (1 << (k - 1))][k-1]);
			}
		}

		for (int i = 0; i < Q; ++i) {
			int n1 = act[S[i]], n2 = act[E[i]];
			if (n1 < n2){ 
				int l = n1, r = n2, f1 = -1, f2 = 1e9;
				while (l <= r) {
					int mid = (l + r) / 2;
					if (query0(n1, mid) >= L[i]) {
						f1 = mid;
						l = mid + 1;
					}
					else {
						r = mid - 1;
					}
				}
				l = n1, r = n2;
				while (l <= r) {
					int mid = (l + r) / 2;
					if (query1(mid, n2) <= R[i]) {
						f2 = mid;
						r = mid - 1;
					}
					else {
						l = mid + 1;
					}
				}
				A[i] = (f1 >= f2);
			}
			else {
				swap(n1, n2);
				int l = n1, r = n2, f1 = -1, f2 = 1e9;
				while (l <= r) {
					int mid = (l + r) / 2;
					if (query1(n1, mid) <= R[i]) {
						f1 = mid;
						l = mid + 1;
					}
					else {
						r = mid - 1;
					}
				}
				l = n1, r = n2;
				while (l <= r) {
					int mid = (l + r) / 2;
					if (query0(mid, n2) >= L[i]) {
						f2 = mid;
						r = mid - 1;
					}
					else {
						l = mid + 1;
					}
				}
				A[i] = (f1 >= f2);
			}
		}
	}
	return A;
}

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:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for (int i = 0; i < X.size(); i++){
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 231 ms 5276 KB Output is correct
11 Correct 142 ms 5332 KB Output is correct
12 Correct 13 ms 5332 KB Output is correct
13 Correct 252 ms 5300 KB Output is correct
14 Correct 161 ms 5236 KB Output is correct
15 Correct 209 ms 5420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 791 ms 52072 KB Output is correct
2 Correct 693 ms 51988 KB Output is correct
3 Correct 762 ms 51916 KB Output is correct
4 Correct 793 ms 60412 KB Output is correct
5 Correct 791 ms 60512 KB Output is correct
6 Correct 799 ms 60408 KB Output is correct
7 Correct 742 ms 60420 KB Output is correct
8 Correct 699 ms 60416 KB Output is correct
9 Correct 364 ms 60396 KB Output is correct
10 Correct 394 ms 60560 KB Output is correct
11 Correct 448 ms 60312 KB Output is correct
12 Correct 419 ms 60428 KB Output is correct
13 Correct 775 ms 60404 KB Output is correct
14 Correct 802 ms 60420 KB Output is correct
15 Correct 749 ms 60412 KB Output is correct
16 Correct 741 ms 60420 KB Output is correct
17 Correct 763 ms 60416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 231 ms 5276 KB Output is correct
11 Correct 142 ms 5332 KB Output is correct
12 Correct 13 ms 5332 KB Output is correct
13 Correct 252 ms 5300 KB Output is correct
14 Correct 161 ms 5236 KB Output is correct
15 Correct 209 ms 5420 KB Output is correct
16 Correct 791 ms 52072 KB Output is correct
17 Correct 693 ms 51988 KB Output is correct
18 Correct 762 ms 51916 KB Output is correct
19 Correct 793 ms 60412 KB Output is correct
20 Correct 791 ms 60512 KB Output is correct
21 Correct 799 ms 60408 KB Output is correct
22 Correct 742 ms 60420 KB Output is correct
23 Correct 699 ms 60416 KB Output is correct
24 Correct 364 ms 60396 KB Output is correct
25 Correct 394 ms 60560 KB Output is correct
26 Correct 448 ms 60312 KB Output is correct
27 Correct 419 ms 60428 KB Output is correct
28 Correct 775 ms 60404 KB Output is correct
29 Correct 802 ms 60420 KB Output is correct
30 Correct 749 ms 60412 KB Output is correct
31 Correct 741 ms 60420 KB Output is correct
32 Correct 763 ms 60416 KB Output is correct
33 Runtime error 231 ms 53744 KB Execution killed with signal 6
34 Halted 0 ms 0 KB -