// author: erray
#include<bits/stdc++.h>
#include "xylophone.h"
using namespace std;
//int query(int s, int e);
//int answer(int ind, int v);
void solve(int n) {
vector<int> f(n);
f[1] = query(1, 2);
for (int i = 2; i < n; ++i) {
int th = query(i - 1, i + 1), tw = query(i, i + 1);
if (th == abs(f[i - 1])) {
f[i] = f[i - 1] + (f[i - 1] > 0 ? -1 : 1) * tw;
} else if (th > abs(f[i - 1])) {
if (tw > th) {
f[i] = f[i - 1] + (f[i - 1] > 0 ? -1 : 1) * tw;
} else {
f[i] = f[i - 1] + (f[i - 1] > 0 ? 1 : -1) * tw;
}
}
}
vector<int> pref(n);
for (int i = 0; i < n; ++i) {
pref[i] = pref[i - (i > 0)] + f[i];
}
int ind1 = (int) (max_element(pref.begin(), pref.end()) - pref.begin()), ind2 = (int) (min_element(pref.begin(), pref.end()) - pref.begin());
if (ind2 > ind1) {
swap(ind2, ind1);
for (auto& el : f) el = -el;
}
swap(ind1, ind2);
vector<int> ans(n);
ans[ind1] = 1;
for (int i = ind1 + 1; i < n; ++i) {
ans[i] = ans[i - 1] + f[i];
}
for (int i = ind1 - 1; i >= 0; --i) {
ans[i] = ans[i + 1] + -f[i + 1];
}
for (int i = 0; i < n; ++i) {
answer(i + 1, ans[i]);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
256 KB |
Wrong Answer [4] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
256 KB |
Wrong Answer [4] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
256 KB |
Wrong Answer [4] |
3 |
Halted |
0 ms |
0 KB |
- |