답안 #342360

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
342360 2021-01-01T23:47:40 Z FlashGamezzz 늑대인간 (IOI18_werewolf) C++11
49 / 100
3752 ms 53996 KB
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <unordered_set>
#include <vector>
#include <utility>
#include <map>
//#include "werewolf.h"

using namespace std;

vector<int> adj[200000]; map<int, int> cc; bool r1[3000], r2[3000];
int cr, cl, n, minvs[600000] = {}, maxvs[600000] = {};

void updh(int i, int s, int e, int l, int u, int d) {
	if (s > e || s > u || e < l) {
		return;
	}
	if (s >= l && e <= u) {
		minvs[i] = d; maxvs[i] = d; return;
	}
	updh(i*2+1, s, (s+e)/2, l, u, d); updh(i*2+2, (s+e)/2+1, e, l, u, d);
	minvs[i] = min(minvs[i*2+1], minvs[i*2+2]); maxvs[i] = max(maxvs[i*2+1], maxvs[i*2+2]);
}
void updv(int i, int d) {
	updh(0, 0, n-1, i, i, d);
}
int minh(int i, int s, int e, int l, int u) {
	if (s > e || s > u || e < l) {
		return 1000000000;
	}
	if (s >= l && e <= u) {
		return minvs[i];
	}
	return min(minh(2*i+1, s, (s+e)/2, l, u), minh(2*i+2, (s+e)/2+1, e, l, u));
}
int minv(int l, int u) {
	return minh(0, 0, n-1, l, u);
}
int maxh(int i, int s, int e, int l, int u) {
	if (s > e || s > u || e < l) {
		return -1;
	}
	if (s >= l && e <= u) {
		return maxvs[i];
	}
	return max(maxh(2*i+1, s, (s+e)/2, l, u), maxh(2*i+2, (s+e)/2+1, e, l, u));
}
int maxv(int l, int u) {
	return maxh(0, 0, n-1, l, u);
}

void dfs1(int i){
	if (i >= cl){
		r1[i] = true;
		for (int a : adj[i]){
			if (a >= cl && !r1[a]){
				dfs1(a);
			}
		}
	}
}
void dfs2(int i){
	if (i <= cr){
		r2[i] = true;
		for (int a : adj[i]){
			if (a <= cr && !r2[a]){
				dfs2(a);
			}
		}
	}
}
void dfs3(int i, int p, int ind){
	updv(ind, i); cc[i] = ind;
	for (int a : adj[i]){
		if (a != p){
			dfs3(a, i, ind+1);
		}
	}
}

vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) {
	n = N; int Q = S.size(); vector<int> A(Q);
	for (int i = 0; i < Q; ++i) {
		A[i] = 0;
	}
	for (int i = 0; i < X.size(); i++){
		adj[X[i]].push_back(Y[i]); adj[Y[i]].push_back(X[i]);
	}
	if (N == X.size() + 1 && N > 3000){
		for (int i = 0; i < N; i++){
			if (adj[i].size() == 1){
				dfs3(i, -1, 0); break;
			}
		}
		for (int i = 0; i < Q; i++) {
			cr = R[i], cl = L[i]; int cs = cc[S[i]], ce = cc[E[i]];
			if (S[i] < cl || E[i] > cr){
				continue;
			}
			if (cs < ce){
				int low = cs, high = ce, ub = 0;
				while (true){
					if (low == high){
						ub = low; break;
					}
					if (low+1 == high){
						ub = high;
						if (minv(cs, high) < cl){
							ub = low;
						}
						break;
					}
					int mid = (low + high)/2;
					if (minv(cs, mid) < cl){
						high = mid;
					} else {
						low = mid;
					}
				}
				low = cs, high = ce; int lb = 0;
				while (true){
					if (low == high){
						lb = low; break;
					}
					if (low+1 == high){
						lb = low;
						if (maxv(low, ce) > cr){
							lb = high;
						}
						break;
					}
					int mid = (low + high)/2;
					if (maxv(mid, ce) > cr){
						low = mid;
					} else {
						high = mid;
					}
				}
				if (ub >= lb){
					A[i] = 1;
				}
			} else{
				int low = ce, high = cs, ub = 0;
				while (true){
					if (low == high){
						ub = low; break;
					}
					if (low+1 == high){
						ub = high;
						if (maxv(ce, high) > cr){
							ub = low;
						}
						break;
					}
					int mid = (low + high)/2;
					if (maxv(ce, mid) > cr){
						high = mid;
					} else {
						low = mid;
					}
				}
				low = ce, high = cs; int lb = 0;
				while (true){
					if (low == high){
						lb = low; break;
					}
					if (low+1 == high){
						lb = low;
						if (minv(low, cs) < cl){
							lb = high;
						}
						break;
					}
					int mid = (low + high)/2;
					if (minv(mid, cs) < cl){
						low = mid;
					} else {
						high = mid;
					}
				}
				if (ub >= lb){
					A[i] = 1;
				}
			}
		}
	} else {
		for (int i = 0; i < Q; i++) {
			for (int j = 0; j < N; j++){
				r1[j] = false; r2[j] = false;
			}
			cr = R[i]; cl = L[i];
			dfs1(S[i]); dfs2(E[i]);
			for (int j = L[i]; j <= R[i]; j++){
				if (r1[j] && r2[j]){
					  A[i] = 1; break;
				}
			}
		}
	}
	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:89:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |  for (int i = 0; i < X.size(); i++){
      |                  ~~^~~~~~~~~~
werewolf.cpp:92:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |  if (N == X.size() + 1 && N > 3000){
      |      ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4972 KB Output is correct
3 Correct 5 ms 4972 KB Output is correct
4 Correct 3 ms 4972 KB Output is correct
5 Correct 4 ms 4972 KB Output is correct
6 Correct 4 ms 4972 KB Output is correct
7 Correct 4 ms 4972 KB Output is correct
8 Correct 4 ms 4972 KB Output is correct
9 Correct 4 ms 4972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4972 KB Output is correct
3 Correct 5 ms 4972 KB Output is correct
4 Correct 3 ms 4972 KB Output is correct
5 Correct 4 ms 4972 KB Output is correct
6 Correct 4 ms 4972 KB Output is correct
7 Correct 4 ms 4972 KB Output is correct
8 Correct 4 ms 4972 KB Output is correct
9 Correct 4 ms 4972 KB Output is correct
10 Correct 261 ms 5356 KB Output is correct
11 Correct 149 ms 5228 KB Output is correct
12 Correct 34 ms 5356 KB Output is correct
13 Correct 285 ms 5356 KB Output is correct
14 Correct 189 ms 5228 KB Output is correct
15 Correct 253 ms 5612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3498 ms 53820 KB Output is correct
2 Correct 3726 ms 53868 KB Output is correct
3 Correct 3752 ms 53996 KB Output is correct
4 Correct 3742 ms 53868 KB Output is correct
5 Correct 3724 ms 53996 KB Output is correct
6 Correct 3554 ms 53996 KB Output is correct
7 Correct 3598 ms 53996 KB Output is correct
8 Correct 3502 ms 53868 KB Output is correct
9 Correct 1419 ms 53740 KB Output is correct
10 Correct 1718 ms 53944 KB Output is correct
11 Correct 1996 ms 53912 KB Output is correct
12 Correct 2484 ms 53868 KB Output is correct
13 Correct 3574 ms 53868 KB Output is correct
14 Correct 3592 ms 53816 KB Output is correct
15 Correct 3566 ms 53816 KB Output is correct
16 Correct 3618 ms 53868 KB Output is correct
17 Correct 3634 ms 53856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 4 ms 4972 KB Output is correct
3 Correct 5 ms 4972 KB Output is correct
4 Correct 3 ms 4972 KB Output is correct
5 Correct 4 ms 4972 KB Output is correct
6 Correct 4 ms 4972 KB Output is correct
7 Correct 4 ms 4972 KB Output is correct
8 Correct 4 ms 4972 KB Output is correct
9 Correct 4 ms 4972 KB Output is correct
10 Correct 261 ms 5356 KB Output is correct
11 Correct 149 ms 5228 KB Output is correct
12 Correct 34 ms 5356 KB Output is correct
13 Correct 285 ms 5356 KB Output is correct
14 Correct 189 ms 5228 KB Output is correct
15 Correct 253 ms 5612 KB Output is correct
16 Correct 3498 ms 53820 KB Output is correct
17 Correct 3726 ms 53868 KB Output is correct
18 Correct 3752 ms 53996 KB Output is correct
19 Correct 3742 ms 53868 KB Output is correct
20 Correct 3724 ms 53996 KB Output is correct
21 Correct 3554 ms 53996 KB Output is correct
22 Correct 3598 ms 53996 KB Output is correct
23 Correct 3502 ms 53868 KB Output is correct
24 Correct 1419 ms 53740 KB Output is correct
25 Correct 1718 ms 53944 KB Output is correct
26 Correct 1996 ms 53912 KB Output is correct
27 Correct 2484 ms 53868 KB Output is correct
28 Correct 3574 ms 53868 KB Output is correct
29 Correct 3592 ms 53816 KB Output is correct
30 Correct 3566 ms 53816 KB Output is correct
31 Correct 3618 ms 53868 KB Output is correct
32 Correct 3634 ms 53856 KB Output is correct
33 Incorrect 915 ms 31288 KB Output isn't correct
34 Halted 0 ms 0 KB -