# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
478982 | ponytail | Xylophone (JOI18_xylophone) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//SUBMIT
#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
static int A[N_MAX];
void solve(int N) {
int value = query(1, N);
int P[N+1];
int delta[N+1];
int one[N+1], two[N+1];
for(int i = 1; i < N; i++) {
one[i] = query(i, i+1);
}
for(int i=1; i<N-1; i++) {
two[i] = query(i, i+2);
}
if(one[1] + one[2] == two[1]) delta[1] = one[1], delta[2] = one[2];
else delta[1] = one[1], delta[2] = -one[2];
for(int i=3; i<N; i++) {
if(one[i-1] + one[i] == two[i-1]) delta[i] = (delta[i-1] > 0 ? 1 : -1) * one[i];
else delta[i] = (delta[i-1] > 0 ? -1 : 1) * one[i];
}
int mini, maxi, cur;
mini = 1e9, maxi = -1e9, cur = 0;
for(int i=1; i<N; i++) {
cur += delta[i];
mini = min(mini, cur);
maxi = max(maxi, cur);
}
cur = 0;
int pos[N+1];
for(int i=2; i<=N; i++) {
cur += delta[i-1];
P[i] = cur - mini + 1;
pos[P[i]] = i;
}
P[1] = -mini + 1;
if(pos[1] > pos[N]) {
for(int i=1; i<N; i++) delta[i] *= -1;
mini = 1e9, maxi = -1e9, cur = 0;
for(int i=1; i<N; i++) {
cur += delta[i];
mini = min(mini, cur);
maxi = max(maxi, cur);
}
cur = 0;
for(int i=2; i<=N; i++) {
cur += delta[i-1];
P[i] = cur - mini + 1;
}
P[1] = -mini + 1;
}
for(int i=1; i<=N; i++) {
answer(i, P[i]);
}
}
//END SUBMIT