#include <bits/stdc++.h>
using namespace std;
#include "xylophone.h"
void solve(int n) {
vector<int> a(n + 1), d(n + 1);
for (int i = 1; i < n; ++i) {
d[i] = query(i, i + 1);
}
int min = 1, hi = n;
while (min + 1 < hi) {
int mid = (min + hi) / 2;
if ((mid + 1 < n ? query(mid, n) : d[mid]) == n - 1) min = mid;
else hi = mid;
}
a[min] = 1;
int last = min, sum = 0;
bool increasing = true;
map<int, bool> used;
used[1] = true;
for (int i = min - 1; i > 0; --i) {
int add = d[i];
if (used[a[i + 1] + add] || a[i + 1] - add > n) {
if (increasing) increasing = false, sum = 0;
} else if (used[a[i + 1] - add] || a[i + 1] + add <= 0) {
if (!increasing) increasing = true, sum = 0;
} else {
int diff = (i + 1 < last ? query(i, last) : d[i]);
if (sum + add != diff) {
last = i + 1, sum = 0;
increasing ^= true;
}
}
a[i] = a[i + 1] + (increasing ? add : -add);
used[a[i]] = true;
sum += add;
}
last = min, sum = 0;
increasing = true;
for (int i = min + 1; i <= n; ++i) {
int add = d[i - 1];
if (used[a[i - 1] + add] || a[i - 1] - add > n) {
if (increasing) increasing = false, sum = 0;
} else if (used[a[i - 1] - add] || a[i - 1] + add <= 0) {
if (!increasing) increasing = true, sum = 0;
} else {
int diff = (last + 1 < i ? query(last, i) : d[last]);
if (sum + add != diff) {
last = i - 1, sum = 0;
increasing ^= true;
}
}
a[i] = a[i - 1] + (increasing ? add : -add);
used[a[i]] = true;
sum += add;
}
for (int i = 1; i <= n; ++i) {
cout << a[i] << ' ';
answer(i, a[i]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |