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>
#define ll long long
#define fi first
#define se second
using namespace std;
int main() {
int n, ans;
vector<int> p;
cin >> n;
p.resize(n+1);
for(int i=1; i<=n; i++) {
cin >> p[i];
}
vector<int>small,big,v;
for(int i=1; i<=n; i++) v.push_back(i);
if(n <= 6) {
cout << "query ";
for(int i=0; i<v.size(); i++) {
cout << v[i] << " ";
}
cout << endl;
cin >> ans;
if(ans==1) {
if(small.empty()) {
small = v;
} else {
small = min(small, v);
}
if(big.empty()) {
big = v;
} else {
big = max(big, v);
}
}
while(next_permutation(v.begin(), v.end())) {
cout << "query ";
for(int i=0; i<v.size(); i++) {
cout << v[i] << " ";
}
cout << endl;
cin >> ans;
if(ans==1) {
if(small.empty()) {
small = v;
} else {
small = min(small, v);
}
if(big.empty()) {
big = v;
} else {
big = max(big, v);
}
}
}
cout << "end" << endl;
for(int i=0; i<small.size(); i++) cout << small[i] << " ";
cout << endl;
for(int i=0; i<big.size(); i++) cout << big[i] << " ";
cout << endl;
return 0;
}
pair<int,int>pil;
pil.fi = -1;
pil.se = -1;
int ag[1001];
int id;
for(int i=2; i<=n-2; i++) {
cout << "query ";
swap(p[i], p[i+1]);
for(int j=1; j<=n; j++) {
cout << p[j] << " ";
}
cout << endl;
cin >> ans;
if(ans==0) {
swap(p[i], p[i+1]);
cout << "query ";
id = i-1;
if(id-1 >= 1) {
swap(p[id], p[id-1]);
for(int j=1; j<=n; j++) {
cout << p[j] << " ";
}
cout << endl;
cin >> ans;
if(ans==1) {
swap(p[id], p[id-1]);
pil.fi = p[id+2];
pil.se = p[id+3];
p.erase(p.begin()+id+2, p.begin()+id+4);
//for (auto it:p) cout << it << " ";
} else {
swap(p[id], p[id-1]);
pil.fi = p[id];
pil.se = p[id+1];
p.erase(p.begin()+id, p.begin()+id+2);
//for (auto it:p) cout << it << " ";
}
} else
if(id+4 <= n) {
swap(p[id+3], p[id+4]);
for(int j=1; j<=n; j++) {
cout << p[j] << " ";
}
cout << endl;
cin >> ans;
if(ans==1) {
swap(p[id+3], p[id+4]);
pil.fi = p[id];
pil.se = p[id+1];
p.erase(p.begin()+id, p.begin()+id+2);
//for (auto it:p) cout << it << " ";
} else {
swap(p[id+3], p[id+4]);
pil.fi = p[id+2];
pil.se = p[id+3];
p.erase(p.begin()+id+2, p.begin()+id+4);
//for (auto it:p) cout << it << " ";
}
}
break;
}
swap(p[i], p[i+1]);
}
for(int i=1; i<=id; i++) {
if(ag[i] == 0) {
}
}
sort(p.begin(), p.end());
//debug
cout << "pas " << pil.fi << " " << pil.se << endl;
int mins = min(pil.fi, pil.se);
int maks = max(pil.fi, pil.se);
if(mins < p[1] || maks > p[p.size()-1]) {
cout << "masuk sini" << endl;
cout << "end" << endl;
cout << mins << " " << maks << " ";
for(int i=1; i<=p.size()-1; i++) {
cout << p[i] << " ";
}
cout << endl;
for(int i=p.size()-1; i>=1; i--) {
cout << p[i] << " ";
}
cout << maks << " " << mins << " ";
cout << endl;
return 0;
}
for(int i=1; i<=n; i++) {
if(p[i]==mins-1) {
p.insert(p.begin()+i+1, {mins, maks});
break;
}
}
for (auto it:p) cout << it << " ";
cout << "end" << endl;
for(int i=1; i<=n; i++) {
cout << p[i] << " ";
}
cout << endl;
for(int i=n; i>=1; i--) {
cout << p[i] << " ";
}
cout << endl;
return 0;
}
Compilation message (stderr)
zagonetka.cpp: In function 'int main()':
zagonetka.cpp:19:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for(int i=0; i<v.size(); i++) {
| ~^~~~~~~~~
zagonetka.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i=0; i<v.size(); i++) {
| ~^~~~~~~~~
zagonetka.cpp:57:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int i=0; i<small.size(); i++) cout << small[i] << " ";
| ~^~~~~~~~~~~~~
zagonetka.cpp:59:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int i=0; i<big.size(); i++) cout << big[i] << " ";
| ~^~~~~~~~~~~
zagonetka.cpp:139:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
139 | for(int i=1; i<=p.size()-1; i++) {
| ~^~~~~~~~~~~~
# | 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... |