/**
____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|
**/
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const ll maxn = 2e5 + 10;
ll n, x, a[maxn], dp[maxn], fp[maxn];
pair < ll, ll > upd[maxn];
void solve()
{
cin >> n >> x;
for (ll i = 1; i <= n; i ++)
cin >> a[i];
ll to = 0;
dp[0] = -2e9 - 1;
for (ll i = 1; i <= n; i ++)
{
ll l = 0, r = to;
while(l <= r)
{
ll m = (l + r) / 2;
if (dp[m] < a[i])
l = m + 1;
else
r = m - 1;
}
upd[i] = {l, dp[l]};
dp[l] = a[i];
if (l > to)
to = l, upd[i].second = 2e9 + 1;
}
ll ans = to;
fp[0] = 2e9 + 1;
ll ho = 0;
for (ll i = n; i > 0; i --)
{
ll l = 0, r = ho;
while(l <= r)
{
ll m = (l + r) / 2;
if (fp[m] > a[i])
l = m + 1;
else
r = m - 1;
}
fp[l] = a[i];
if (l > ho)
ho = l;
dp[upd[i].first] = upd[i].second;
ll lf = 0, rf = to;
while(lf <= rf)
{
ll mf = (lf + rf) / 2;
if (dp[mf] - x < a[i])
lf = mf + 1;
else
rf = mf - 1;
}
if (rf + l > ans)
ans = rf + l;
}
cout << ans << endl;
}
int main()
{
solve();
return 0;
}
/**
10 10
1 1 1 1 1 1 2 2 2 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 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 |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 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 |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 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 |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 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 |
100 ms |
4992 KB |
Output is correct |
2 |
Correct |
99 ms |
4952 KB |
Output is correct |
3 |
Correct |
102 ms |
5016 KB |
Output is correct |
4 |
Correct |
101 ms |
5048 KB |
Output is correct |
5 |
Correct |
65 ms |
6508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1484 KB |
Output is correct |
2 |
Correct |
24 ms |
1476 KB |
Output is correct |
3 |
Correct |
29 ms |
1408 KB |
Output is correct |
4 |
Correct |
18 ms |
1868 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
16 ms |
1868 KB |
Output is correct |
7 |
Correct |
23 ms |
1484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
2620 KB |
Output is correct |
2 |
Correct |
45 ms |
2616 KB |
Output is correct |
3 |
Correct |
95 ms |
4940 KB |
Output is correct |
4 |
Correct |
67 ms |
6460 KB |
Output is correct |
5 |
Correct |
34 ms |
3360 KB |
Output is correct |
6 |
Correct |
61 ms |
6216 KB |
Output is correct |
7 |
Correct |
79 ms |
6212 KB |
Output is correct |
8 |
Correct |
43 ms |
2584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 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 |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 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 |
100 ms |
4992 KB |
Output is correct |
28 |
Correct |
99 ms |
4952 KB |
Output is correct |
29 |
Correct |
102 ms |
5016 KB |
Output is correct |
30 |
Correct |
101 ms |
5048 KB |
Output is correct |
31 |
Correct |
65 ms |
6508 KB |
Output is correct |
32 |
Correct |
25 ms |
1484 KB |
Output is correct |
33 |
Correct |
24 ms |
1476 KB |
Output is correct |
34 |
Correct |
29 ms |
1408 KB |
Output is correct |
35 |
Correct |
18 ms |
1868 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
16 ms |
1868 KB |
Output is correct |
38 |
Correct |
23 ms |
1484 KB |
Output is correct |
39 |
Correct |
48 ms |
2620 KB |
Output is correct |
40 |
Correct |
45 ms |
2616 KB |
Output is correct |
41 |
Correct |
95 ms |
4940 KB |
Output is correct |
42 |
Correct |
67 ms |
6460 KB |
Output is correct |
43 |
Correct |
34 ms |
3360 KB |
Output is correct |
44 |
Correct |
61 ms |
6216 KB |
Output is correct |
45 |
Correct |
79 ms |
6212 KB |
Output is correct |
46 |
Correct |
43 ms |
2584 KB |
Output is correct |
47 |
Correct |
50 ms |
2624 KB |
Output is correct |
48 |
Correct |
50 ms |
2652 KB |
Output is correct |
49 |
Correct |
100 ms |
4968 KB |
Output is correct |
50 |
Correct |
65 ms |
6464 KB |
Output is correct |
51 |
Correct |
51 ms |
5340 KB |
Output is correct |
52 |
Correct |
67 ms |
6476 KB |
Output is correct |
53 |
Correct |
65 ms |
6492 KB |
Output is correct |
54 |
Correct |
88 ms |
6440 KB |
Output is correct |
55 |
Correct |
103 ms |
6860 KB |
Output is correct |