#include "library.h"
#include <bits/stdc++.h>
using namespace std;
void Solve(int N) {
if (N == 1) {
Answer({1});
return;
}
if (N == 2) {
Answer({1, 2});
return;
}
vector<int> cc[N];
for (int i = 0; i < N; i++) {
cc[i].resize(N);
iota(cc[i].begin(), cc[i].end(), 0);
cc[i].erase(find(cc[i].begin(), cc[i].end(), i));
}
int ae[N], s = -1, q_cnt = N;
for (int i = 0; i < N; i++) {
vector<int> vec(N, 1);
vec[i] = 0;
ae[i] = Query(vec) < 2;
s = ae[i] ? s : i;
}
vector<int> adj[N];
auto findBest = [&](int i) {
int lo = 0, hi = cc[i].size()-1;
while (lo < hi) {
int mid = lo + hi >> 1;
vector<int> vec(N);
for (int j = 0; j <= mid; j++) {
vec[cc[i][j]] = 1;
}
if (++q_cnt > 20000) return;
int q = Query(vec);
vec[i] = 1;
if (++q_cnt > 20000) return;
q - Query(vec) < 0 ? lo = mid + 1 : hi = mid;
}
if (lo == cc[i].size()) return -1;
int j = cc[i][lo];
adj[i].push_back(j);
adj[j].push_back(i);
cc[j].erase(find(cc[j].begin(), cc[j].end(), i));
cc[i].erase(find(cc[i].begin(), cc[i].end(), j));
return j;
};
for (int cur = s; cur >= 0 && !ae[cur]; cur = findBest(cur));
for (int cur = s; cur >= 0 && !ae[cur]; cur = findBest(cur));
for (int i = 0; i < N; i++) {
if (adj[i].size() < 2) {
vector<int> ans(N);
ans[0] = i;
for (int j = 1, x = adj[i][0]; j < N; j++) {
ans[j] = x;
for (int k : adj[x]) {
x = k == ans[j-1] ? x : k;
}
}
for (int &j : ans) {
j++;
}
Answer(ans);
return;
}
}
}
Compilation message
library.cpp: In lambda function:
library.cpp:34:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | int mid = lo + hi >> 1;
| ~~~^~~~
library.cpp:45:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | if (lo == cc[i].size()) return -1;
| ~~~^~~~~~~~~~~~~~~
library.cpp:45:34: error: inconsistent types 'void' and 'int' deduced for lambda return type
45 | if (lo == cc[i].size()) return -1;
| ^~
library.cpp:45:34: error: return-statement with a value, in function returning 'void' [-fpermissive]
library.cpp:51:10: error: inconsistent types 'void' and 'int' deduced for lambda return type
51 | return j;
| ^
library.cpp:51:10: error: return-statement with a value, in function returning 'void' [-fpermissive]
library.cpp: In function 'void Solve(int)':
library.cpp:53:56: error: void value not ignored as it ought to be
53 | for (int cur = s; cur >= 0 && !ae[cur]; cur = findBest(cur));
| ~~~~~~~~^~~~~
library.cpp:54:56: error: void value not ignored as it ought to be
54 | for (int cur = s; cur >= 0 && !ae[cur]; cur = findBest(cur));
| ~~~~~~~~^~~~~