# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1107714 | KK_1729 | 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 <bits/stdc++.h>
using namespace std;
// #define int long long
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(a) a.begin(), a.end()
#define endl "\n"
void printVector(vector<int> a){
for (auto x: a) cout << x << " ";
cout << endl;
}
void solve(int n){
vector<int> diff(n+1);
FOR(i,1,n){
diff[i] = query(i, i+1);
}
vector<int> type(n+1, -1);
type[1] = 1;
FOR(i,1,n-1){
int e = query(i, i+2);
if (e == diff[i]+diff[i+1]){
type[i+1] = type[i];
}else{
type[i+1] = type[i]^1;
}
}
vector<int> a(n+1);
FOR(i,1,n){
if (type[i] == 1){
a[i+1] = a[i]+diff[i];
}else{
a[i+1] = a[i]-diff[i];
}
}
int mini = 1e9; int maxi = 0;
int minind = 0; int maxind = 0;
FOR(i,1,n+1){
if (a[i] < mini){
minind = i;
}
if (a[i] > maxi){
maxind = i;
}
mini = min(mini, a[i]);
maxi = max(maxi, a[i]);
}
// printVector(a);
if (maxi - mini == n-1 && maxind > minind){
FOR(i,1,n+1){
answer(i, a[i]-(mini-1));
}
return;
}
a.clear();a.resize(n+1);
FOR(i,1,n){
if (type[i] == 1){
a[i+1] = a[i]-diff[i];
}else{
a[i+1] = a[i]+diff[i];
}
}
mini = 1e9; maxi = 0;
FOR(i,1,n+1){
mini = min(mini, a[i]);maxi = max(maxi, a[i]);
}
FOR(i,1,n+1){
answer(i, a[i]-(mini-1));
}
return;
}
int32_t main(){
solve(7);
}