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 "sequence.h"
#include <bits/stdc++.h>
// #include "grader.cpp"
using namespace std;
const int LIM=2e3+10;
int pre[LIM][LIM];
int a[LIM],n;
void compute_pre()
{
for(int i=1;i<=n;i++)
pre[0][i]=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
pre[i][j]=pre[i-1][j]+(a[i-1]<=j);
}
}
}
int count_less(int l,int r,int x)
{
return pre[r+1][x]-pre[l][x];
}
int count(int l,int r,int x)
{
int tp=count_less(l,r,x)-count_less(l,r,x-1);
// if(tp==4)
// cout<<"FOR "<<l<<' '<<r<<' '<<x<<endl;
return tp;
}
int sequence(int NP, std::vector<int> AP) {
if(NP<LIM)
{
n=NP;
for(int j=0;j<n;j++)
a[j]=AP[j];
compute_pre();
int ans=1;
for(int l=0;l<n;l++)
{
for(int r=l+1;r<n;r++)
{
int s=0;
int e=n+1;
int len=(r-l+1);
int flooor=(len-1)/2;
/*
if len is even
then there are two medain = floor((len-1)/2) and ceil((len-1)/2)
else if len is odd
single medain
*/
while(s+1<e)
{
int mid=(s+e)/2;
if(count_less(l,r,mid)<=flooor)
{
s=mid;
}
else{
e=mid;
}
}
ans=max(ans,count(l,r,e));
if(len%2==0)
{
int ceill=flooor+1;
s=0;
e=n+1;
while(s+1<e)
{
int mid=(s+e)/2;
if(count_less(l,r,mid)<=ceill)
{
s=mid;
}
else{
e=mid;
}
}
ans=max(ans,count(l,r,e));
}
}
}
return ans;
// cout<<ans<<endl;
}
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... |