#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(1e6)));
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
8792 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
1 ms |
10588 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
8792 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
1 ms |
10588 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
8792 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
1 ms |
10588 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
298 ms |
17724 KB |
Output is correct |
2 |
Correct |
292 ms |
17716 KB |
Output is correct |
3 |
Correct |
283 ms |
22052 KB |
Output is correct |
4 |
Correct |
256 ms |
23124 KB |
Output is correct |
5 |
Correct |
149 ms |
20852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
11624 KB |
Output is correct |
2 |
Correct |
59 ms |
11100 KB |
Output is correct |
3 |
Correct |
72 ms |
11240 KB |
Output is correct |
4 |
Correct |
38 ms |
3156 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
127 ms |
11868 KB |
Output is correct |
2 |
Correct |
137 ms |
11848 KB |
Output is correct |
3 |
Correct |
297 ms |
16884 KB |
Output is correct |
4 |
Correct |
177 ms |
12880 KB |
Output is correct |
5 |
Correct |
91 ms |
11744 KB |
Output is correct |
6 |
Correct |
161 ms |
18904 KB |
Output is correct |
7 |
Incorrect |
163 ms |
10932 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
8792 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
10588 KB |
Output is correct |
7 |
Correct |
1 ms |
10588 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |