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;
typedef int INT;
#define int long long
#define FOR(i, l, r) for(int i = (l); i < (r); i++)
#define fst first
#define snd second
typedef vector<int> vi;
typedef pair<int, int> ii;
vi A;
void solve(INT N) {
A.resize(N);
A[0] = 0;
A[1] = query(1, 2);
FOR(i, 2, N){
int a = query(i, i+1);
int b = query(i-1, i+1);
int p1 = A[i-1] + a, p2 = A[i-1] - a;
if(abs( max(A[i-2], max(p1, A[i-1])) - min(min(A[i-2], A[i-1]), p1) ) == b) A[i] = p1;
else A[i] = p2;
}
//for(int a : A) cout << a << " ";
//cout << endl;
ii mi = {1e9, -1}, ma = {-1e9, -1};
FOR(i, 0, N) mi = min(mi, {A[i], i}), ma = max(ma, {A[i], i});
//cout << mi.fst << " " << ma.fst << endl;
//cout << mi.snd << " " << ma.snd << endl;
if(mi.snd > ma.snd) {
//cout << "Reversing " << endl;
for(int &a : A) a = -a;
mi.fst = -ma.fst;
}
//cout << 1 - mi.fst << endl;
for(int &a : A) a += 1 - mi.fst;
//for(int a : A) cout << a << " ";
//cout << endl;
FOR(i, 0, N){
//cout << A[i] << " ";
answer(i+1, A[i]);
}
// cout << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |