#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,x,v[200005],ans,dp[200005],maxim[200005],minim[200005],pref[200005];
ll getLIS()
{
ll rez=0;
for(int i=1;i<=n;i++)
maxim[i]=-3e9;
for(int i=n;i>=1;i--)
{
int lg=0;
int st=1;
int dr=n-i;
while(st<=dr)
{
int mij=(st+dr)/2;
if(maxim[mij]>v[i])
{
lg=mij;
st=mij+1;
}
else
dr=mij-1;
}
dp[i]=lg+1;
rez=max(rez,dp[i]);
maxim[dp[i]]=max(maxim[dp[i]],v[i]);
}
return rez;
}
void getprefLIS()
{
ll rez=0;
for(int i=1;i<=n;i++)
minim[i]=3e9;
for(int i=1;i<=n;i++)
{
ll lg=0;
ll st=1;
ll dr=i-1;
while(st<=dr)
{
ll mij=(st+dr)/2;
if(minim[mij]<v[i])
{
lg=mij;
st=mij+1;
}
else
dr=mij-1;
}
pref[i]=lg+1;
minim[pref[i]]=min(minim[pref[i]],v[i]);
}
}
int main()
{
cin>>n>>x;
for(int i=1;i<=n;i++)
cin>>v[i];
ans=getLIS();
getprefLIS();
for(ll i=1;i<=n;i++)
maxim[i]=-3e9;
for(int i=n;i>=1;i--)
{
ll val=pref[i];
ll lg=0;
ll st=1;
ll dr=n-i;
while(st<=dr)
{
ll mij=(st+dr)/2;
if(maxim[mij]>v[i]-x)
{
lg=mij;
st=mij+1;
}
else
dr=mij-1;
}
ans=max(ans,val+lg);
maxim[dp[i]]=max(maxim[dp[i]],v[i]);
}
cout<<ans;
return 0;
}
Compilation message
glo.cpp: In function 'void getprefLIS()':
glo.cpp:35:8: warning: unused variable 'rez' [-Wunused-variable]
35 | ll rez=0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
276 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
352 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
276 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
352 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
276 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
352 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
126 ms |
8012 KB |
Output is correct |
2 |
Correct |
118 ms |
8056 KB |
Output is correct |
3 |
Correct |
114 ms |
8092 KB |
Output is correct |
4 |
Correct |
120 ms |
8100 KB |
Output is correct |
5 |
Correct |
68 ms |
8060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
2224 KB |
Output is correct |
2 |
Correct |
29 ms |
2252 KB |
Output is correct |
3 |
Correct |
29 ms |
2232 KB |
Output is correct |
4 |
Correct |
18 ms |
2252 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
17 ms |
2200 KB |
Output is correct |
7 |
Correct |
27 ms |
2176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
4164 KB |
Output is correct |
2 |
Correct |
50 ms |
4088 KB |
Output is correct |
3 |
Correct |
115 ms |
8004 KB |
Output is correct |
4 |
Correct |
73 ms |
8100 KB |
Output is correct |
5 |
Correct |
41 ms |
4176 KB |
Output is correct |
6 |
Correct |
88 ms |
7708 KB |
Output is correct |
7 |
Correct |
98 ms |
7648 KB |
Output is correct |
8 |
Correct |
47 ms |
4164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
276 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
352 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
126 ms |
8012 KB |
Output is correct |
28 |
Correct |
118 ms |
8056 KB |
Output is correct |
29 |
Correct |
114 ms |
8092 KB |
Output is correct |
30 |
Correct |
120 ms |
8100 KB |
Output is correct |
31 |
Correct |
68 ms |
8060 KB |
Output is correct |
32 |
Correct |
29 ms |
2224 KB |
Output is correct |
33 |
Correct |
29 ms |
2252 KB |
Output is correct |
34 |
Correct |
29 ms |
2232 KB |
Output is correct |
35 |
Correct |
18 ms |
2252 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
17 ms |
2200 KB |
Output is correct |
38 |
Correct |
27 ms |
2176 KB |
Output is correct |
39 |
Correct |
54 ms |
4164 KB |
Output is correct |
40 |
Correct |
50 ms |
4088 KB |
Output is correct |
41 |
Correct |
115 ms |
8004 KB |
Output is correct |
42 |
Correct |
73 ms |
8100 KB |
Output is correct |
43 |
Correct |
41 ms |
4176 KB |
Output is correct |
44 |
Correct |
88 ms |
7708 KB |
Output is correct |
45 |
Correct |
98 ms |
7648 KB |
Output is correct |
46 |
Correct |
47 ms |
4164 KB |
Output is correct |
47 |
Correct |
55 ms |
4204 KB |
Output is correct |
48 |
Correct |
73 ms |
4188 KB |
Output is correct |
49 |
Correct |
126 ms |
8012 KB |
Output is correct |
50 |
Correct |
74 ms |
8104 KB |
Output is correct |
51 |
Correct |
56 ms |
6164 KB |
Output is correct |
52 |
Correct |
70 ms |
8016 KB |
Output is correct |
53 |
Correct |
82 ms |
8068 KB |
Output is correct |
54 |
Correct |
104 ms |
8052 KB |
Output is correct |
55 |
Correct |
111 ms |
7988 KB |
Output is correct |