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>
int ask(int l, int r) {
return query(l + 1, r + 1);
}
void solve(int N) {
std::vector<int> ans(N);
ans[0] = 0;
ans[1] = ask(0, 1);
for (int i = 2; i < N; ++i) {
int v1 = ask(i - 2, i), v2 = ask(i - 1, i);
if (ans[i - 2] < ans[i - 1]) {
if (v1 == ans[i - 1] - ans[i - 2]) {
ans[i] = ans[i - 1] - v2;
} else if (v1 == v2) {
ans[i] = ans[i - 1] - v2;
} else {
ans[i] = ans[i - 1] + v2;
}
} else {
if (v1 == ans[i - 2] - ans[i - 1]) {
ans[i] = ans[i - 1] + v2;
} else if (v1 == v2) {
ans[i] = ans[i - 1] + v2;
} else {
ans[i] = ans[i - 1] - v2;
}
}
}
int minId = (int)(std::min_element(ans.begin(), ans.end()) - ans.begin());
int maxId = (int)(std::max_element(ans.begin(), ans.end()) - ans.begin());
if (minId > maxId) {
for (auto &e : ans) e = -e;
std::swap(minId, maxId);
}
const int v = ans[minId];
for (auto &e : ans) e -= v;
for (int i = 0; i < N; ++i) {
answer(i + 1, ans[i] + 1);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |