# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
74326 | Mamnoon_Siam | 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.
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
void detect_pitch(int N) {
if(N == 2) {
answer(0, 0);
answer(1, 1);
return;
}
vector<int> a(N), two(N), three(N);
for(int i = 0; i < N - 1; i++) {
two[i] = ask(i, i + 1);
if(i < N - 2) three[i] = ask(i, i + 2);
}
a[1] = two[0];
int tog = 1;
for(int i = 2; i < N; i++) {
if(three[i - 2] == two[i - 2] + two[i - 1]) {
a[i] = tog ? a[i - 1] + two[i - 1] : a[i - 1] - two[i - 1];
} else {
a[i] = tog ? a[i - 1] - two[i - 1] : a[i - 1] + two[i - 1];
tog ^= 1;
}
}
int mxid, mnid, mx = -1e5, mn = 1e5;
for(int i = 0; i < N; i++) {
if(a[i] < mn) mn = a[i], mnid = i;
if(a[i] > mx) mx = a[i], mxid = i;
}
if(mxid < mnid) {
for(int &b : a) b = -b;
swap(mn, mx);
mx = -mx, mn = -mn;
}
for(int i = 0; i < N; i++) a[i] -= mn;
for(int i = 0; i < N; i++) answer(i, a[i]);
}