This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma once
#include <iostream>
#include <vector>
using namespace std;
const int NPA=5201;
int cs[NPA],ce[NPA],a[NPA],mi[NPA],mx[NPA];
int GetBestPosition(int n, int c, int r, int k[], int s[], int e[])
{
// Lets change the queries from the changed array to the original array
for(int i=0;i<n;i++)
a[i]=mi[i]=mx[i]=i;
int len=n;
for(int ro=0;ro<c;ro++)
{
int ns=a[s[ro]];
int ne=a[e[ro]];
for(int l=s[ro];l<=e[ro];l++)
{
ns=min(ns,mi[a[l]]);
ne=max(ne,mx[a[l]]);
}
for(int l=s[ro];l<=e[ro];l++)
{
mi[a[l]]=min(ns,mi[a[l]]);
mx[a[l]]=max(ne,mx[a[l]]);
}
for(int j=e[ro];j<len;j++)
a[j+s[ro]-e[ro]]=a[j];
len=len-e[ro]+s[ro];
cs[ro]=ns;
ce[ro]=ne;
}
int wins=0;
int poss=0;
a[0]=r;
for(int j=0;j<(n-1);j++)
a[j+1]=k[j];
for(int p=0;p<(n-1);p++)
{
int win=0;
if(p>0)
swap(a[p-1],a[p]);
int back_mx=-n-1,front_mx=n+1;
for(int i=0;i<p;i++)
if(a[i]>a[p])
back_mx=i;
for(int i=n-1;i>p;i--)
if(a[i]>a[p])
front_mx=i;
for(int ro=0;ro<c;ro++)
{
if(cs[ro]<=p and p<=ce[ro] and back_mx<cs[ro] and ce[ro]<front_mx)
{
win++;
}
}
if(win>wins)
{
wins=win;
poss=p;
}
}
return poss;
}
Compilation message (stderr)
tournament.cpp:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |