답안 #412155

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
412155 2021-05-26T15:00:12 Z Ahmadsm2005 늑대인간 (IOI18_werewolf) C++14
0 / 100
387 ms 524292 KB
#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];
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(R<L)
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){
if(R<L)
exit(1);
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=LL;
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;
vector<int>ANS;
edges.resize(N);
for(int i=1;i<N;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:46:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 | for(int i=0;i<X.size();i++)
      |             ~^~~~~~~~~
werewolf.cpp:61:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 | for(int i=0;i<S.size();i++){
      |             ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 387 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 387 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 379 ms 129184 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 387 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -