#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14936 KB |
Output is correct |
2 |
Correct |
4 ms |
14940 KB |
Output is correct |
3 |
Correct |
3 ms |
14940 KB |
Output is correct |
4 |
Correct |
3 ms |
14936 KB |
Output is correct |
5 |
Incorrect |
4 ms |
14936 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14936 KB |
Output is correct |
2 |
Correct |
4 ms |
14940 KB |
Output is correct |
3 |
Correct |
3 ms |
14940 KB |
Output is correct |
4 |
Correct |
3 ms |
14936 KB |
Output is correct |
5 |
Incorrect |
4 ms |
14936 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14936 KB |
Output is correct |
2 |
Execution timed out |
2029 ms |
29720 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14940 KB |
Output is correct |
2 |
Execution timed out |
2036 ms |
23040 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2017 ms |
35408 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14936 KB |
Output is correct |
2 |
Correct |
4 ms |
14940 KB |
Output is correct |
3 |
Correct |
3 ms |
14940 KB |
Output is correct |
4 |
Correct |
3 ms |
14936 KB |
Output is correct |
5 |
Incorrect |
4 ms |
14936 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14936 KB |
Output is correct |
2 |
Correct |
4 ms |
14940 KB |
Output is correct |
3 |
Correct |
3 ms |
14940 KB |
Output is correct |
4 |
Correct |
3 ms |
14936 KB |
Output is correct |
5 |
Incorrect |
4 ms |
14936 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |