#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-1,0)+1;
if(arr[last]==arr[i]+x) last--;
ll val1=que(0,N-1,1,1,last,0)+1;
ll val2=que(0,N-1,1,1,idx-1,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 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
243 ms |
13104 KB |
Output is correct |
2 |
Correct |
249 ms |
9812 KB |
Output is correct |
3 |
Correct |
218 ms |
13916 KB |
Output is correct |
4 |
Correct |
212 ms |
14752 KB |
Output is correct |
5 |
Incorrect |
130 ms |
11856 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
49 ms |
8028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
11816 KB |
Output is correct |
2 |
Correct |
87 ms |
11612 KB |
Output is correct |
3 |
Correct |
188 ms |
14940 KB |
Output is correct |
4 |
Correct |
122 ms |
11888 KB |
Output is correct |
5 |
Correct |
70 ms |
12368 KB |
Output is correct |
6 |
Correct |
123 ms |
15596 KB |
Output is correct |
7 |
Incorrect |
126 ms |
16448 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |