# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
566143 | Uzouf | Xylophone (JOI18_xylophone) | C++14 | 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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "xylophone.h"
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl "\n"
int mod=1e9+7;
int N=2e5+5;
template<class x>
using ordered_multiset = tree<x, null_type,less_equal<x>, rb_tree_tag,tree_order_statistics_node_update>;
bool sign[5005];
void solve(int N) {
map<pair<int,int>,int> df;
for (int i=1;i<=N;i++) {
if (i+1<=N) {
df[{i,i+1}]=query(i,i+1);
}
if (i+2<=N) {
df[{i,i+2}]=query(i,i+2);
}
}
for (int i=1;i<=N;i++) {
if (df[{i,i+2}]==df[{i,i+1}]+df[{i+1,i+2}]) {
sign[i]=true; sign[i+1]=true; i++; continue;
}
sign[i]=1^sign[i-1];
}
int og[N+5];
og[1]=0;
int mn=INT_MAX;
for (int i=2;i<=N;i++) {
if (sign[i-1]==0) {
og[i]=og[i-1]+df[{i-1,i}];
}
else {
og[i]=og[i-1]-df[{i-1,i}];
}
mn=min(mn,og[i]);
}
mn*=-1;
int ans[N+5];
bool f1=false,gg=false;
for (int i=1;i<=N;i++) {
ans[i]=og[i]+mn+1;
if (ans[i]==1) f1=true;
if (ans[i]==N && !f1) gg=true;
}
for (int i=1;i<=N;i++) {
if (gg) ans[i]=N+1-ans[i];
answer(i,ans[i]);
}
}