#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]=-4e9;
for(long long i=1;i<=n;i++) d[i]=4e9;
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]=4e9;
long long ans=ls;
dc[0]=4e9;
for(long long i=1;i<=n;i++) dc[i]=-4e9;
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]==4e9) 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];
}
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;
}
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
6492 KB |
Output is correct |
5 |
Correct |
0 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
0 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 |
0 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
6492 KB |
Output is correct |
5 |
Correct |
0 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
0 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 |
0 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6588 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 |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
6492 KB |
Output is correct |
5 |
Correct |
0 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
0 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 |
0 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6588 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 |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
8020 KB |
Output is correct |
2 |
Correct |
61 ms |
8124 KB |
Output is correct |
3 |
Correct |
60 ms |
8176 KB |
Output is correct |
4 |
Correct |
59 ms |
8020 KB |
Output is correct |
5 |
Correct |
44 ms |
8236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
6748 KB |
Output is correct |
2 |
Correct |
15 ms |
6592 KB |
Output is correct |
3 |
Correct |
14 ms |
6748 KB |
Output is correct |
4 |
Correct |
11 ms |
6596 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
11 ms |
6748 KB |
Output is correct |
7 |
Correct |
14 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
6736 KB |
Output is correct |
2 |
Correct |
29 ms |
6744 KB |
Output is correct |
3 |
Correct |
63 ms |
8020 KB |
Output is correct |
4 |
Correct |
43 ms |
8028 KB |
Output is correct |
5 |
Correct |
21 ms |
6748 KB |
Output is correct |
6 |
Correct |
41 ms |
8020 KB |
Output is correct |
7 |
Correct |
54 ms |
8024 KB |
Output is correct |
8 |
Correct |
27 ms |
6744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
6492 KB |
Output is correct |
5 |
Correct |
0 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6488 KB |
Output is correct |
7 |
Correct |
0 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 |
0 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6588 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 |
- |