Submission #817313

# Submission time Handle Problem Language Result Execution time Memory
817313 2023-08-09T11:26:37 Z Dan4Life Werewolf (IOI18_werewolf) C++17
0 / 100
1792 ms 524288 KB
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
using vi = vector<int>;
const int mxN = (int)2e5+10;
int n, m, q;
vi adj[mxN], a;
int pos[mxN], mnSeg[mxN*2], mxSeg[mxN*2];

void upd(int x, int v, int seg[], bool t, int p=0, int l=0, int r=n-1){
	if(l==r){ seg[p] = v; return; }
	int mid = (l+r)>>1; int rp = p+2*(mid-l+1);
	if(x<=mid) upd(x,v,seg,t,p+1,l,mid);
	else upd(x,v,seg,t,rp,mid+1,r);
	if(t) seg[p] = max(seg[p+1],seg[rp]);
	else seg[p] = min(seg[p+1],seg[rp]);
}
 
int rmq(int i, int j, int seg[], bool t, int p=0, int l=0, int r=n-1){
	if(i>r or j<l or i>j) return t?0:mxN;
	if(i<=l and r<=j) return seg[p];
	int mid = (l+r)>>1; int rp = p+2*(mid-l+1);
	int le = t?0:mxN; int ri = le;
	if(i<=mid) le = rmq(i,j,seg,t,p+1,l,mid);
	if(j>mid) ri = rmq(i,j,seg,t,rp,mid+1,r);
	if(t) return max(le,ri);
	return min(le,ri);
}

void dfs(int s, int p){
	a.pb(s);
	for(auto u : adj[s])
		if(u!=p) dfs(u,s);
}

vi check_validity(int N, vi U, vi V, vi S, vi T, vi L, vi R) {
	n = N, m = sz(U), q = sz(S); vi ans(q, 0);
	for(int i = 0; i < m; i++){
		int a = U[i], b = V[i];
		adj[a].pb(b); adj[b].pb(a);
	}
	for(int i = 0; i < n; i++){
		if(sz(adj[i])==1){
			dfs(i,-1); break;
		}
	}
	for(int i = 0; i < n; i++) 
		upd(i,a[i],mnSeg,0), upd(i,a[i],mxSeg,1),pos[a[i]]=i;
	for(int i = 0; i < q; i++){
		int s = pos[S[i]], t = pos[T[i]];
		if(s<t){
			int l = s, r = t;
			while(l<r){
				int mid = (l+r+1)/2;
				if(rmq(s,mid,mnSeg,0)>=L[i]) l=mid;
				else r=mid-1;
			}
			int x = l;
			l = s, r = t;
			while(l<r){
				int mid = (l+r)/2;
				if(rmq(mid,t,mxSeg,1)<=R[i]) r=mid;
				else l=mid+1;
			}
			ans[i] = x>=l;
		}
		else{
			swap(s,t);
			int l = s, r = t;
			while(l<r){
				int mid = (l+r+1)/2;
				if(rmq(s,mid,mnSeg,0)<=R[i]) l=mid;
				else r=mid-1;
			}
			int x = l;
			l = s, r = t;
			while(l<r){
				int mid = (l+r)/2;
				if(rmq(mid,t,mxSeg,1)>=L[i]) r=mid;
				else l=mid+1;
			}
			ans[i] = x>=l;
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 284 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 284 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1792 ms 44088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 284 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -