#include<bits/stdc++.h>
using namespace std;
pair<long long,long long>step[200005];
long long a[200005],d[200005],dc[200005],ls;
int main(){
long long n,x;
cin>>n>>x;
d[0]=-2e9-1;
for(long long i=1;i<=n;i++) d[i]=2e9+1;
for(long long i=1;i<=n;i++){
cin>>a[i];
long long l=0,r=n+1;
while(l+1<r){
long long mid=(l+r)/2;
if(d[mid]<a[i]) l=mid;
else r=mid;
}
l++;
if(d[l]>a[i]){
step[i]={l,d[l]};
d[l]=a[i];
ls=max(ls,l);
}
}
d[n+1]=2e9+1;
long long ans=ls,ld=0;
dc[0]=2e9+1;
for(long long i=1;i<=n;i++) dc[i]=-2e9-1;
for(long long i=n;i>=1;i--){
if(step[i].first!=0){
d[step[i].first]=step[i].second;
if(d[step[i].first]==2e9+1) ls--;
}
a[i]+=x;
long long l=0,r=n+1;
while(l+1<r){
long long mid=(l+r)/2;
if(dc[mid]>a[i]) l=mid;
else r=mid;
}
l++;
if(dc[l]<a[i]){
dc[l]=a[i];
ld=max(ld,l);
}
l=0,r=n+1;
while(l+1<r){
long long mid=(l+r)/2;
if(dc[mid]>d[ls]) l=mid;
else r=mid;
}
ans=max(ans,ls+l);
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
0 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
0 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6488 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
0 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
0 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6488 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
0 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
0 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6488 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
8120 KB |
Output is correct |
2 |
Correct |
60 ms |
8020 KB |
Output is correct |
3 |
Correct |
60 ms |
8016 KB |
Output is correct |
4 |
Correct |
79 ms |
8016 KB |
Output is correct |
5 |
Correct |
50 ms |
8144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
6740 KB |
Output is correct |
2 |
Correct |
25 ms |
6588 KB |
Output is correct |
3 |
Correct |
18 ms |
6600 KB |
Output is correct |
4 |
Correct |
12 ms |
6596 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
19 ms |
6748 KB |
Output is correct |
7 |
Correct |
15 ms |
6744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
6748 KB |
Output is correct |
2 |
Correct |
29 ms |
6592 KB |
Output is correct |
3 |
Correct |
60 ms |
8020 KB |
Output is correct |
4 |
Correct |
52 ms |
8016 KB |
Output is correct |
5 |
Correct |
22 ms |
6744 KB |
Output is correct |
6 |
Correct |
38 ms |
7868 KB |
Output is correct |
7 |
Correct |
50 ms |
8020 KB |
Output is correct |
8 |
Correct |
27 ms |
6584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
0 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
0 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6488 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |