# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
295758 | eohomegrownapps | Werewolf (IOI18_werewolf) | C++14 | 1833 ms | 48888 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> l;
vector<int> r;
int n,q;
vector<vector<int>> adjlist;
bool comp_l(int a, int b){
return l[a]<l[b];
}
bool comp_r(int a, int b){
return r[a]>r[b];
}
std::vector<int> check_validity(int N, std::vector<int> x, std::vector<int> y,
std::vector<int> s, std::vector<int> e,
std::vector<int> L, std::vector<int> R) {
q = s.size();
l=L;r=R;n=N;
adjlist.resize(n);
for (int i = 0; i<x.size(); i++){
//cout<<x[i]<<' '<<y[i]<<endl;
adjlist[x[i]].push_back(y[i]);
adjlist[y[i]].push_back(x[i]);
}
int start = -1;
for (int i = 0; i<n; i++){
if (adjlist[i].size()==1){
start=i;
break;
}
}
int cur = start;
int pre = -1;
int ptr = 0;
int pop2ind[200005];
int ind2pop[200005];
do {
pop2ind[cur]=ptr;
ind2pop[ptr]=cur;
if (adjlist[cur][0]==pre){
pre=cur;
cur=adjlist[cur][1];
} else {
pre=cur;
cur=adjlist[cur][0];
}
ptr++;
} while (adjlist[cur].size()!=1);
pop2ind[cur]=ptr;
ind2pop[ptr]=cur;
/*for (int i = 0; i<n; i++){
cout<<ind2pop[i]<<' ';
}cout<<'\n';*/
vector<int> intsl(q);
vector<int> intsr(q);
vector<int> intel(q);
vector<int> inter(q);
vector<int> inds(q);
//cout<<"blehhh"<<endl;
for (int i = 0; i<q; i++){
inds[i]=i;
}
//cout<<"blehhh"<<endl;
/*for (int i : l){
cout<<i<<' ';
}cout<<endl;
for (int i : r){
cout<<i<<' ';
}cout<<endl;*/
sort(inds.begin(), inds.end(), comp_l);
//cout<<"blehhh"<<endl;
int prevl = 0;
set<int> lpoints;
lpoints.insert(-1);
lpoints.insert(n);
for (int i = 0; i<q; i++){
cout<<i<<endl;
while (prevl<l[inds[i]]){
lpoints.insert(pop2ind[prevl]);
prevl++;
}
auto lb = lpoints.lower_bound(pop2ind[s[inds[i]]]);
intsl[inds[i]]=*(prev(lb))+1;
intsr[inds[i]]=*lb-1;
}
sort(inds.begin(), inds.end(), comp_r);
int prevr = n-1;
set<int> rpoints;
rpoints.insert(-1);
rpoints.insert(n);
for (int i = 0; i<q; i++){
cout<<i<<endl;
while (prevr>r[inds[i]]){
rpoints.insert(pop2ind[prevr]);
prevr--;
}
auto lb = rpoints.lower_bound(pop2ind[e[inds[i]]]);
intel[inds[i]]=*(prev(lb))+1;
inter[inds[i]]=*lb-1;
}
vector<int> ans(q);
for (int i = 0; i<q; i++){
//cout<<"human: "<<intsl[i]<<' '<<intsr[i]<<'\n';
//cout<<"werewolf: "<<intel[i]<<' '<<inter[i]<<'\n';
if (!(inter[i]<intsl[i]||intsr[i]<intel[i])){
ans[i]=1;
} else {
ans[i]=0;
}
}
return ans;
}
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... |