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 get_min(int l,int r){
int res=1e9;
for(int i=l;i<r;i++)
res=min(res,tree[i]);
return res;
}
int get_max(int l,int r){
int res=-1e9;
for(int i=l;i<r;i++)
res=max(res,tree[i]);
return res;
}
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=1;
for(int v=0;v<n;v++){
for(int idx:arr[v])
for(int i=idx+1;i<=n;i++)
tree[i]+=2;
int l=0;
for(int r=0;r<(int)arr[v].size();r++){
int min2=get_min(arr[v][r],n+1);
int max2=get_max(arr[v][r],n+1);
int min1=get_min(0,arr[v][l]+1);
int max1=get_max(0,arr[v][l]+1);
while(l<r&&(max1+(r-l+1)*4<min2||max2<min1)){
l++;
min1=get_min(0,arr[v][l]+1);
max1=get_max(0,arr[v][l]+1);
}
res=max(res,r-l+1);
}
}
return res;
}
# | 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... |