#include <bits/stdc++.h>
using namespace std;
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
typedef long long int ll;
#define all(a) a.begin(),a.end()
const int MAXN = 2e5+5;
int a[MAXN],b[MAXN];
int t[4*MAXN];
void upd(int v,int l,int r,int pos,int val){
if(l==r){
t[v] = max(t[v],val);
return;
}
int tm = (l+r)/2;
if(pos<=tm)upd(2*v,l,tm,pos,val);
else upd(2*v+1,tm+1,r,pos,val);
t[v] = max(t[2*v],t[2*v+1]);
}
int query(int v,int l,int r,int tl,int tr){
if(l>r)return 0;
if(l==tl && r==tr)return t[v];
int tm = (tl+tr)/2;
return max(query(2*v,l,min(r,tm),tl,tm),
query(2*v+1,max(l,tm+1),r,tm+1,tr));
}
int dp[MAXN];
int main()
{
owo
int n,x;
cin>>n>>x;
vector<int>c = {0};
for(int i=0;i<n;i++){
cin>>a[i];
b[i] = a[i];
c.push_back(a[i]);
}
sort(all(c));
c.resize(unique(all(c)) - c.begin());
for(int i=0;i<n;i++)a[i] = lower_bound(all(c),a[i]) - c.begin()+1;
int rn = c.size();
//cout<<rn<<'\n';
for(int i=n-1;i>=0;i--){
dp[i] = query(1,a[i]+1,rn,1,rn) + 1;
upd(1,1,rn,a[i],dp[i]);
}
//for(int i=0;i<n;i++)cout<<dp[i]<<" ";
//cout<<'\n';
for(int i=0;i<=4*n+10;i++)t[i] = 0;
int ans = 1;
for(int i=0;i<n;i++){
int cur = 0;
int p = lower_bound(all(c),b[i]+x) - c.begin() + 1;
cur = query(1,1,p-1,1,rn);
ans = max(ans,cur+dp[i]);
cur = query(1,1,a[i]-1,1,rn)+1;
upd(1,1,rn,a[i],cur);
//cout<<i<<" "<<cur<<'\n';
}
cout<<ans<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
392 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
289 ms |
8508 KB |
Output is correct |
2 |
Correct |
284 ms |
8300 KB |
Output is correct |
3 |
Correct |
241 ms |
8320 KB |
Output is correct |
4 |
Correct |
272 ms |
8292 KB |
Output is correct |
5 |
Correct |
136 ms |
7820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
2452 KB |
Output is correct |
2 |
Correct |
58 ms |
2440 KB |
Output is correct |
3 |
Correct |
67 ms |
2436 KB |
Output is correct |
4 |
Correct |
34 ms |
2240 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
34 ms |
2236 KB |
Output is correct |
7 |
Correct |
48 ms |
2456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
4440 KB |
Output is correct |
2 |
Correct |
125 ms |
4584 KB |
Output is correct |
3 |
Correct |
205 ms |
8560 KB |
Output is correct |
4 |
Correct |
116 ms |
7808 KB |
Output is correct |
5 |
Correct |
63 ms |
4060 KB |
Output is correct |
6 |
Correct |
120 ms |
7780 KB |
Output is correct |
7 |
Correct |
124 ms |
8260 KB |
Output is correct |
8 |
Correct |
79 ms |
4528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
392 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
289 ms |
8508 KB |
Output is correct |
28 |
Correct |
284 ms |
8300 KB |
Output is correct |
29 |
Correct |
241 ms |
8320 KB |
Output is correct |
30 |
Correct |
272 ms |
8292 KB |
Output is correct |
31 |
Correct |
136 ms |
7820 KB |
Output is correct |
32 |
Correct |
60 ms |
2452 KB |
Output is correct |
33 |
Correct |
58 ms |
2440 KB |
Output is correct |
34 |
Correct |
67 ms |
2436 KB |
Output is correct |
35 |
Correct |
34 ms |
2240 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
34 ms |
2236 KB |
Output is correct |
38 |
Correct |
48 ms |
2456 KB |
Output is correct |
39 |
Correct |
93 ms |
4440 KB |
Output is correct |
40 |
Correct |
125 ms |
4584 KB |
Output is correct |
41 |
Correct |
205 ms |
8560 KB |
Output is correct |
42 |
Correct |
116 ms |
7808 KB |
Output is correct |
43 |
Correct |
63 ms |
4060 KB |
Output is correct |
44 |
Correct |
120 ms |
7780 KB |
Output is correct |
45 |
Correct |
124 ms |
8260 KB |
Output is correct |
46 |
Correct |
79 ms |
4528 KB |
Output is correct |
47 |
Correct |
125 ms |
4480 KB |
Output is correct |
48 |
Correct |
128 ms |
4528 KB |
Output is correct |
49 |
Correct |
250 ms |
8636 KB |
Output is correct |
50 |
Correct |
142 ms |
7756 KB |
Output is correct |
51 |
Correct |
112 ms |
6024 KB |
Output is correct |
52 |
Correct |
176 ms |
7976 KB |
Output is correct |
53 |
Correct |
131 ms |
7880 KB |
Output is correct |
54 |
Correct |
134 ms |
8612 KB |
Output is correct |
55 |
Correct |
214 ms |
8644 KB |
Output is correct |