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 "library.h"
#include <bits/stdc++.h>
using namespace std;
vector <int> p, f;
vector <int> Left, Right;
inline int exists(int st, int dr){
for(int i = st; i <= dr ; ++i) f[p[i]] = 1;
int val = Query(f);
for(auto it : Left) f[it] = 1;
for(auto it : Right) f[it] = 1;
int val2 = Query(f);
for(auto it : Left) f[it] = 0;
for(auto it : Right) f[it] = 0;
for(int i = st; i <= dr ; ++i) f[p[i]] = 0;
int dif = val2 - val;
if(dif <= 1) return 1;
return 0;
}
inline int find_value(int st, int dr){
if(st == dr) return p[st];
int mij = (st + dr) / 2;
if(exists(st, mij)) return find_value(st, mij);
else return find_value(mij + 1, dr);
}
inline bool belongs(vector <int> v, int val, int n){
vector <int> f(n);
for(int i = 0; i < n ; ++i) f[i] = 0;
for(auto it : v) f[it] = 1;
f[val] = 1;
int x = Query(f);
if(x == 1) return 1;
return 0;
}
void Solve(int n){
if(n == 1){
vector <int> ans;
ans.push_back(1);
Answer(ans);
return ;
}
for(int i = 0; i < n ; i++) p.push_back(i), f.push_back(1);
for(int i = 0; i < n ; ++i){
f[i] = 0;
if(Query(f) == 1){
if(Left.empty()) Left.push_back(i);
else Right.push_back(i);
p.erase(find(p.begin(), p.end(), i));
}
f[i] = 1;
}
for(int i = 0; i < n ; ++i) f[i] = 0;
while(!p.empty()){
int val = find_value(0, p.size() - 1);
if(belongs(Left, val, n)) Left.push_back(val);
else Right.push_back(val);
p.erase(find(p.begin(), p.end(), val));
}
vector <int> ans;
for(auto it : Left) ans.push_back(it + 1);
reverse(Right.begin(), Right.end());
for(auto it : Right) ans.push_back(it + 1);
Answer(ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |