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>
#define ll long long
#define mid (r+l)/2
using namespace std;
const ll N=3e5+9,M=2e18+9,mod=1e9+7;
ll tr[N],n,x,y,L,R,m;
void up(ll i,ll l,ll r,ll ind,ll v)
{
if(l==r)
{
tr[i]+=v;
return;
}
if(ind<=mid)up(2*i,l,mid,ind,v);
else up(2*i+1,mid+1,r,ind,v);
tr[i]=tr[2*i]+tr[2*i+1];
}
ll q(ll i,ll l,ll r,ll s,ll e)
{
if(s<=l && r<=e)return tr[i];
if(s<=mid && mid<e)return q(2*i,l,mid,s,e)+q(2*i+1,mid+1,r,s,e);
if(s<=mid)return q(2*i,l,mid,s,e);
return q(2*i+1,mid+1,r,s,e);
}
int sequence(int N, vector<int> A) {
ll ans=1;
for(ll i=0;i<N;++i)
{
for(ll j=i;j<N;++j)
{
up(1,0,N,A[j],1);
if((j-i+1)&1)
{
L=0,R=N+1,x=(j-i+1)/2+1;
while(R-L>1)
{
m=(R+L)/2;
if(q(1,0,N,0,m)<x)L=m;else R=m;
}
ans=max(ans,q(1,0,N,L+1,L+1));
}
else
{
L=0,R=N+1,x=(j-i+1)/2;
while(R-L>1)
{
m=(R+L)/2;
if(q(1,0,N,0,m)<x)L=m;else R=m;
}
ans=max(ans,q(1,0,N,L+1,L+1));
L=0,R=N+1,x=(j-i+1)/2+1;
while(R-L>1)
{
m=(R+L)/2;
if(q(1,0,N,0,m)<x)L=m;else R=m;
}
ans=max(ans,q(1,0,N,L+1,L+1));
}
}
for(ll j=i;j<N;++j)up(1,0,N,A[j],-1);
}
return ans;
}
/*
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n;
vector<int>v(n);
for(auto &i:v)cin>>i;
cout<<sequence(n,v);
}
*/
# | 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... |