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 "xylophone.h"
#define ll int
using namespace std;
ll a[100005];
ll calc(ll a, ll b, ll dis1, ll dis2)
{
if (a<b)
{
if (dis1==dis2 || dis2==b-a)
return a+dis1;
return a-dis1;
}
if (dis1==dis2 || dis2==a-b)
return a-dis1;
return a+dis1;
}
void solve(ll n)
{
// freopen("output.txt", "w", stdout);
ll L=1, R=n;
ll lo=L, hi=R, val=query(lo, hi);
while (hi-lo>1)
{
ll mid=(hi+lo)/2;
if (query(L, mid)!=val)
lo=mid;
else hi=mid;
}
if (query(L, lo)!=val)
R=hi;
else R=lo;
lo=L, hi=R;
while (hi-lo>1)
{
ll mid=(hi+lo)/2;
if (query(mid, R)!=val)
hi=mid;
else lo=mid;
}
if (query(hi, R)!=val)
L=lo;
else R=hi;
a[L]=1; a[R]=n;
// cout << L << " " << R << "\n";
if (L>1) a[L-1]=a[L]+query(L-1, L);
a[L+1]=a[L]+query(L, L+1);
if (R<n) a[R+1]=a[R]-query(R, R+1);
for (ll i=L-2; i>=1; i--)
a[i]=calc(a[i+1], a[i+2], query(i, i+1), query(i, i+2));
for (ll i=L+2; i<R; i++)
a[i]=calc(a[i-1], a[i-2], query(i-1, i), query(i-2, i));
for (ll i=R+2; i<=n; i++)
a[i]=calc(a[i-1], a[i-2], query(i-1, i), query(i-2, i));
// for (ll i=1; i<=n; i++)
// cout << a[i] << " ";
// cout << "\n";
for (ll i=1; i<=n; i++)
answer(i, a[i]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |