#include "werewolf.h"
//#include "grader.cpp"
#include<bits/stdc++.h>
using namespace std;
vector<vector<int>>edges;
int Log[200003],RMQ[2000003][30],MP[200003],RMQ2[200003][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){
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 '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:43:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int i=0;i<X.size();i++)
| ~^~~~~~~~~
werewolf.cpp:58:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int i=0;i<S.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
356 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
356 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
437 ms |
145104 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
356 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |