#include"sequence.h"
#include<vector>
#include<iostream>
using namespace std;
const int TREE_SIZE=1<<19;
int n;
vector<int>arr[500000];
int tree_lazy[2*TREE_SIZE];
int tree_min[2*TREE_SIZE];
int tree_max[2*TREE_SIZE];
void push_lazy(int node){
if(tree_lazy[node]!=0){
tree_min[node]+=tree_lazy[node];
tree_max[node]+=tree_lazy[node];
if(node<TREE_SIZE){
tree_lazy[2*node]+=tree_lazy[node];
tree_lazy[2*node+1]+=tree_lazy[node];
}
tree_lazy[node]=0;
}
}
int get_min(int node,int rl,int rr,int l,int r){
push_lazy(node);
if(r<=rl||rr<=l)
return 1e8;
if(l<=rl&&rr<=r)
return tree_min[node];
int mid=(rl+rr)/2;
return min(get_min(2*node,rl,mid,l,r),get_min(2*node+1,mid,rr,l,r));
}
int get_max(int node,int rl,int rr,int l,int r){
push_lazy(node);
if(r<=rl||rr<=l)
return -1e8;
if(l<=rl&&rr<=r)
return tree_max[node];
int mid=(rl+rr)/2;
return max(get_max(2*node,rl,mid,l,r),get_max(2*node+1,mid,rr,l,r));
}
int get_min(int l,int r){
return get_min(1,0,TREE_SIZE,l,r);
}
int get_max(int l,int r){
return get_max(1,0,TREE_SIZE,l,r);
}
void add(int node,int rl,int rr,int l,int r,int v){
push_lazy(node);
if(r<=rl||rr<=l)
return;
if(l<=rl&&rr<=r){
tree_lazy[node]+=v;
push_lazy(node);
return;
}
int mid=(rl+rr)/2;
add(2*node,rl,mid,l,r,v);
add(2*node+1,mid,rr,l,r,v);
tree_min[node]=min(tree_min[2*node],tree_min[2*node+1]);
tree_max[node]=max(tree_max[2*node],tree_max[2*node+1]);
}
void add(int l,int r,int v){
add(1,0,TREE_SIZE,l,r,v);
}
int sequence(int N,vector<int>A){
n=N;
for(int i=0;i<n;i++)
arr[A[i]-1].push_back(i);
/*for(int i=0;i<=n;i++)
tree[i]=-i;*/
for(int i=0;i<=n;i++)
add(i,i+1,-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]++;*/
add(idx+1,n+1,1);
int l=0;
for(int r=0;r<(int)arr[v].size();r++){
//l=0;
l=max(0,l-10);
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-l+1<min2-r||max2+r+1<min1+l)){
l++;
min1=get_min(0,arr[v][l]+1);
max1=get_max(0,arr[v][l]+1);
}
res=max(res,r-l+1);
}
for(int idx:arr[v])
/*for(int i=idx+1;i<=n;i++)
tree[i]++;*/
add(idx+1,n+1,1);
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
15960 KB |
Output is correct |
2 |
Correct |
5 ms |
15960 KB |
Output is correct |
3 |
Correct |
4 ms |
15960 KB |
Output is correct |
4 |
Correct |
5 ms |
15960 KB |
Output is correct |
5 |
Correct |
5 ms |
15960 KB |
Output is correct |
6 |
Correct |
5 ms |
15964 KB |
Output is correct |
7 |
Correct |
4 ms |
15960 KB |
Output is correct |
8 |
Correct |
4 ms |
15964 KB |
Output is correct |
9 |
Correct |
5 ms |
15960 KB |
Output is correct |
10 |
Correct |
5 ms |
15960 KB |
Output is correct |
11 |
Correct |
4 ms |
15960 KB |
Output is correct |
12 |
Correct |
4 ms |
15960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
15960 KB |
Output is correct |
2 |
Correct |
5 ms |
15960 KB |
Output is correct |
3 |
Correct |
4 ms |
15960 KB |
Output is correct |
4 |
Correct |
5 ms |
15960 KB |
Output is correct |
5 |
Correct |
5 ms |
15960 KB |
Output is correct |
6 |
Correct |
5 ms |
15964 KB |
Output is correct |
7 |
Correct |
4 ms |
15960 KB |
Output is correct |
8 |
Correct |
4 ms |
15964 KB |
Output is correct |
9 |
Correct |
5 ms |
15960 KB |
Output is correct |
10 |
Correct |
5 ms |
15960 KB |
Output is correct |
11 |
Correct |
4 ms |
15960 KB |
Output is correct |
12 |
Correct |
4 ms |
15960 KB |
Output is correct |
13 |
Correct |
9 ms |
16216 KB |
Output is correct |
14 |
Correct |
9 ms |
16216 KB |
Output is correct |
15 |
Correct |
15 ms |
16216 KB |
Output is correct |
16 |
Correct |
16 ms |
16216 KB |
Output is correct |
17 |
Correct |
18 ms |
16472 KB |
Output is correct |
18 |
Correct |
8 ms |
16216 KB |
Output is correct |
19 |
Correct |
9 ms |
16216 KB |
Output is correct |
20 |
Correct |
9 ms |
16216 KB |
Output is correct |
21 |
Correct |
10 ms |
16220 KB |
Output is correct |
22 |
Correct |
10 ms |
16216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
15960 KB |
Output is correct |
2 |
Correct |
1224 ms |
37980 KB |
Output is correct |
3 |
Correct |
1264 ms |
38152 KB |
Output is correct |
4 |
Correct |
1419 ms |
30552 KB |
Output is correct |
5 |
Correct |
1229 ms |
40064 KB |
Output is correct |
6 |
Correct |
1223 ms |
40280 KB |
Output is correct |
7 |
Correct |
1956 ms |
31824 KB |
Output is correct |
8 |
Correct |
1674 ms |
31964 KB |
Output is correct |
9 |
Correct |
1764 ms |
31232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
15960 KB |
Output is correct |
2 |
Correct |
1933 ms |
30204 KB |
Output is correct |
3 |
Execution timed out |
2045 ms |
31160 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1344 ms |
43824 KB |
Output is correct |
2 |
Correct |
1308 ms |
43804 KB |
Output is correct |
3 |
Correct |
1366 ms |
43392 KB |
Output is correct |
4 |
Correct |
1307 ms |
43168 KB |
Output is correct |
5 |
Correct |
1360 ms |
39816 KB |
Output is correct |
6 |
Correct |
1361 ms |
39992 KB |
Output is correct |
7 |
Correct |
1259 ms |
38736 KB |
Output is correct |
8 |
Correct |
1281 ms |
38132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
15960 KB |
Output is correct |
2 |
Correct |
5 ms |
15960 KB |
Output is correct |
3 |
Correct |
4 ms |
15960 KB |
Output is correct |
4 |
Correct |
5 ms |
15960 KB |
Output is correct |
5 |
Correct |
5 ms |
15960 KB |
Output is correct |
6 |
Correct |
5 ms |
15964 KB |
Output is correct |
7 |
Correct |
4 ms |
15960 KB |
Output is correct |
8 |
Correct |
4 ms |
15964 KB |
Output is correct |
9 |
Correct |
5 ms |
15960 KB |
Output is correct |
10 |
Correct |
5 ms |
15960 KB |
Output is correct |
11 |
Correct |
4 ms |
15960 KB |
Output is correct |
12 |
Correct |
4 ms |
15960 KB |
Output is correct |
13 |
Correct |
9 ms |
16216 KB |
Output is correct |
14 |
Correct |
9 ms |
16216 KB |
Output is correct |
15 |
Correct |
15 ms |
16216 KB |
Output is correct |
16 |
Correct |
16 ms |
16216 KB |
Output is correct |
17 |
Correct |
18 ms |
16472 KB |
Output is correct |
18 |
Correct |
8 ms |
16216 KB |
Output is correct |
19 |
Correct |
9 ms |
16216 KB |
Output is correct |
20 |
Correct |
9 ms |
16216 KB |
Output is correct |
21 |
Correct |
10 ms |
16220 KB |
Output is correct |
22 |
Correct |
10 ms |
16216 KB |
Output is correct |
23 |
Correct |
245 ms |
19796 KB |
Output is correct |
24 |
Correct |
215 ms |
20004 KB |
Output is correct |
25 |
Correct |
229 ms |
19800 KB |
Output is correct |
26 |
Correct |
508 ms |
19048 KB |
Output is correct |
27 |
Correct |
523 ms |
19340 KB |
Output is correct |
28 |
Correct |
522 ms |
19328 KB |
Output is correct |
29 |
Correct |
433 ms |
18768 KB |
Output is correct |
30 |
Correct |
438 ms |
19008 KB |
Output is correct |
31 |
Correct |
184 ms |
19144 KB |
Output is correct |
32 |
Correct |
159 ms |
21332 KB |
Output is correct |
33 |
Incorrect |
228 ms |
20368 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
15960 KB |
Output is correct |
2 |
Correct |
5 ms |
15960 KB |
Output is correct |
3 |
Correct |
4 ms |
15960 KB |
Output is correct |
4 |
Correct |
5 ms |
15960 KB |
Output is correct |
5 |
Correct |
5 ms |
15960 KB |
Output is correct |
6 |
Correct |
5 ms |
15964 KB |
Output is correct |
7 |
Correct |
4 ms |
15960 KB |
Output is correct |
8 |
Correct |
4 ms |
15964 KB |
Output is correct |
9 |
Correct |
5 ms |
15960 KB |
Output is correct |
10 |
Correct |
5 ms |
15960 KB |
Output is correct |
11 |
Correct |
4 ms |
15960 KB |
Output is correct |
12 |
Correct |
4 ms |
15960 KB |
Output is correct |
13 |
Correct |
9 ms |
16216 KB |
Output is correct |
14 |
Correct |
9 ms |
16216 KB |
Output is correct |
15 |
Correct |
15 ms |
16216 KB |
Output is correct |
16 |
Correct |
16 ms |
16216 KB |
Output is correct |
17 |
Correct |
18 ms |
16472 KB |
Output is correct |
18 |
Correct |
8 ms |
16216 KB |
Output is correct |
19 |
Correct |
9 ms |
16216 KB |
Output is correct |
20 |
Correct |
9 ms |
16216 KB |
Output is correct |
21 |
Correct |
10 ms |
16220 KB |
Output is correct |
22 |
Correct |
10 ms |
16216 KB |
Output is correct |
23 |
Correct |
1224 ms |
37980 KB |
Output is correct |
24 |
Correct |
1264 ms |
38152 KB |
Output is correct |
25 |
Correct |
1419 ms |
30552 KB |
Output is correct |
26 |
Correct |
1229 ms |
40064 KB |
Output is correct |
27 |
Correct |
1223 ms |
40280 KB |
Output is correct |
28 |
Correct |
1956 ms |
31824 KB |
Output is correct |
29 |
Correct |
1674 ms |
31964 KB |
Output is correct |
30 |
Correct |
1764 ms |
31232 KB |
Output is correct |
31 |
Correct |
1933 ms |
30204 KB |
Output is correct |
32 |
Execution timed out |
2045 ms |
31160 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |