이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
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];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=tree2[j+1]-tree2[i];
if(sum==0||sum==1)
res=max(res,num);
}
}*/
}
}
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... |