#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 101001
#define M ll(998244353)
#define inf 1e9 + 1e9
using namespace std;
//using namespace __gnu_pbds;
typedef long double ld;
typedef long long ll;
typedef short int si;
typedef array <int, 3> a3;
//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
vector <int> mn, mx, g;
int n, mk[N];
bool gd(vector <int> &g)
{
cout << "query ";
for (auto it : g) cout << it << " "; cout << endl;
bool t;
cin >> t;
return t;
}
bool lower(vector <int> &a, vector <int> &b)
{
for (int i = 0; i < sz(a); i++)
{
if (a[i] == b[i]) continue;
return a[i] < b[i];
}
return 1;
}
void rec(int v)
{
if (v == n)
{
if (gd(g))
{
if (sz(mn) == 0 || lower(g, mn)) mn = g;
if (sz(mx) == 0 || lower(mx, g)) mx = g;
}
return;
}
for (int i = 1; i <= n; i++)
{
if (mk[i]) continue;
mk[i] = 1;
g.pb(i);
rec(v + 1);
g.pop_back();
mk[i] = 0;
}
}
int main()
{
//freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
vector <int> vr(n);
for (int i = 0; i < n; i++) cin >> vr[i];
if (n <= 6)
{
rec(0);
cout << "end" << endl;
for (auto it : mn) cout << it << " "; cout << endl;
for (auto it : mx) cout << it << " "; cout << endl;
exit(0);
}
int l = 0, r = 0;
if (gd(vr))
{
for (int i = 0; i < n && l == 0; i++)
{
vector <int> gr = vr;
for (int j = i + 1; j < n && l == 0; j++)
{
swap(gr[j - 1], gr[j]);
if (gd(gr)) continue;
l = gr[j]; r = gr[j - 1];
}
}
}
else
{
for (int i = 0; i < n && l == 0; i++)
{
vector <int> gr = vr;
for (int j = i + 1; j < n && l == 0; j++)
{
swap(gr[j - 1], gr[j]);
if (!gd(gr)) continue;
l = gr[j - 1]; r = gr[j];
}
}
}
for (int i = 1; i <= n; i++)
{
if (i != l && i != r) {mn.pb(i); continue;}
if (i == r && l < i) {mn.pb(i); continue;}
if (i == l && r > i) {mn.pb(i); continue;}
else if (i == l) {mn.pb(i); mn.pb(r); continue;}
}
for (int i = n; i >= 1; i--)
{
if (i != l && i != r) {mx.pb(i); continue;}
if (i == r && l > i) {mx.pb(i); continue;}
if (i == l && r < i) {mx.pb(i); continue;}
else if (i == l) {mx.pb(i); mx.pb(r); continue;}
}
cout << "end" << endl;
for (auto it : mn) cout << it << " "; cout << endl;
for (auto it : mx) cout << it << " "; cout << endl;
}
Compilation message
zagonetka.cpp: In function 'bool gd(std::vector<int>&)':
zagonetka.cpp:38:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (auto it : g) cout << it << " "; cout << endl;
^~~
zagonetka.cpp:38:42: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for (auto it : g) cout << it << " "; cout << endl;
^~~~
zagonetka.cpp: In function 'int main()':
zagonetka.cpp:107:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (auto it : mn) cout << it << " "; cout << endl;
^~~
zagonetka.cpp:107:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for (auto it : mn) cout << it << " "; cout << endl;
^~~~
zagonetka.cpp:109:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (auto it : mx) cout << it << " "; cout << endl;
^~~
zagonetka.cpp:109:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for (auto it : mx) cout << it << " "; cout << endl;
^~~~
zagonetka.cpp:171:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (auto it : mn) cout << it << " "; cout << endl;
^~~
zagonetka.cpp:171:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for (auto it : mn) cout << it << " "; cout << endl;
^~~~
zagonetka.cpp:173:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (auto it : mx) cout << it << " "; cout << endl;
^~~
zagonetka.cpp:173:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for (auto it : mx) cout << it << " "; cout << endl;
^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
11 ms |
384 KB |
Output is correct |
6 |
Correct |
11 ms |
384 KB |
Output is correct |
7 |
Correct |
13 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |