#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho
using ll=long long;
using ld=long double;
int const INF=1000000005;
ll const LINF=1000000000000000005;
ll const mod=1000000007;
ld const PI=3.14159265359;
ll const MAX_N=3e5+5;
ld const EPS=0.00000001;
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(a) (int)a.size()
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,a[2000005],dp[2000005][3],x,tree[3][400005];
map<ll,ll>val;
void update1(ll pos,ll val){
for(;pos<=2*n+1;pos+=pos&(-pos)){
tree[1][pos]=max(tree[1][pos],val);
}
}
void update2(ll pos,ll val){
for(;pos<=2*n+1;pos+=pos&(-pos)){
tree[2][pos]=max(tree[2][pos],val);
}
}
ll query1(ll pos){
ll res=0;
for(;pos;pos-=pos&(-pos)){
res=max(res,tree[1][pos]);
}
return res;
}
ll query2(ll pos){
ll res=0;
for(;pos;pos-=pos&(-pos)){
res=max(res,tree[2][pos]);
}
return res;
}
int32_t main(){
CODE_START;
#ifdef LOCAL
ifstream cin("input.txt");
#endif
cin>>n>>x;
vector<ll>v;
v.pb(x);
for(ll i=1;i<=n;i++)
{
cin>>a[i];
v.pb(a[i]);
v.pb(a[i]+x-1);
}
sort(v.begin(),v.end());
ll vl=0;
for(ll i=0;i<v.size();i++)
{
if(i==0||v[i]!=v[i-1]){
val[v[i]]=++vl;
}
}
for(ll i=1;i<=n;i++)
{
dp[i][0]=query1(val[a[i]]-1)+1;
dp[i][1]=query2(val[a[i]]-1)+1;
dp[i][1]=max(dp[i][1],query1(val[a[i]+x-1])+1);
update1(val[a[i]],dp[i][0]);
update2(val[a[i]],dp[i][1]);
}
ll ans=0;
for(ll i=1;i<=n;i++)
{
ans=max(ans,dp[i][0]);
ans=max(ans,dp[i][1]);
}
cout<<ans<<endl;
}
Compilation message
glo.cpp: In function 'int32_t main()':
glo.cpp:62:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(ll i=0;i<v.size();i++)
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
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 |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
4 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
312 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
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 |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
4 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
312 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
564 KB |
Output is correct |
20 |
Correct |
2 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
3 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
701 ms |
41140 KB |
Output is correct |
2 |
Correct |
676 ms |
41012 KB |
Output is correct |
3 |
Correct |
780 ms |
41128 KB |
Output is correct |
4 |
Correct |
622 ms |
41424 KB |
Output is correct |
5 |
Correct |
197 ms |
25716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
10724 KB |
Output is correct |
2 |
Correct |
100 ms |
11020 KB |
Output is correct |
3 |
Correct |
109 ms |
10924 KB |
Output is correct |
4 |
Correct |
56 ms |
6924 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
42 ms |
4920 KB |
Output is correct |
7 |
Correct |
71 ms |
9640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
258 ms |
19496 KB |
Output is correct |
2 |
Correct |
272 ms |
19452 KB |
Output is correct |
3 |
Correct |
665 ms |
38188 KB |
Output is correct |
4 |
Correct |
193 ms |
24120 KB |
Output is correct |
5 |
Correct |
116 ms |
19476 KB |
Output is correct |
6 |
Correct |
247 ms |
36344 KB |
Output is correct |
7 |
Correct |
228 ms |
36392 KB |
Output is correct |
8 |
Correct |
163 ms |
19460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
4 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
312 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
564 KB |
Output is correct |
20 |
Correct |
2 ms |
468 KB |
Output is correct |
21 |
Correct |
2 ms |
468 KB |
Output is correct |
22 |
Correct |
3 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
27 |
Correct |
701 ms |
41140 KB |
Output is correct |
28 |
Correct |
676 ms |
41012 KB |
Output is correct |
29 |
Correct |
780 ms |
41128 KB |
Output is correct |
30 |
Correct |
622 ms |
41424 KB |
Output is correct |
31 |
Correct |
197 ms |
25716 KB |
Output is correct |
32 |
Correct |
110 ms |
10724 KB |
Output is correct |
33 |
Correct |
100 ms |
11020 KB |
Output is correct |
34 |
Correct |
109 ms |
10924 KB |
Output is correct |
35 |
Correct |
56 ms |
6924 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
42 ms |
4920 KB |
Output is correct |
38 |
Correct |
71 ms |
9640 KB |
Output is correct |
39 |
Correct |
258 ms |
19496 KB |
Output is correct |
40 |
Correct |
272 ms |
19452 KB |
Output is correct |
41 |
Correct |
665 ms |
38188 KB |
Output is correct |
42 |
Correct |
193 ms |
24120 KB |
Output is correct |
43 |
Correct |
116 ms |
19476 KB |
Output is correct |
44 |
Correct |
247 ms |
36344 KB |
Output is correct |
45 |
Correct |
228 ms |
36392 KB |
Output is correct |
46 |
Correct |
163 ms |
19460 KB |
Output is correct |
47 |
Correct |
218 ms |
21592 KB |
Output is correct |
48 |
Correct |
228 ms |
21728 KB |
Output is correct |
49 |
Correct |
509 ms |
42892 KB |
Output is correct |
50 |
Correct |
176 ms |
26580 KB |
Output is correct |
51 |
Correct |
140 ms |
19200 KB |
Output is correct |
52 |
Correct |
192 ms |
26716 KB |
Output is correct |
53 |
Correct |
238 ms |
39136 KB |
Output is correct |
54 |
Correct |
259 ms |
39908 KB |
Output is correct |
55 |
Correct |
333 ms |
37792 KB |
Output is correct |