#include "werewolf.h"
//#include "grader.cpp"
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>>edges;
int Log[200001],RMQ[200001][20],MP[200001],RMQ2[200001][20],n;
vector<int>TEMP;
void DFS(int X,int p=-1){
MP[X]=TEMP.size(),TEMP.push_back(X);
for(int i=0;i<edges[X].size();i++){
if(edges[X][i]!=p)
DFS(edges[X][i],X);
}
}
int querymin(int L,int R){
if(L<0||R>=N)
exit(1);
return min(RMQ[L][Log[R-L+1]],RMQ[R-(1<<Log[R-L+1])+1][Log[R-L+1]]);
}
int querymax(int L,int R){
return max(RMQ2[L][Log[R-L+1]],RMQ2[R-(1<<Log[R-L+1])+1][Log[R-L+1]]);
}
bool BS(int S,int E,int L,int R){
int Q=MP[S],QQ=MP[E];
if(Q>QQ)
swap(Q,QQ);
int LL=Q,RR=QQ,mid,BEST=Q;
while(LL<=RR){
mid=(LL+RR)/2;
if(querymax(Q,mid)>=L)
RR=mid-1,BEST=max(mid,BEST);
else
LL=mid+1;
}
if(querymin(BEST,QQ)<=R)return 1;
return 0;
}
vector<int>check_validity(int N,vector<int>X,vector<int>Y,vector<int>S,vector<int>E,vector<int>L,vector<int>R){
Log[1]=0;
n=N;
vector<int>ANS;
edges.resize(N);
for(int i=1;i<=200000;i++)
Log[i]=Log[i/2]+1;
for(int i=0;i<X.size();i++)
edges[X[i]].push_back(Y[i]),edges[Y[i]].push_back(X[i]);
for(int i=0;i<N;i++)
if(edges[i].size()==1){
DFS(i);
break;
}
for(int i=0;i<N;i++)
RMQ[i][0]=TEMP[i],RMQ2[i][0]=TEMP[i];
for(int l=1;l<20;l++){
for(int i=0;i+(1<<l)<=N;i++){
RMQ[i][l]=min(RMQ[i][l-1],RMQ[i+(1<<(l-1))][l-1]);
RMQ2[i][l]=max(RMQ2[i][l-1],RMQ2[i+(1<<(l-1))][l-1]);
}
}
for(int i=0;i<S.size();i++){
ANS.push_back(BS(S[i],E[i],L[i],R[i]));
}
return ANS;
}
Compilation message
werewolf.cpp: In function 'void DFS(int, int)':
werewolf.cpp:10:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for(int i=0;i<edges[X].size();i++){
| ~^~~~~~~~~~~~~~~~
werewolf.cpp: In function 'int querymin(int, int)':
werewolf.cpp:16:12: error: 'N' was not declared in this scope
16 | if(L<0||R>=N)
| ^
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:45:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i=0;i<X.size();i++)
| ~^~~~~~~~~
werewolf.cpp:60:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int i=0;i<S.size();i++){
| ~^~~~~~~~~