#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)*3<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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
14940 KB |
Output is correct |
2 |
Correct |
5 ms |
14940 KB |
Output is correct |
3 |
Correct |
5 ms |
14940 KB |
Output is correct |
4 |
Correct |
4 ms |
14936 KB |
Output is correct |
5 |
Correct |
5 ms |
14936 KB |
Output is correct |
6 |
Correct |
4 ms |
14940 KB |
Output is correct |
7 |
Correct |
4 ms |
14940 KB |
Output is correct |
8 |
Correct |
3 ms |
14940 KB |
Output is correct |
9 |
Correct |
4 ms |
14940 KB |
Output is correct |
10 |
Correct |
4 ms |
14936 KB |
Output is correct |
11 |
Correct |
4 ms |
14936 KB |
Output is correct |
12 |
Correct |
5 ms |
14964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
14940 KB |
Output is correct |
2 |
Correct |
5 ms |
14940 KB |
Output is correct |
3 |
Correct |
5 ms |
14940 KB |
Output is correct |
4 |
Correct |
4 ms |
14936 KB |
Output is correct |
5 |
Correct |
5 ms |
14936 KB |
Output is correct |
6 |
Correct |
4 ms |
14940 KB |
Output is correct |
7 |
Correct |
4 ms |
14940 KB |
Output is correct |
8 |
Correct |
3 ms |
14940 KB |
Output is correct |
9 |
Correct |
4 ms |
14940 KB |
Output is correct |
10 |
Correct |
4 ms |
14936 KB |
Output is correct |
11 |
Correct |
4 ms |
14936 KB |
Output is correct |
12 |
Correct |
5 ms |
14964 KB |
Output is correct |
13 |
Correct |
14 ms |
14940 KB |
Output is correct |
14 |
Correct |
14 ms |
14940 KB |
Output is correct |
15 |
Correct |
16 ms |
14936 KB |
Output is correct |
16 |
Correct |
16 ms |
15024 KB |
Output is correct |
17 |
Correct |
15 ms |
14940 KB |
Output is correct |
18 |
Correct |
12 ms |
14940 KB |
Output is correct |
19 |
Correct |
12 ms |
14940 KB |
Output is correct |
20 |
Correct |
13 ms |
14936 KB |
Output is correct |
21 |
Incorrect |
14 ms |
15044 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
14940 KB |
Output is correct |
2 |
Execution timed out |
2045 ms |
29740 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
14940 KB |
Output is correct |
2 |
Execution timed out |
2029 ms |
22788 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2013 ms |
35624 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
14940 KB |
Output is correct |
2 |
Correct |
5 ms |
14940 KB |
Output is correct |
3 |
Correct |
5 ms |
14940 KB |
Output is correct |
4 |
Correct |
4 ms |
14936 KB |
Output is correct |
5 |
Correct |
5 ms |
14936 KB |
Output is correct |
6 |
Correct |
4 ms |
14940 KB |
Output is correct |
7 |
Correct |
4 ms |
14940 KB |
Output is correct |
8 |
Correct |
3 ms |
14940 KB |
Output is correct |
9 |
Correct |
4 ms |
14940 KB |
Output is correct |
10 |
Correct |
4 ms |
14936 KB |
Output is correct |
11 |
Correct |
4 ms |
14936 KB |
Output is correct |
12 |
Correct |
5 ms |
14964 KB |
Output is correct |
13 |
Correct |
14 ms |
14940 KB |
Output is correct |
14 |
Correct |
14 ms |
14940 KB |
Output is correct |
15 |
Correct |
16 ms |
14936 KB |
Output is correct |
16 |
Correct |
16 ms |
15024 KB |
Output is correct |
17 |
Correct |
15 ms |
14940 KB |
Output is correct |
18 |
Correct |
12 ms |
14940 KB |
Output is correct |
19 |
Correct |
12 ms |
14940 KB |
Output is correct |
20 |
Correct |
13 ms |
14936 KB |
Output is correct |
21 |
Incorrect |
14 ms |
15044 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
14940 KB |
Output is correct |
2 |
Correct |
5 ms |
14940 KB |
Output is correct |
3 |
Correct |
5 ms |
14940 KB |
Output is correct |
4 |
Correct |
4 ms |
14936 KB |
Output is correct |
5 |
Correct |
5 ms |
14936 KB |
Output is correct |
6 |
Correct |
4 ms |
14940 KB |
Output is correct |
7 |
Correct |
4 ms |
14940 KB |
Output is correct |
8 |
Correct |
3 ms |
14940 KB |
Output is correct |
9 |
Correct |
4 ms |
14940 KB |
Output is correct |
10 |
Correct |
4 ms |
14936 KB |
Output is correct |
11 |
Correct |
4 ms |
14936 KB |
Output is correct |
12 |
Correct |
5 ms |
14964 KB |
Output is correct |
13 |
Correct |
14 ms |
14940 KB |
Output is correct |
14 |
Correct |
14 ms |
14940 KB |
Output is correct |
15 |
Correct |
16 ms |
14936 KB |
Output is correct |
16 |
Correct |
16 ms |
15024 KB |
Output is correct |
17 |
Correct |
15 ms |
14940 KB |
Output is correct |
18 |
Correct |
12 ms |
14940 KB |
Output is correct |
19 |
Correct |
12 ms |
14940 KB |
Output is correct |
20 |
Correct |
13 ms |
14936 KB |
Output is correct |
21 |
Incorrect |
14 ms |
15044 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |