#include<bits/stdc++.h>
#define MAXN 200007
using namespace std;
const long long inf=1e9;
struct ST{
struct node{
int l,r,val;
};
node tree[100*MAXN];
int num;
void init(){
num=1;
tree[num]={0,0,0};
}
void addnode(){
num++;
tree[num]={0,0,0};
}
void check(int v){
if(tree[v].l==0){
addnode(); tree[v].l=num;
}
if(tree[v].r==0){
addnode(); tree[v].r=num;
}
}
void update(int v,long long l,long long r,long long pos,int val){
if(l==r){
tree[v].val=max(tree[v].val,val);
}else{
long long tt=(l+r)/2;
check(v);
if(pos<=tt)update(tree[v].l,l,tt,pos,val);
else update(tree[v].r,tt+1,r,pos,val);
tree[v].val=max(tree[tree[v].l].val,tree[tree[v].r].val);
}
}
int getmax(int v,long long l,long long r,long long ll,long long rr){
if(ll>rr or v==0)return 0;
if(l==ll and r==rr){
return tree[v].val;
}else{
long long tt=(l+r)/2;
return max( getmax(tree[v].l,l,tt,ll,min(tt,rr)) , getmax(tree[v].r,tt+1,r,max(tt+1,ll),rr) );
}
}
}seg[3];
int n,a[MAXN],ans,x;
int dp[MAXN][3];
int solve(int d){
seg[0].init();
seg[1].init();
seg[2].init();
int res=0;
for(int i=1;i<=n;i++){
dp[i][0]=seg[0].getmax(1,0,3*inf,0,a[i]-1)+1;
dp[i][1]=max(seg[1].getmax(1,0,3*inf,0,a[i]-1)+1 , seg[0].getmax(1,0,3*inf,0,a[i]+d-1)+1);
dp[i][2]=max(seg[2].getmax(1,0,3*inf,0,a[i]-1)+1 , seg[1].getmax(1,0,3*inf,0,a[i]-d-1)+1);
seg[0].update(1,0,3*inf,a[i],dp[i][0]);
seg[1].update(1,0,3*inf,a[i],dp[i][1]);
seg[2].update(1,0,3*inf,a[i],dp[i][2]);
res=max(res,max(dp[i][0],max(dp[i][1],dp[i][2])));
}
return res;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>x;
for(int i=1;i<=n;i++){
cin>>a[i];
a[i]+=inf+1;
}
cout<<max(solve(-x),solve(x))<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
404 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
404 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
404 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
4 ms |
1884 KB |
Output is correct |
20 |
Correct |
4 ms |
1924 KB |
Output is correct |
21 |
Correct |
4 ms |
1884 KB |
Output is correct |
22 |
Correct |
4 ms |
1928 KB |
Output is correct |
23 |
Correct |
3 ms |
1116 KB |
Output is correct |
24 |
Correct |
3 ms |
1116 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
3 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1056 ms |
179028 KB |
Output is correct |
2 |
Correct |
862 ms |
179024 KB |
Output is correct |
3 |
Correct |
872 ms |
179028 KB |
Output is correct |
4 |
Correct |
872 ms |
179028 KB |
Output is correct |
5 |
Correct |
479 ms |
98384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
182 ms |
52048 KB |
Output is correct |
2 |
Correct |
187 ms |
52004 KB |
Output is correct |
3 |
Correct |
192 ms |
52052 KB |
Output is correct |
4 |
Correct |
138 ms |
28240 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
123 ms |
4624 KB |
Output is correct |
7 |
Correct |
154 ms |
36260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
371 ms |
96736 KB |
Output is correct |
2 |
Correct |
386 ms |
96592 KB |
Output is correct |
3 |
Correct |
819 ms |
179140 KB |
Output is correct |
4 |
Correct |
435 ms |
98480 KB |
Output is correct |
5 |
Correct |
191 ms |
9076 KB |
Output is correct |
6 |
Correct |
351 ms |
16716 KB |
Output is correct |
7 |
Incorrect |
351 ms |
16724 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
404 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
4 ms |
1884 KB |
Output is correct |
20 |
Correct |
4 ms |
1924 KB |
Output is correct |
21 |
Correct |
4 ms |
1884 KB |
Output is correct |
22 |
Correct |
4 ms |
1928 KB |
Output is correct |
23 |
Correct |
3 ms |
1116 KB |
Output is correct |
24 |
Correct |
3 ms |
1116 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
3 ms |
344 KB |
Output is correct |
27 |
Correct |
1056 ms |
179028 KB |
Output is correct |
28 |
Correct |
862 ms |
179024 KB |
Output is correct |
29 |
Correct |
872 ms |
179028 KB |
Output is correct |
30 |
Correct |
872 ms |
179028 KB |
Output is correct |
31 |
Correct |
479 ms |
98384 KB |
Output is correct |
32 |
Correct |
182 ms |
52048 KB |
Output is correct |
33 |
Correct |
187 ms |
52004 KB |
Output is correct |
34 |
Correct |
192 ms |
52052 KB |
Output is correct |
35 |
Correct |
138 ms |
28240 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
123 ms |
4624 KB |
Output is correct |
38 |
Correct |
154 ms |
36260 KB |
Output is correct |
39 |
Correct |
371 ms |
96736 KB |
Output is correct |
40 |
Correct |
386 ms |
96592 KB |
Output is correct |
41 |
Correct |
819 ms |
179140 KB |
Output is correct |
42 |
Correct |
435 ms |
98480 KB |
Output is correct |
43 |
Correct |
191 ms |
9076 KB |
Output is correct |
44 |
Correct |
351 ms |
16716 KB |
Output is correct |
45 |
Incorrect |
351 ms |
16724 KB |
Output isn't correct |
46 |
Halted |
0 ms |
0 KB |
- |