#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(200000)));
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;
}
}
void solve(){
cin>>n>>x;
for(int i=0;i<n;i++){
cin>>arr[i];
arr1[i]=arr[i];
}
ll mx=0;
sort(arr1,arr1+n);
for(int i=0;i<n;i++){
ll idx=lower_bound(arr1,arr1+n,arr[i])-arr1;
ll last=lower_bound(arr1,arr1+n,arr[i]+x)-arr1;
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;
mx=max({mx,val,val1,val2});
upd(idx,val,0);
upd(idx,val1,1);
upd(idx,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 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
216 ms |
16864 KB |
Output is correct |
2 |
Correct |
212 ms |
16852 KB |
Output is correct |
3 |
Correct |
227 ms |
16720 KB |
Output is correct |
4 |
Correct |
224 ms |
16868 KB |
Output is correct |
5 |
Incorrect |
139 ms |
12860 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
8536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
12780 KB |
Output is correct |
2 |
Correct |
89 ms |
12788 KB |
Output is correct |
3 |
Correct |
194 ms |
16720 KB |
Output is correct |
4 |
Incorrect |
130 ms |
12988 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |