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 "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
bool Check(int a, int b, int c, int i) {
if (a == b || b == c || a == c) {return false;}
if (a > b && b > c) {
return query(i + 1, i + 3) == a - c;
}
if (a > c && c > b) {
return query(i + 1, i + 3) == a - b;
}
if (c > a && a > b) {
return query(i + 1, i + 3) == c - b;
}
if (c > b && b > a) {
return query(i + 1, i + 3) == c - a;
}
if (b > a && a > c) {
return query(i + 1, i + 3) == b - c;
}
if (b > c && c > a) {
return query(i + 1, i + 3) == b - a;
}
}
int GetRight(int n, int a, int b, int x, int i) {
int c1 = b + x, c2 = b - x;
if (c1 > n) {return c2;}
if (c2 < 1) {return c1;}
if (Check(a, b, c1, i)) {
return c1;
}
return c2;
}
int GetLeft(int n, int a, int b, int x, int i) {
int c1 = a + x, c2 = a - x;
if (c1 > n) {return c2;}
if (c2 < 1) {return c1;}
if (Check(c1, a, b, i)) {
return c1;
}
return c2;
}
void solve(int n) {
int pos = n - 1;
int l = 0, r = n;
while (r - l > 1) {
int m = l + (r - l) / 2;
if (query(1, m) == n - 1) {
r = m;
} else {
l = m;
}
}
pos = l;
vector <int> num(n);
num[pos] = n;
if (pos + 1 < n) {
int x = query(pos + 1, pos + 2);
num[pos + 1] = n - x;
}
vector <vector<int>> cand1(n), cand2(n);
for (int i = pos + 2; i < n; ++i) {
int x = query(i, i + 1);
num[i] = GetRight(n, num[i - 2], num[i - 1], x, i - 2);
}
if (pos != 0) {
int x = query(pos, pos + 1);
num[pos - 1] = n - x;
}
for (int i = pos - 2; i >= 0; --i) {
int x = query(i + 1, i + 2);
num[i] = GetLeft(n, num[i + 1], num[i + 2], x, i);
}
for(int i = 0; i < n; ++i) {
answer(i + 1, num[i]);
}
}
Compilation message (stderr)
xylophone.cpp: In function 'bool Check(int, int, int, int)':
xylophone.cpp:26:1: warning: control reaches end of non-void function [-Wreturn-type]
26 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |