# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
295435 | eohomegrownapps | Werewolf (IOI18_werewolf) | C++14 | 1743 ms | 30968 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;
int sqrtn;
vector<vector<int>> adjlist;
bool comp(int a, int b){
if (l[a]/sqrtn == l[b]/sqrtn){
return r[a]<r[b];
} else {
return l[a]<l[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;
sqrtn=sqrt(n);
vector<int> inds(q);
for (int i = 0; i<q; i++){
inds[i]=i;
}
sort(inds.begin(),inds.end(),comp);
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;
vector<int> ind2pop(n);
vector<int> pop2ind(n);
do {
ind2pop[ptr]=cur;
ind2pop[cur]=ptr;
if (adjlist[cur][0]==pre){
pre=cur;
cur=adjlist[cur][1];
} else {
pre=cur;
cur=adjlist[cur][0];
}
ptr++;
} while (adjlist[cur].size()!=1);
vector<int> ans(q);
int lv = 0;
int rv = 0;
set<int> lvals;
set<int> rvals;
for (int i = 1; i<n; i++){
rvals.insert(pop2ind[i]);
}
lvals.insert(-1);
lvals.insert(n);
rvals.insert(-1);
rvals.insert(n);
for (int i = 0; i<q; i++){
while (lv!=l[inds[i]]){
if (lv<l[inds[i]]){
lvals.insert(pop2ind[lv]);
lv++;
} else {
lvals.erase(pop2ind[lv]);
lv--;
}
}
while (rv!=r[inds[i]]){
if (rv<r[inds[i]]){
rvals.insert(pop2ind[rv]);
rv++;
} else {
rvals.erase(pop2ind[rv]);
rv--;
}
}
int ls = *(prev(lvals.lower_bound(s[inds[i]]),1));
int le = *(lvals.lower_bound(s[inds[i]]));
int rs = *(prev(rvals.lower_bound(e[inds[i]]),1));
int re = *(rvals.lower_bound(e[inds[i]]));
if (le<rs||re<ls){
ans[i]=0;
} else {
ans[i]=1;
}
}
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... |