| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1290649 | hasandas | Xylophone (JOI18_xylophone) | C++20 | 0 ms | 0 KiB |
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
void solve(long long N) {
vector<long long> ans(N + 1, 0);
long long LJ = 1, HJ = N;
while (LJ < HJ) {
long long mid = (LJ + HJ + 1) / 2;
long long q = query(mid, N);
if (q == N - 1) {
LJ = mid;
}
else {
HJ = mid - 1;
}
}
long long pos1 = LJ;
ans[pos1] = 1;
long long current_max = 1;
long long idx_max = pos1;
for (long long i = pos1 + 1; i <= N; ++i) {
long long q = query(pos1, i);
if (q > current_max - 1) {
ans[i] = q + 1;
current_max = ans[i];
idx_max = i;
}
else {
long long s = min(idx_max, i);
long long t = max(idx_max, i);
long long d = query(s, t);
ans[i] = current_max - d;
}
}
current_max = 1;
idx_max = pos1;
for (long long i = pos1 - 1; i >= 1; --i) {
long long q = query(i, pos1);
if (q > current_max - 1) {
ans[i] = q + 1;
current_max = ans[i];
idx_max = i;
}
else {
long long s = min(idx_max, i);
long long t = max(idx_max, i);
long long d = query(s, t);
ans[i] = current_max - d;
}
}
for (long long i = 1; i <= N; ++i) {
answer(i, ans[i]);
}
}
