#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
#define pll vector<pair<ll,ll>>
using namespace std;/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>*/
template<class S,class T>
bool chmin(S &a,const T &b) {
return a>b?(a=b)==b:false;
}
template<class S,class T>
bool chmax(S &a,const T &b) {
return a<b?(a=b)==b:false;
}
//void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const ll inf=1e18;
const ll mod=998244353;
const ll N=1e6+5;
const ld eps=1e-9;
vll t0(N*4),t1(N*4);
void upd(ll id,ll pos,ll val,ll v=1,ll tl=1,ll tr=N){
if(tl>pos || tr<pos) return;
if(tl==tr){
if(!id) chmax(t0[v],val);
chmax(t1[v],val);
return;
}
ll tm=(tl+tr)/2;
upd(id,pos,val,v*2,tl,tm);
upd(id,pos,val,v*2+1,tm+1,tr);
t0[v]=max(t0[v*2],t0[v*2+1]);
t1[v]=max(t1[v*2],t1[v*2+1]);
}
ll get(ll id,ll l,ll r,ll v=1,ll tl=1,ll tr=N){
if(tl>r || tr<l) return 0;
if(l<=tl && tr<=r)return (id ? max(t1[v],t0[v]) : t0[v]);
ll tm=(tl+tr)/2;
return max(get(id,l,r,v*2,tl,tm),get(id,l,r,v*2+1,tm+1,tr));
}
void solve(){
ll i,j;
ll n,x;
cin>>n>>x;
ll a[n+5];
set<ll> st;
for(i=1;i<=n;i++){
cin>>a[i];
st.ins(a[i]);
st.ins(a[i]+x);
}
map<ll,ll> pos;
ll c=1;
for(auto i : st){
pos[i]=c++;
}
for(i=1;i<=n;i++){
ll y2=get(1,1,pos[a[i]+x]-1);
upd(1,pos[a[i]+x],y2+1);
ll y=get(0,1,pos[a[i]]-1);
upd(0,pos[a[i]],y+1);
}
cout<<get(1,1,st.sz+5)<<endl;
}
signed main(){
start();
ll t=1;
//cin>>t;
while(t--) solve();
return 0;
}
/*
6
3 8 7 1 6 6
0 -1 9 1 2 0
*/
Compilation message
glo.cpp: In function 'void solve()':
glo.cpp:66:10: warning: unused variable 'j' [-Wunused-variable]
66 | ll i,j;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
63068 KB |
Output is correct |
2 |
Correct |
9 ms |
63068 KB |
Output is correct |
3 |
Correct |
9 ms |
63064 KB |
Output is correct |
4 |
Correct |
9 ms |
63068 KB |
Output is correct |
5 |
Correct |
10 ms |
63040 KB |
Output is correct |
6 |
Correct |
9 ms |
63068 KB |
Output is correct |
7 |
Correct |
9 ms |
63064 KB |
Output is correct |
8 |
Correct |
9 ms |
63068 KB |
Output is correct |
9 |
Correct |
9 ms |
63068 KB |
Output is correct |
10 |
Correct |
8 ms |
63068 KB |
Output is correct |
11 |
Correct |
9 ms |
63068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
63068 KB |
Output is correct |
2 |
Correct |
9 ms |
63068 KB |
Output is correct |
3 |
Correct |
9 ms |
63064 KB |
Output is correct |
4 |
Correct |
9 ms |
63068 KB |
Output is correct |
5 |
Correct |
10 ms |
63040 KB |
Output is correct |
6 |
Correct |
9 ms |
63068 KB |
Output is correct |
7 |
Correct |
9 ms |
63064 KB |
Output is correct |
8 |
Correct |
9 ms |
63068 KB |
Output is correct |
9 |
Correct |
9 ms |
63068 KB |
Output is correct |
10 |
Correct |
8 ms |
63068 KB |
Output is correct |
11 |
Correct |
9 ms |
63068 KB |
Output is correct |
12 |
Correct |
9 ms |
63068 KB |
Output is correct |
13 |
Correct |
9 ms |
63068 KB |
Output is correct |
14 |
Correct |
9 ms |
62920 KB |
Output is correct |
15 |
Correct |
10 ms |
63068 KB |
Output is correct |
16 |
Correct |
9 ms |
63068 KB |
Output is correct |
17 |
Correct |
9 ms |
63068 KB |
Output is correct |
18 |
Correct |
9 ms |
63068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
63068 KB |
Output is correct |
2 |
Correct |
9 ms |
63068 KB |
Output is correct |
3 |
Correct |
9 ms |
63064 KB |
Output is correct |
4 |
Correct |
9 ms |
63068 KB |
Output is correct |
5 |
Correct |
10 ms |
63040 KB |
Output is correct |
6 |
Correct |
9 ms |
63068 KB |
Output is correct |
7 |
Correct |
9 ms |
63064 KB |
Output is correct |
8 |
Correct |
9 ms |
63068 KB |
Output is correct |
9 |
Correct |
9 ms |
63068 KB |
Output is correct |
10 |
Correct |
8 ms |
63068 KB |
Output is correct |
11 |
Correct |
9 ms |
63068 KB |
Output is correct |
12 |
Correct |
9 ms |
63068 KB |
Output is correct |
13 |
Correct |
9 ms |
63068 KB |
Output is correct |
14 |
Correct |
9 ms |
62920 KB |
Output is correct |
15 |
Correct |
10 ms |
63068 KB |
Output is correct |
16 |
Correct |
9 ms |
63068 KB |
Output is correct |
17 |
Correct |
9 ms |
63068 KB |
Output is correct |
18 |
Correct |
9 ms |
63068 KB |
Output is correct |
19 |
Correct |
10 ms |
63064 KB |
Output is correct |
20 |
Correct |
11 ms |
63068 KB |
Output is correct |
21 |
Correct |
10 ms |
63068 KB |
Output is correct |
22 |
Correct |
10 ms |
63064 KB |
Output is correct |
23 |
Correct |
10 ms |
63068 KB |
Output is correct |
24 |
Correct |
10 ms |
63168 KB |
Output is correct |
25 |
Correct |
10 ms |
63068 KB |
Output is correct |
26 |
Correct |
11 ms |
63068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
559 ms |
86544 KB |
Output is correct |
2 |
Correct |
469 ms |
86532 KB |
Output is correct |
3 |
Correct |
452 ms |
86384 KB |
Output is correct |
4 |
Correct |
494 ms |
86540 KB |
Output is correct |
5 |
Correct |
240 ms |
75344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
74196 KB |
Output is correct |
2 |
Correct |
116 ms |
74396 KB |
Output is correct |
3 |
Correct |
112 ms |
74408 KB |
Output is correct |
4 |
Correct |
73 ms |
68700 KB |
Output is correct |
5 |
Correct |
9 ms |
63068 KB |
Output is correct |
6 |
Correct |
73 ms |
68896 KB |
Output is correct |
7 |
Correct |
102 ms |
72596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
313 ms |
85584 KB |
Output is correct |
2 |
Correct |
328 ms |
85844 KB |
Output is correct |
3 |
Correct |
898 ms |
108624 KB |
Output is correct |
4 |
Correct |
285 ms |
86440 KB |
Output is correct |
5 |
Correct |
188 ms |
85588 KB |
Output is correct |
6 |
Correct |
359 ms |
106516 KB |
Output is correct |
7 |
Correct |
376 ms |
106068 KB |
Output is correct |
8 |
Correct |
235 ms |
85960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
63068 KB |
Output is correct |
2 |
Correct |
9 ms |
63068 KB |
Output is correct |
3 |
Correct |
9 ms |
63064 KB |
Output is correct |
4 |
Correct |
9 ms |
63068 KB |
Output is correct |
5 |
Correct |
10 ms |
63040 KB |
Output is correct |
6 |
Correct |
9 ms |
63068 KB |
Output is correct |
7 |
Correct |
9 ms |
63064 KB |
Output is correct |
8 |
Correct |
9 ms |
63068 KB |
Output is correct |
9 |
Correct |
9 ms |
63068 KB |
Output is correct |
10 |
Correct |
8 ms |
63068 KB |
Output is correct |
11 |
Correct |
9 ms |
63068 KB |
Output is correct |
12 |
Correct |
9 ms |
63068 KB |
Output is correct |
13 |
Correct |
9 ms |
63068 KB |
Output is correct |
14 |
Correct |
9 ms |
62920 KB |
Output is correct |
15 |
Correct |
10 ms |
63068 KB |
Output is correct |
16 |
Correct |
9 ms |
63068 KB |
Output is correct |
17 |
Correct |
9 ms |
63068 KB |
Output is correct |
18 |
Correct |
9 ms |
63068 KB |
Output is correct |
19 |
Correct |
10 ms |
63064 KB |
Output is correct |
20 |
Correct |
11 ms |
63068 KB |
Output is correct |
21 |
Correct |
10 ms |
63068 KB |
Output is correct |
22 |
Correct |
10 ms |
63064 KB |
Output is correct |
23 |
Correct |
10 ms |
63068 KB |
Output is correct |
24 |
Correct |
10 ms |
63168 KB |
Output is correct |
25 |
Correct |
10 ms |
63068 KB |
Output is correct |
26 |
Correct |
11 ms |
63068 KB |
Output is correct |
27 |
Correct |
559 ms |
86544 KB |
Output is correct |
28 |
Correct |
469 ms |
86532 KB |
Output is correct |
29 |
Correct |
452 ms |
86384 KB |
Output is correct |
30 |
Correct |
494 ms |
86540 KB |
Output is correct |
31 |
Correct |
240 ms |
75344 KB |
Output is correct |
32 |
Correct |
114 ms |
74196 KB |
Output is correct |
33 |
Correct |
116 ms |
74396 KB |
Output is correct |
34 |
Correct |
112 ms |
74408 KB |
Output is correct |
35 |
Correct |
73 ms |
68700 KB |
Output is correct |
36 |
Correct |
9 ms |
63068 KB |
Output is correct |
37 |
Correct |
73 ms |
68896 KB |
Output is correct |
38 |
Correct |
102 ms |
72596 KB |
Output is correct |
39 |
Correct |
313 ms |
85584 KB |
Output is correct |
40 |
Correct |
328 ms |
85844 KB |
Output is correct |
41 |
Correct |
898 ms |
108624 KB |
Output is correct |
42 |
Correct |
285 ms |
86440 KB |
Output is correct |
43 |
Correct |
188 ms |
85588 KB |
Output is correct |
44 |
Correct |
359 ms |
106516 KB |
Output is correct |
45 |
Correct |
376 ms |
106068 KB |
Output is correct |
46 |
Correct |
235 ms |
85960 KB |
Output is correct |
47 |
Correct |
277 ms |
85592 KB |
Output is correct |
48 |
Correct |
277 ms |
85764 KB |
Output is correct |
49 |
Correct |
690 ms |
108236 KB |
Output is correct |
50 |
Correct |
283 ms |
86540 KB |
Output is correct |
51 |
Correct |
224 ms |
80468 KB |
Output is correct |
52 |
Correct |
300 ms |
86664 KB |
Output is correct |
53 |
Correct |
377 ms |
108280 KB |
Output is correct |
54 |
Correct |
393 ms |
108628 KB |
Output is correct |
55 |
Correct |
418 ms |
101240 KB |
Output is correct |