#include <bits/stdc++.h>
#define suiii ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define co cout<<
//#pragma GCC optimize("O3,Ofast,unroll-loops")
//#pragma GCC target("avx2,sse3,sse4,avx")
using namespace std;
//stuff
const ll N=exp2(ceil(log2(5e5)));
ll n,x;
ll arr[1000001];
ll arr1[1000001];
ll tre[N*4][2];
ll que(ll l,ll r,ll i,ll lq,ll rq,ll type){
if(l>rq||r<lq) return 0;
if(r<=rq&&l>=lq){
return tre[i][type];
}
ll mid=(l+r)/2;
return max(que(l,mid,i*2,lq,rq,type),que(mid+1,r,i*2+1,lq,rq,type));
}
void upd(ll idx,ll val,ll type){
idx+=N;
tre[idx][type]=max(tre[idx][type],val);
idx/=2;
while(idx){
tre[idx][type]=max(tre[idx*2][type],tre[idx*2+1][type]);
idx/=2;
}
}
ll cnt=0;
void solve(){
cin>>n>>x;
for(int i=0;i<n;i++){
cin>>arr[i];
arr1[cnt]=arr[i];
cnt++;
arr1[cnt]=arr[i]+x;
cnt++;
}
sort(arr1,arr1+cnt);
for(int i=0;i<n;i++){
ll idx=lower_bound(arr1,arr1+cnt,arr[i])-arr1-1;
ll last=lower_bound(arr1,arr1+cnt,arr[i]+x)-arr1-1;
ll val=que(0,N-1,1,0,idx,0)+1;
ll val1=que(0,N-1,1,1,last,0)+1;
ll val2=que(0,N-1,1,1,idx,1)+1;
upd(idx+1,val,0);
upd(idx+1,val1,1);
upd(idx+1,val2,1);
}
co max(tre[1][0],tre[1][1]);
}
int main()
{
suiii
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
307 ms |
23128 KB |
Output is correct |
2 |
Correct |
290 ms |
23124 KB |
Output is correct |
3 |
Correct |
286 ms |
23120 KB |
Output is correct |
4 |
Correct |
281 ms |
23132 KB |
Output is correct |
5 |
Correct |
151 ms |
18344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
9696 KB |
Output is correct |
2 |
Correct |
71 ms |
11100 KB |
Output is correct |
3 |
Correct |
65 ms |
11096 KB |
Output is correct |
4 |
Correct |
36 ms |
9944 KB |
Output is correct |
5 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
147 ms |
11604 KB |
Output is correct |
2 |
Correct |
134 ms |
11732 KB |
Output is correct |
3 |
Correct |
263 ms |
17016 KB |
Output is correct |
4 |
Correct |
165 ms |
15092 KB |
Output is correct |
5 |
Correct |
86 ms |
11604 KB |
Output is correct |
6 |
Correct |
140 ms |
17224 KB |
Output is correct |
7 |
Incorrect |
158 ms |
16464 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |