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 <bits/stdc++.h>
using namespace std;
int a, b;
bool debug = false;
bool grad(vector<int>&v){
return (v[a-1] < v[b-1]);
}
bool ask(vector<int>&v){
cout << "query ";
for(auto &x: v) cout << x << " ";
cout << endl;
bool ret;
if(debug) ret = grad(v);
else cin >> ret;
return ret;
}
void st1(int n){
vector<int>v(n);
for(int i = 0; i < n; i++) cin >> v[i];
sort(v.begin(), v.end());
vector<int>mini(n, 1e9), maxi(n, -1);
do{
if(ask(v)){
if(v < mini) mini = v;
if(v > maxi) maxi = v;
}
} while (next_permutation(v.begin(), v.end()));
cout << "end" << endl;
for(auto &x: mini) cout << x << " ";
cout << endl;
for(auto &x: maxi) cout << x << " ";
cout << endl;
}
void st2(int n){
vector<int>v(n);
for(int i = 0; i < n; i++) cin >> v[i];
sort(v.begin(), v.end());
bool asc = ask(v);
if(!asc) reverse(v.begin(), v.end());
int a = -1, b = -1;
for(int i = 0; i < n; i++){
if(b != -1) break;
for(int j = i + 1; j < n; j++){
swap(v[i], v[j]);
bool tmp = ask(v);
swap(v[i], v[j]);
if(!tmp){
b = j;
break;
}
}
}
for(int i = b - 1; i >= 0; i--){
swap(v[b], v[i]);
bool tmp = ask(v);
swap(v[b], v[i]);
if(!tmp){
a = i;
break;
}
}
cout << "end" << endl;
sort(v.begin(), v.end());
int ans[n];
bool mark[n + 1];
memset(ans, -1, sizeof(ans));
memset(mark, 0, sizeof(mark));
if(!asc){
mark[v[a]] = mark[v[a] + 1] = true;
ans[a] = v[a] + 1;
ans[b] = v[a];
}
int j = 0;
for(int i = 0; i < n; i++){
if(ans[i] != -1) continue;
while(mark[v[j]]) j++;
mark[v[j]] = true;
ans[i] = v[j];
j++;
}
for(auto &x: ans) cout << x << " ";
cout << endl;
sort(v.begin(), v.end(), greater<int>());
memset(ans, -1, sizeof(ans));
memset(mark, 0, sizeof(mark));
if(asc){
mark[v[a]] = mark[v[a] - 1] = true;
ans[a] = v[a] - 1;
ans[b] = v[a];
}
j = 0;
for(int i = 0; i < n; i++){
if(ans[i] != -1) continue;
while(mark[v[j]]) j++;
mark[v[j]] = true;
ans[i] = v[j];
j++;
}
for(auto &x: ans) cout << x << " ";
cout << endl;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n; cin >> n;
if(debug) cin >> a >> b;
if(n <= 6) st1(n);
else st2(n);
return 0;
}
# | 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... |