답안 #465391

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
465391 2021-08-15T20:08:05 Z dutch 늑대인간 (IOI18_werewolf) C++17
0 / 100
451 ms 29332 KB
#include <bits/stdc++.h>
using namespace std;
#include "werewolf.h"
typedef vector<int> vi;
#define vii(Z) iota(begin(Z), end(Z), 0)
#define sortBy(X, Y) sort(begin(X), end(X), [&](int &u, int &v){ return Y[u] < Y[v]; });

const int NL = 2e5, ML = 6e5;
 
int N, M, Q, k, dfsTimer;
int e[NL], r[NL], lca[2][NL], st[2*NL], tL[2][ML], tR[2][ML], a[2][2*NL];
array<int, 2> g[ML];
 
int find(int u){
	return e[u] < 0 ? u : e[u] = find(e[u]);
}
 
void dfs(int u){
	if(u < N){
		tL[k][u] = ++dfsTimer;
	}else{
		tL[k][u] = 1+dfsTimer;
		auto &[vL, vR] = g[u-N];
		dfs(vL);
		if(vL != vR) dfs(vR);	
	}
	tR[k][u] = dfsTimer;
}
 
vi check_validity(int __N, vi X, vi Y, vi S, vi E, vi L, vi R){
	N = __N, Q = size(S), M = size(X);
	for(int i=0; i<M; ++i){
		if(X[i] > Y[i]) swap(X[i], Y[i]);
		a[0][i] =  max(X[i], Y[i]);
		a[1][i] = -min(X[i], Y[i]);
		X[i] = -X[i];
	}

	vi h(M); vii(h);
	vi byLim(Q); vii(byLim);

	for(int &i : R) i = -i;
 
	for(; k<2; ++k){
		iota(r, r+N, 0);
		fill(e, e+N,-1);
		sortBy(h, a[k]);
		sortBy(byLim, R);
		int p = Q - 1;
 
		for(int &i : h){
			int u = find(-X[i]), v = find(Y[i]);

			while(p >= 0 && R[byLim[p]] > -a[k][i])
				lca[k][byLim[p]] = r[find(E[byLim[p]])], --p;
 
			if(e[u] > e[v]) swap(u, v);
			g[i] = {r[u], r[v]};
			if(u != v){
				e[u] += e[v];
				e[v] = u;
			}
			r[u] = i+N;
		}
		swap(L, R), swap(S, E);

		for(int i=0; i<=p; ++i)
			lca[k][byLim[i]] = h.back() + N;
 
		dfsTimer = -1;
		dfs(h.back()+N);
	}
 
	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 p = 0;
	vii(byL);
	sortBy(byL, tL[0]);
	sort(rbegin(q), rend(q));
 
	fill(st, st+N+N, ML);
	for(auto &[lx, rx, id] : q){
		while(p < N && tL[0][byL[p]] >= lx){
			int i = tL[1][byL[p]];
			for(st[i+=N]=tL[0][byL[p]]; i/=2; )
				st[i] = min(st[2*i], st[2*i+1]);
			++p;
		}
		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 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 451 ms 29332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -