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 <iostream>
#include <algorithm>
#define int long long
using namespace std;
int v[405], sp[405];
struct element
{
int poz, val;
};
element ord[405];
bool cmp(element a, element b)
{
return a.poz < b.poz;
}
signed main()
{
int n;
cin>>n;
for(int i = 1; i <= n; i++)
{
cin>>v[i];
int nrsubsir = (v[i] - v[i - 1]) - 1, st = 1, dr = i - 1, mij = 0;
if(i > 1 || nrsubsir != 0)
{
mij = -1;
while(st <= dr)
{
mij = (st + dr) / 2;
if(sp[mij] == nrsubsir)
break;
else if(sp[mij] < nrsubsir)
st = mij + 1;
else
dr = mij - 1;
}
}
if(nrsubsir == 0 || i <= 1)
mij = 1;
else
mij++;
for(int j = i - 1; j >= mij; j--)
{
sp[j + 1] = sp[j] + nrsubsir + 1;
ord[j + 1].poz = ord[j].poz;
}
ord[mij].poz = i;
sp[mij] = sp[mij - 1] + nrsubsir + 1;
}
for(int i = 1; i <= n; i++)
ord[i].val = i;
sort(ord + 1, ord + n + 1, cmp);
for(int i = 1; i <= n; i++)
cout<<ord[i].val<<" ";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |