# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
299677 | TMJN | Werewolf (IOI18_werewolf) | C++17 | 564 ms | 29932 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
vector<int>V[200000];
vector<int>A;
int treemin[1<<19],treemax[1<<19],B[200000];
int calcmin(int l,int r){
int a=0xE869120;
l+=(1<<18);
r+=(1<<18);
while(l<=r){
a=min({a,treemin[l],treemin[r]});
l=(l+1)/2;
r=(r-1)/2;
}
return a;
}
int calcmax(int l,int r){
int a=0;
l+=(1<<18);
r+=(1<<18);
while(l<=r){
a=max({a,treemax[l],treemax[r]});
l=(l+1)/2;
r=(r-1)/2;
}
return a;
}
vector<int>check_validity(int N,vector<int>X,vector<int>Y,vector<int>S,vector<int>E,vector<int>L,vector<int>R){
assert(X.size()==N-1);
for(int i=0;i<N-1;i++){
V[X[i]].push_back(Y[i]);
V[Y[i]].push_back(X[i]);
}
for(int i=0;i<N;i++){
assert(V[i].size()<=2);
}
for(int i=0;i<N;i++){
if(V[i].size()==1){
A.push_back(i);
A.push_back(V[i][0]);
while(V[A.back()].size()>=2){
for(int i=0;i<2;i++){
if(V[A.back()][i]!=A[A.size()-2]){
A.push_back(V[A.back()][i]);
break;
}
}
}
break;
}
}
for(int i=0;i<N;i++){
treemin[i+(1<<18)]=treemax[i+(1<<18)]=A[i];
}
for(int i=(1<<18)-1;i;i--){
treemin[i]=min(treemin[i+i],treemin[i+i+1]);
treemax[i]=max(treemax[i+i],treemax[i+i+1]);
}
vector<int>res;
int Q=S.size();
for(int i=0;i<N;i++){
B[A[i]]=i;
}
for(int i=0;i<Q;i++){
S[i]=B[S[i]];
E[i]=B[E[i]];
}
for(int i=0;i<Q;i++){
if(S[i]<E[i]){
int l,r;
l=S[i];
r=E[i]+1;
while(l+1!=r){
int m=(l+r)/2;
if(calcmin(S[i],m)>=L[i]){
l=m;
}
else{
r=m;
}
}
if(calcmax(l,E[i])<=R[i]){
res.push_back(1);
}
else{
res.push_back(0);
}
}
else{
int l,r;
l=E[i];
r=S[i]+1;
while(l+1!=r){
int m=(l+r)/2;
if(calcmax(E[i],m)<=R[i]){
l=m;
}
else{
r=m;
}
}
if(calcmin(l,S[i])>=L[i]){
res.push_back(1);
}
else{
res.push_back(0);
}
}
}
return res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |