# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
381176 | vishesh312 | 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;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
*/
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
using ll = long long;
const int mod = 1e9+7;
void solve(int n) {
vector<vector<int>> diff(n+1, vector<int>(n+1));
for (int i = 1; i < n; ++i) {
diff[i][i+1] = query(i, i+1);
}
for (int i = 1; i < n-1; ++i) {
diff[i][i+2] = query(i, i+2);
}
vector<int> rel(n);
rel[1] = diff[1][2];
bool inc = true;
for (int i = 2; i < n; ++i) {
inc ^= (diff[i-1][i] + diff[i][i+1] != diff[i-1][i+1]);
rel[i] = rel[i-1] + diff[i][i+1] * (inc?1:-1);
}
array<int, 2> mx = {0, 0}, mn = {0, 0};
for (int i = 1; i < n; ++i) {
if (rel[i] > mx[0]) {
mx = {rel[i], i};
}
if (rel[i] < mn[0]) {
mn = {rel[i], i};
}
}
if (mn[1] < mx[1]) {
for (int i = 0; i < n; ++i) {
answer(i+1, rel[i] - mn[0] + 1);
}
} else {
for (int i = 0; i < n; ++i) {
answer(i+1, mx[0] - rel[i] + 1);
}
}
}
/*
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int tc = 1;
//cin >> tc;
for (int i = 1; i <= tc; ++i) solve(i);
return 0;
}
*/