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<vector>
#include<iostream>
using namespace std;
int n;
int arr2[500000];
int tree[500001];
vector<int>arr[500000];
int sequence(int N,vector<int>A){
n=N;
for(int i=0;i<n;i++){
arr[A[i]-1].push_back(i);
arr2[i]=A[i]-1;
}
for(int i=0;i<=n;i++)
tree[i]=-i;
int res=0,res2=0;
for(int v=0;v<n;v++){
for(int idx=0;idx<(int)arr[v].size();idx++){
for(int i=arr[v][idx]+1;i<=n;i++)
tree[i]+=2;
int min2=1e9;
int max2=-1e9;
for(int i=arr[v][idx]+1;i<=n;i++){
int sum=tree[i];
min2=min(min2,sum);
max2=max(max2,sum);
}
int min1=1e9;
int max1=-1e9;
for(int i=0;i<=arr[v][idx];i++){
int sum=tree[i];
min1=min(min1,sum);
max1=max(max1,sum);
//cout<<min1<<" "<<max1<<", "<<min2<<" "<<max2<<"\n";
if(max1<min2-1||max2<min1)
continue;
int i2=0;
while(arr[v][i2]<i)
i2++;
res=max(res,idx-i2+1);
break;
}
for(int i=0;i<n;i++){
int num=0;
for(int j=i;j<n;j++){
if(arr2[j]==v)
num++;
int sum=tree[j+1]-tree[i];
if(sum==0||sum==1)
res2=max(res2,num);
}
}
}
}
return res2;
}
# | 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... |