#include "werewolf.h"
#include<bits/stdc++.h>
#define lcm(a,b) (a/__gcd(a,b))*b
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define F first
#define S second
#define mp make_pair
using namespace std;
const int MA=200000;
vi G[MA];
vi res,v;
int pos[MA];
int cant[MA]={0};
pair<int,int>T[4*MA];
int A1,A2,B1,B2,n;
void dfs(int nodo, int ant, int p){
pos[nodo]=p;
v.pb(nodo);
for(auto it : G[nodo]){
if(it!=ant){
dfs(it,nodo,p+1);
}
}
}
void init(int nodo, int b, int e){
int L=2*nodo+1,R=L+1,mid=(b+e)/2;
if(b==e){
T[nodo]={v[b],v[e]};
return;
}
init(L,b,mid);init(R,mid+1,e);
T[nodo].F=min(T[L].F,T[R].F);
T[nodo].S=max(T[L].S,T[R].S);
}
int menor(int nodo, int b, int e, int izq, int der, int num){
int L=2*nodo+1,R=L+1,mid=(b+e)/2;
if(b==e){
if(v[b]<num)return -1;
return b;
}
if(b>=izq && e<=der){
if(T[L].F<num)return menor(L,b,mid,izq,der,num);
return menor(R,mid+1,e,izq,der,num);
}
if(der<=mid)return menor(L,b,mid,izq,der,num);
if(izq>mid)return menor(R,mid+1,e,izq,der,num);
return max(menor(L,b,mid,izq,der,num),menor(R,mid+1,e,izq,der,num));
}
int mayor(int nodo, int b, int e, int izq, int der, int num){
int L=2*nodo+1,R=L+1,mid=(b+e)/2;
if(b==e){
if(v[b]>num)return -1;
return b;
}
if(b>=izq && e<=der){
if(T[L].S>num)return mayor(L,b,mid,izq,der,num);
return mayor(R,mid+1,e,izq,der,num);
}
if(der<=mid)return mayor(L,b,mid,izq,der,num);
if(izq>mid)return mayor(R,mid+1,e,izq,der,num);
return max(mayor(L,b,mid,izq,der,num),mayor(R,mid+1,izq,e,der,num));
}
int menorl(int nodo, int b, int e, int izq, int der, int num){
int L=2*nodo+1,R=L+1,mid=(b+e)/2;
if(b==e){
if(v[b]<num)return MA;
return b;
}
if(b>=izq && e<=der){
if(T[L].S<num)return menorl(R,mid+1,e,izq,der,num);
return menorl(L,b,mid,izq,der,num);
}
if(der<=mid)return menorl(L,b,mid,izq,der,num);
if(izq>=mid+1)return menorl(R,mid+1,e,izq,der,num);
return min(menorl(R,mid+1,e,izq,der,num),menorl(L,b,mid,izq,der,num));
}
int mayorl(int nodo, int b, int e, int izq, int der, int num){
int L=2*nodo+1,R=L+1,mid=(b+e)/2;
if(b==e){
if(v[b]>num)return MA;
return b;
}
if(b>=izq && e<=der){
if(T[R].S>num)return mayorl(R,mid+1,e,izq,der,num);
return mayorl(L,b,mid,izq,der,num);
}
if(der<=mid)return mayorl(L,b,mid,izq,der,num);
if(izq>=mid+1)return mayorl(R,mid+1,e,izq,der,num);
return min(mayorl(L,b,mid,izq,der,num),mayorl(R,mid+1,e,izq,der,num));
}
vi check_validity(int N,vi X,vi Y,vi S,vi E,vi L,vi R) {
n=N;
for(int i=0;i<X.size();i++){
G[X[i]].pb(Y[i]);
G[Y[i]].pb(X[i]);
cant[X[i]]++;cant[Y[i]]++;
}
for(int i=0;i<n;i++){
if(cant[i]==1){
dfs(i,-1,0);
break;
}
}
init(0,0,n-1);
for(int i=0;i<S.size();i++){
if(S[i]<L[i] or E[i]>R[i]){
res.pb(0);continue;
}
if(pos[S[i]]<=pos[R[i]]){
A2=menor(0,0,n-1,pos[S[i]],n-1,L[i]);
B1=mayorl(0,0,n-1,pos[E[i]],n-1,R[i]);
res.pb(!(A2<B1));
}else{
A1=menorl(0,0,n-1,pos[S[i]],n-1,L[i]);
B2=mayor(0,0,n-1,pos[E[i]],n-1,R[i]);
res.pb(!(B2<A1));
}
}
return res;
}
/*
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
*/
/*
5 4 3
0 1
1 2
2 3
3 4
1 3 2 4
0 3 0 4
3 4 2 2
*/
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:98:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
98 | for(int i=0;i<X.size();i++){
| ~^~~~~~~~~
werewolf.cpp:110:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
110 | for(int i=0;i<S.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
359 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
359 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4088 ms |
39904 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
359 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |