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"
using namespace std;
#define pb push_back
void solve(int n)
{
vector<int> arr(n+1);
/*for(auto elt: arr)
cout << elt << ' ';
cout << endl;*/
/*orig.resize(n+1);
for(int i = 1; i<=n; i++)
cin >> orig[i];*/
int l = 1, r = n-1;
int maxdif = n-1;
while(maxdif==n-1)
{
maxdif = query(l, r);
r--;
}
r+=2, l++;
maxdif = n-1;
while(maxdif==n-1)
{
maxdif = query(l, r);
l++;
}
l-=2;
arr[l] = 1;
arr[r] = n;
//cout << l << ' ' << r << endl;
if(r-l>1)
{
maxdif = query(l, l+1);
arr[l+1] = maxdif+1;
}
for(int i = l+2; i<r; i++)
{
int dif = query(l, i);
if(dif==maxdif)
{
int dif2 = query(l+1, i);
arr[i] = arr[l+1]-dif2;
}
else
{
arr[i] = dif + 1;
}
}
if(l>1)
{
maxdif = query(l-1, l);
arr[l-1] = maxdif+1;
}
for(int i = l-2; i>=1; i--)
{
int dif = query(i, l);
if(dif==maxdif)
{
int dif2 = query(l-1, i);
arr[i] = arr[l-1]-dif2;
}
else
{
arr[i] = dif+1;
}
}
if(r<n)
{
maxdif = query(r, r+1);
arr[r+1] = n-maxdif;
}
for(int i = r+2; i<=n; i++)
{
int dif = query(r, i);
if(dif==maxdif)
{
int dif2 = query(r+1, i);
arr[i] = arr[r+1] + dif2;
}
else
{
arr[i] = n-dif;
}
}
for(int i = 1; i<=n; i++)
{
answer(i, arr[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... |