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) {
int lo = 1, hi = n;
vector <int> a(n + 1, 0), vis(n + 1, 0);
while (lo < hi) {
int mid = (lo + hi + 1) / 2, val = query(mid, n);
if (val == n - 1)
lo = mid;
else
hi = mid - 1;
}
a[lo] = 1;
vis[1] = 1;
if (lo > 1) {
int val = query(lo - 1, lo);
a[lo - 1] = val + 1;
vis[val + 1] = 1;
for (int i = lo - 2; i > 0; i --) {
val = query(i, i + 1);
vector <int> g;
if (a[i + 1] - val > 0 && !vis[a[i + 1] - val])
g.push_back(a[i + 1] - val);
if (a[i + 1] + val <= n && !vis[a[i + 1] + val])
g.push_back(a[i + 1] + val);
if (g.size() == 1) {
a[i] = g[0];
vis[a[i]] = 1;
}
else {
int val_ = max({g[0], a[i + 1], a[i + 2]}) - min({g[0], a[i + 1], a[i + 2]});
if (val_ == query(i, i + 2)) {
a[i] = g[0];
vis[a[i]] = 1;
}
else {
a[i] = g[1];
vis[a[i]] = 1;
}
}
}
}
int val = query(lo, lo + 1);
a[lo + 1] = val + 1;
vis[val + 1] = 1;
for (int i = lo + 2; i <= n; i ++) {
val = query(i - 1, i);
vector <int> g;
if (a[i - 1] - val > 0 && !vis[a[i - 1] - val])
g.push_back(a[i - 1] - val);
if (a[i - 1] + val <= n && !vis[a[i - 1] + val])
g.push_back(a[i - 1] + val);
if (g.size() == 1) {
a[i] = g[0];
vis[a[i]] = 1;
}
else {
int val_ = max({g[0], a[i - 1], a[i - 2]}) - min({g[0], a[i - 1], a[i - 2]});
if (val_ == query(i - 2, i)) {
a[i] = g[0];
vis[a[i]] = 1;
}
else {
a[i] = g[1];
vis[a[i]] = 1;
}
}
}
for (int i = 1; i <= n; i ++)
answer(i, a[i]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |