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"
#define here cerr<<"===========================================\n"
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
using namespace std;
static int A[5000];
#define maxn 5005
int a[maxn];
map<pii,int> mp;
int get(int l,int r){
if(mp.count({l,r})) return mp[{l,r}];
return mp[{l,r}] = query(l,r);
}
bool vis[maxn];
void solve(int N) {
int n = N;
a[1] = 0;
a[2] = get(1,2);
for(int i = 3;i<=n;i++){
int x = get(i-1,i);
int y = get(i-2,i-1);
int z = get(i-2,i);
if(x+y==z){
if(a[i-1]>=a[i-2]) a[i] = a[i-2] + z;
else a[i] = a[i-2] - z;
}else if(z==x){
if(a[i-1]>=a[i-2]) a[i] = a[i-1] - x;
else a[i] = a[i-1] + x;
}else{
if(a[i-1]>=a[i-2]) a[i] = a[i-1] - x;
else a[i] = a[i-1] + x;
}
}
int mini = llinf;
for(int i = 1;i<=n;i++){
mini = min(mini,a[i]);
}
int idx1,idxn;
for(int i = 1;i<=n;i++){
a[i]-=mini-1;
if(a[i]==1) idx1 = i;
if(a[i]==n) idxn = i;
}
if(idx1>idxn) for(int i = 1;i<=n;i++) a[i] = n-a[i]+1;
if(n<=10) ceri(a,1,n);
for(int i = 1;i<=n;i++) answer(i,a[i]);
}
/*
5
2 1 5 3 4
*/
Compilation message (stderr)
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:7:15: warning: overflow in conversion from 'long long int' to 'int' changes value from '100000000000000000' to '1569325056' [-Woverflow]
7 | #define llinf 100000000000000000LL // 10^17
| ^~~~~~~~~~~~~~~~~~~~
xylophone.cpp:50:16: note: in expansion of macro 'llinf'
50 | int mini = llinf;
| ^~~~~
xylophone.cpp: At global scope:
xylophone.cpp:21:12: warning: 'A' defined but not used [-Wunused-variable]
21 | static int A[5000];
| ^
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:60:5: warning: 'idxn' may be used uninitialized in this function [-Wmaybe-uninitialized]
60 | if(idx1>idxn) for(int i = 1;i<=n;i++) a[i] = n-a[i]+1;
| ^~
xylophone.cpp:60:5: warning: 'idx1' may be used uninitialized in this function [-Wmaybe-uninitialized]
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |