| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1350481 | Ghulam_Junaid | Xylophone (JOI18_xylophone) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#include "xylophone.h"
#include "grader.cpp"
using namespace std;
typedef long long ll;
void solve(int N) {
int a[N + 2];
int lo = 1, hi = N, mid;
while (hi - lo > 1) {
mid = (lo + hi) / 2;
if (query(mid, N) == N - 1) lo = mid;
else hi = mid;
}
a[lo] = 1;
bool done[N + 2] = {};
done[1] = 1;
for (int i = lo + 1; i <= N; i ++){
int d = query(i - 1, i);
int x = a[i - 1] + d, y = a[i - 1] - d;
if (x > N or done[x]) a[i] = y;
else if (y <= 0 or done[y]) a[i] = x;
else{
d = query(i - 2, i);
if (a[i - 2] < a[i - 1]){
if (d == x - a[i - 2])
a[i] = x;
else
a[i] = y;
}
else{
if (d == a[i - 2] - y)
a[i] = y;
else
a[i] = x;
}
}
done[a[i]] = 1;
}
for (int i = lo - 1; i > 0; i --){
int d = query(i, i + 1);
int x = a[i + 1] + d, y = a[i + 1] - d;
if (x > N or done[x]) a[i] = y;
else if (y <= 0 or done[y]) a[i] = x;
else{
d = query(i, i + 2);
if (a[i + 2] < a[i + 1]){
if (d == x - a[i + 2])
a[i] = x;
else
a[i] = y;
}
else{
if (d == a[i + 2] - y)
a[i] = y;
else
a[i] = x;
}
}
done[a[i]] = 1;
}
for (int i = 1; i <= N; i++)
answer(i, a[i]);
}