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>
using namespace std;
#include "xylophone.h"
void solve(int n) {
vector<int> a(n + 1);
int min = 1, max = n;
int lo = 1, hi = n;
while (lo + 1 < hi) {
int mid = (lo + hi) / 2;
if (query(mid, n) == n - 1) lo = mid;
else hi = mid;
}
min = lo;
lo = 1, hi = n;
while (lo + 1 < hi) {
int mid = (lo + hi) / 2;
if (query(1, mid) == n - 1) hi = mid;
else lo = mid;
}
max = hi;
a[min] = 1, a[max] = n;
int last = min, sum = 0;
bool increasing = true;
for (int i = min - 1; i > 0; --i) {
int diff = query(i, last), add = query(i, i + 1);
if (sum + add != diff) {
last = i + 1, sum = 0;
increasing ^= true;
}
a[i] = a[i + 1] + (increasing ? add : -add);
sum += add;
}
last = min, sum = 0;
increasing = true;
for (int i = min + 1; i < max; ++i) {
int diff = query(last, i), add = query(i - 1, i);
if (sum + add != diff) {
last = i - 1, sum = 0;
increasing ^= true;
}
a[i] = a[i - 1] + (increasing ? add : -add);
sum += add;
}
last = max, sum = 0;
increasing = false;
for (int i = max + 1; i <= n; ++i) {
int diff = query(last, i), add = query(i - 1, i);
if (sum + add != diff) {
last = i - 1, sum = 0;
increasing ^= true;
}
a[i] = a[i - 1] + (increasing ? add : -add);
sum += add;
}
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... |