#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);
vector<int>mn1,mn2,mx1,mx2;
for(int i:arr[v]){
mn1.push_back(get_min(0,i+1));
mn2.push_back(get_min(i,n+1));
mx1.push_back(get_max(0,i+1));
mx2.push_back(get_max(i,n+1));
}
int l=0;
for(int r=0;r<(int)arr[v].size();r++){
l=max(0,l-30);
int min2=mn2[r];
int max2=mx2[r];
int min1=mn1[l];
int max1=mx1[l];
while(l<r&&(max1-l+1<min2-r||max2+r+1<min1+l)){
l++;
min1=mn1[l];
max1=mx1[l];
}
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 |
5 ms |
15960 KB |
Output is correct |
2 |
Correct |
4 ms |
15960 KB |
Output is correct |
3 |
Correct |
4 ms |
15964 KB |
Output is correct |
4 |
Correct |
4 ms |
15960 KB |
Output is correct |
5 |
Correct |
4 ms |
15960 KB |
Output is correct |
6 |
Correct |
4 ms |
15960 KB |
Output is correct |
7 |
Correct |
4 ms |
15964 KB |
Output is correct |
8 |
Correct |
4 ms |
16164 KB |
Output is correct |
9 |
Correct |
4 ms |
15960 KB |
Output is correct |
10 |
Correct |
4 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 |
5 ms |
15960 KB |
Output is correct |
2 |
Correct |
4 ms |
15960 KB |
Output is correct |
3 |
Correct |
4 ms |
15964 KB |
Output is correct |
4 |
Correct |
4 ms |
15960 KB |
Output is correct |
5 |
Correct |
4 ms |
15960 KB |
Output is correct |
6 |
Correct |
4 ms |
15960 KB |
Output is correct |
7 |
Correct |
4 ms |
15964 KB |
Output is correct |
8 |
Correct |
4 ms |
16164 KB |
Output is correct |
9 |
Correct |
4 ms |
15960 KB |
Output is correct |
10 |
Correct |
4 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 |
8 ms |
16216 KB |
Output is correct |
14 |
Correct |
10 ms |
16216 KB |
Output is correct |
15 |
Correct |
8 ms |
16216 KB |
Output is correct |
16 |
Correct |
8 ms |
16216 KB |
Output is correct |
17 |
Correct |
8 ms |
16216 KB |
Output is correct |
18 |
Correct |
8 ms |
16216 KB |
Output is correct |
19 |
Correct |
8 ms |
16216 KB |
Output is correct |
20 |
Correct |
9 ms |
16220 KB |
Output is correct |
21 |
Correct |
8 ms |
16216 KB |
Output is correct |
22 |
Correct |
9 ms |
16220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
15960 KB |
Output is correct |
2 |
Correct |
1293 ms |
37864 KB |
Output is correct |
3 |
Correct |
1297 ms |
37964 KB |
Output is correct |
4 |
Correct |
1200 ms |
32836 KB |
Output is correct |
5 |
Correct |
1282 ms |
37016 KB |
Output is correct |
6 |
Correct |
1300 ms |
36952 KB |
Output is correct |
7 |
Correct |
1198 ms |
30524 KB |
Output is correct |
8 |
Correct |
1175 ms |
30648 KB |
Output is correct |
9 |
Correct |
1201 ms |
33992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
15960 KB |
Output is correct |
2 |
Correct |
1092 ms |
39640 KB |
Output is correct |
3 |
Correct |
1122 ms |
35032 KB |
Output is correct |
4 |
Correct |
1195 ms |
36080 KB |
Output is correct |
5 |
Correct |
1216 ms |
40344 KB |
Output is correct |
6 |
Correct |
1207 ms |
37084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1367 ms |
43904 KB |
Output is correct |
2 |
Correct |
1382 ms |
43516 KB |
Output is correct |
3 |
Correct |
1388 ms |
43540 KB |
Output is correct |
4 |
Correct |
1393 ms |
43344 KB |
Output is correct |
5 |
Correct |
1389 ms |
39760 KB |
Output is correct |
6 |
Correct |
1397 ms |
39760 KB |
Output is correct |
7 |
Correct |
1287 ms |
38408 KB |
Output is correct |
8 |
Correct |
1281 ms |
38064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
15960 KB |
Output is correct |
2 |
Correct |
4 ms |
15960 KB |
Output is correct |
3 |
Correct |
4 ms |
15964 KB |
Output is correct |
4 |
Correct |
4 ms |
15960 KB |
Output is correct |
5 |
Correct |
4 ms |
15960 KB |
Output is correct |
6 |
Correct |
4 ms |
15960 KB |
Output is correct |
7 |
Correct |
4 ms |
15964 KB |
Output is correct |
8 |
Correct |
4 ms |
16164 KB |
Output is correct |
9 |
Correct |
4 ms |
15960 KB |
Output is correct |
10 |
Correct |
4 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 |
8 ms |
16216 KB |
Output is correct |
14 |
Correct |
10 ms |
16216 KB |
Output is correct |
15 |
Correct |
8 ms |
16216 KB |
Output is correct |
16 |
Correct |
8 ms |
16216 KB |
Output is correct |
17 |
Correct |
8 ms |
16216 KB |
Output is correct |
18 |
Correct |
8 ms |
16216 KB |
Output is correct |
19 |
Correct |
8 ms |
16216 KB |
Output is correct |
20 |
Correct |
9 ms |
16220 KB |
Output is correct |
21 |
Correct |
8 ms |
16216 KB |
Output is correct |
22 |
Correct |
9 ms |
16220 KB |
Output is correct |
23 |
Correct |
234 ms |
19964 KB |
Output is correct |
24 |
Correct |
222 ms |
19792 KB |
Output is correct |
25 |
Correct |
227 ms |
19788 KB |
Output is correct |
26 |
Correct |
212 ms |
19056 KB |
Output is correct |
27 |
Correct |
213 ms |
19060 KB |
Output is correct |
28 |
Correct |
203 ms |
19032 KB |
Output is correct |
29 |
Correct |
197 ms |
19224 KB |
Output is correct |
30 |
Correct |
199 ms |
19152 KB |
Output is correct |
31 |
Correct |
185 ms |
20940 KB |
Output is correct |
32 |
Correct |
167 ms |
20848 KB |
Output is correct |
33 |
Incorrect |
206 ms |
19860 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
15960 KB |
Output is correct |
2 |
Correct |
4 ms |
15960 KB |
Output is correct |
3 |
Correct |
4 ms |
15964 KB |
Output is correct |
4 |
Correct |
4 ms |
15960 KB |
Output is correct |
5 |
Correct |
4 ms |
15960 KB |
Output is correct |
6 |
Correct |
4 ms |
15960 KB |
Output is correct |
7 |
Correct |
4 ms |
15964 KB |
Output is correct |
8 |
Correct |
4 ms |
16164 KB |
Output is correct |
9 |
Correct |
4 ms |
15960 KB |
Output is correct |
10 |
Correct |
4 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 |
8 ms |
16216 KB |
Output is correct |
14 |
Correct |
10 ms |
16216 KB |
Output is correct |
15 |
Correct |
8 ms |
16216 KB |
Output is correct |
16 |
Correct |
8 ms |
16216 KB |
Output is correct |
17 |
Correct |
8 ms |
16216 KB |
Output is correct |
18 |
Correct |
8 ms |
16216 KB |
Output is correct |
19 |
Correct |
8 ms |
16216 KB |
Output is correct |
20 |
Correct |
9 ms |
16220 KB |
Output is correct |
21 |
Correct |
8 ms |
16216 KB |
Output is correct |
22 |
Correct |
9 ms |
16220 KB |
Output is correct |
23 |
Correct |
1293 ms |
37864 KB |
Output is correct |
24 |
Correct |
1297 ms |
37964 KB |
Output is correct |
25 |
Correct |
1200 ms |
32836 KB |
Output is correct |
26 |
Correct |
1282 ms |
37016 KB |
Output is correct |
27 |
Correct |
1300 ms |
36952 KB |
Output is correct |
28 |
Correct |
1198 ms |
30524 KB |
Output is correct |
29 |
Correct |
1175 ms |
30648 KB |
Output is correct |
30 |
Correct |
1201 ms |
33992 KB |
Output is correct |
31 |
Correct |
1092 ms |
39640 KB |
Output is correct |
32 |
Correct |
1122 ms |
35032 KB |
Output is correct |
33 |
Correct |
1195 ms |
36080 KB |
Output is correct |
34 |
Correct |
1216 ms |
40344 KB |
Output is correct |
35 |
Correct |
1207 ms |
37084 KB |
Output is correct |
36 |
Correct |
1367 ms |
43904 KB |
Output is correct |
37 |
Correct |
1382 ms |
43516 KB |
Output is correct |
38 |
Correct |
1388 ms |
43540 KB |
Output is correct |
39 |
Correct |
1393 ms |
43344 KB |
Output is correct |
40 |
Correct |
1389 ms |
39760 KB |
Output is correct |
41 |
Correct |
1397 ms |
39760 KB |
Output is correct |
42 |
Correct |
1287 ms |
38408 KB |
Output is correct |
43 |
Correct |
1281 ms |
38064 KB |
Output is correct |
44 |
Correct |
234 ms |
19964 KB |
Output is correct |
45 |
Correct |
222 ms |
19792 KB |
Output is correct |
46 |
Correct |
227 ms |
19788 KB |
Output is correct |
47 |
Correct |
212 ms |
19056 KB |
Output is correct |
48 |
Correct |
213 ms |
19060 KB |
Output is correct |
49 |
Correct |
203 ms |
19032 KB |
Output is correct |
50 |
Correct |
197 ms |
19224 KB |
Output is correct |
51 |
Correct |
199 ms |
19152 KB |
Output is correct |
52 |
Correct |
185 ms |
20940 KB |
Output is correct |
53 |
Correct |
167 ms |
20848 KB |
Output is correct |
54 |
Incorrect |
206 ms |
19860 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |