# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
680561 | nutella | Xylophone (JOI18_xylophone) | C++17 | 1 ms | 208 KiB |
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>
#include "xylophone.h"
using namespace std;
void solve(int N) {
vector<bool> was(N + 1);
vector<int> A(N);
int lo = -1, hi = N - 1;
while (lo + 1 < hi) {
int mid = lo + hi >> 1;
if (query(1, mid + 1) == N - 1) {
hi = mid;
} else {
lo = mid;
}
}
answer(hi + 1, N);
A[hi] = N;
was[N] = true;
int p = N, pp = -1;
for (int i = hi - 1; i >= 0; --i) {
int diff = query(i + 1, i + 2);
int a;
if (diff + p > N || was[diff + p]) {
a = p - diff;
} else if (p - diff <= 0 || was[p - diff]) {
a = p + diff;
} else {
assert(pp != -1);
int x = query(i + 1, i + 3);
if (x == diff) {
a = pp > p ? p + diff : p - diff;
} else if (x == abs(pp - p)) {
a = p + diff < pp ? p + diff : p - diff;
assert(p < a && a < pp || pp < a && a < p);
} else {
a = pp > p ? pp - x : pp + x;
}
}
A[i] = a;
answer(i + 1, a);
was[a] = true;
pp = p;
p = a;
}
p = N;
pp = -1;
for (int i = hi + 1; i < N; ++i) {
int diff = query(i, i + 1);
int a;
if (diff + p > N || was[diff + p]) {
a = p - diff;
} else if (p - diff <= 0 || was[p - diff]) {
a = p + diff;
} else {
assert(pp != -1);
int x = query(i + 1, i + 3);
if (x == diff) {
a = pp > p ? p + diff : p - diff;
} else if (x == abs(pp - p)) {
a = p + diff < pp ? p + diff : p - diff;
assert(p < a && a < pp || pp < a && a < p);
} else {
a = pp > p ? pp - x : pp + x;
}
}
A[i] = a;
answer(i + 1, a);
was[a] = true;
pp = p;
p = a;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |