#include <bits/stdc++.h>
#ifndef LOCAL
#include "library.h"
#else
#include <vector>
int Query(const std::vector<int>& M);
void Answer(const std::vector<int>& res);
#endif
void Solve(int N) {
std::vector<int> dp(N + 1, -1);
auto get_pref = [&](int x) {
if (dp[x] != -1) return dp[x];
std::vector<int> a(N);
for (int i = 0; i < x; i++) {
a[i] = 1;
}
return Query(a);
};
auto get_pref_more = [&](int x, int y) {
std::vector<int> a(N);
a[y - 1] = 1;
for (int i = 0; i < x; i++) {
a[i] = 1;
}
return Query(a);
};
auto get_pref_more_not = [&](int x, int y, int z) {
std::vector<int> a(N);
a[y - 1] = 1;
for (int i = 0; i < x; i++) {
a[i] = 1;
}
a[z] = 0;
return Query(a);
};
std::vector<std::vector<int>> adj(N + 1);
dp[1] = 1;
for (int i = 2; i <= N; i++) {
if (get_pref(i) - get_pref(i - 1) == 1) {
continue;
}
if (get_pref(i) - get_pref(i - 1) == 0) {
int lb = 1, rb = i - 1;
while (lb < rb) {
int mid = (lb + rb) / 2;
int bef = get_pref(mid);
int aft = get_pref_more(mid, i);
if (aft - bef == 0) {
rb = mid;
} else {
lb = mid + 1;
}
}
adj[rb].push_back(i);
adj[i].push_back(rb);
continue;
}
assert(get_pref(i) - get_pref(i - 1) == -1);
int lb = 1, rb = i - 1;
while (lb < rb) {
int mid = (lb + rb) / 2;
int bef = get_pref(mid);
int aft = get_pref_more(mid, i);
if (aft - bef == -1) { // now we can be sure
rb = mid;
} else {
lb = mid + 1;
}
}
int z = rb;
adj[z].push_back(i);
adj[i].push_back(z);
lb = 1, rb = z - 1; // z - 1
while (lb < rb) {
int mid = (lb + rb) / 2;
int bef = get_pref(mid);
int aft = get_pref_more(mid, i);
if (aft - bef == 0) {
rb = mid;
} else {
lb = mid + 1;
}
}
adj[rb].push_back(i);
adj[i].push_back(rb);
}
std::vector<int> res;
std::function<void(int, int)> dfs = [&](int u, int p) {
res.push_back(u);
for (int v : adj[u]) {
if (v == p) continue;
dfs(v, u);
}
};
for (int i = 1; i <= N; i++) {
if ((int) adj[i].size() == 1) {
dfs(i, i);
break;
}
}
Answer(res);
}
Compilation message
library.cpp: In function 'void Solve(int)':
library.cpp:33:8: warning: variable 'get_pref_more_not' set but not used [-Wunused-but-set-variable]
33 | auto get_pref_more_not = [&](int x, int y, int z) {
| ^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
672 KB |
# of queries: 3283 |
2 |
Correct |
25 ms |
440 KB |
# of queries: 3303 |
3 |
Correct |
29 ms |
440 KB |
# of queries: 3469 |
4 |
Correct |
30 ms |
440 KB |
# of queries: 3461 |
5 |
Correct |
23 ms |
440 KB |
# of queries: 3465 |
6 |
Correct |
31 ms |
432 KB |
# of queries: 3447 |
7 |
Correct |
24 ms |
436 KB |
# of queries: 3475 |
8 |
Correct |
30 ms |
696 KB |
# of queries: 3327 |
9 |
Correct |
24 ms |
440 KB |
# of queries: 3479 |
10 |
Correct |
14 ms |
696 KB |
# of queries: 2057 |
11 |
Incorrect |
0 ms |
340 KB |
Wrong Answer [4] |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
672 KB |
# of queries: 3283 |
2 |
Correct |
25 ms |
440 KB |
# of queries: 3303 |
3 |
Correct |
29 ms |
440 KB |
# of queries: 3469 |
4 |
Correct |
30 ms |
440 KB |
# of queries: 3461 |
5 |
Correct |
23 ms |
440 KB |
# of queries: 3465 |
6 |
Correct |
31 ms |
432 KB |
# of queries: 3447 |
7 |
Correct |
24 ms |
436 KB |
# of queries: 3475 |
8 |
Correct |
30 ms |
696 KB |
# of queries: 3327 |
9 |
Correct |
24 ms |
440 KB |
# of queries: 3479 |
10 |
Correct |
14 ms |
696 KB |
# of queries: 2057 |
11 |
Incorrect |
0 ms |
340 KB |
Wrong Answer [4] |
12 |
Halted |
0 ms |
0 KB |
- |