#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<long long, long long>
#define st first
#define nd second
#define file "test"
using namespace std;
const long long oo = 1e18;
const long long N = 2e5 + 5;
ll n, a[N], x, lis[N], lds[N];
vector <ll> dp(N, 3e9);
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#ifndef ONLINE_JUDGE
// freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
//#endif
cin >> n >> x;
for (int i = 1; i <= n; i ++)
cin >> a[i];
for (int i = n; i >= 1; i --){
lds[i] = lower_bound(dp.begin(), dp.end(), - a[i]) - dp.begin() + 1;
dp[lds[i] - 1] = -a[i];
}
dp.assign(N, 3e9);
ll ans = 0;
for (int i = 1; i <= n; i ++){
lis[i] = lower_bound(dp.begin(), dp.end(), a[i] - x) - dp.begin() + 1;
ans = max(ans, lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin() + lds[i]);
dp[lis[i] - 1] = a[i] - x;
// cout << lis[i] << ' ';
}
cout << ans;
return 0;
}
/** /\_/\
(= ._.)
/ >0 \>1
________________________
/ Brainstorming section /
/=======================/
---
===
To be frank I did not quite get your way of thinking, but let me put it my way.
Let's say we modify some subsegment [i, j] (we do not say anything about whether
some points in it will belong to our final LIS or whatever).
Let's say we move it down by y.
We can note that we in fact can move down [1, i-1] segment as well,
because moving down some prefix never decreases LIS.
So it turns out that we can in fact restrict to moving prefix [1, j] down under the assumption
that we moved our subsegment down. Moreover we can move it down as far as we can and
it will not worsen our answer, so we can restrict our move here to x what almost proves my claim.
There is second case to consider of subsegment being moved up,
in which case we see that we can move suffix [i, n] by x up, but that is
the same as moving prefix [1, i-1] down by x.
===
**/
// Before submit: spot the visible bug by reading the code.
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1868 KB |
Output is correct |
2 |
Correct |
1 ms |
1868 KB |
Output is correct |
3 |
Correct |
1 ms |
1868 KB |
Output is correct |
4 |
Correct |
1 ms |
1868 KB |
Output is correct |
5 |
Correct |
1 ms |
1868 KB |
Output is correct |
6 |
Correct |
1 ms |
1868 KB |
Output is correct |
7 |
Correct |
1 ms |
1868 KB |
Output is correct |
8 |
Correct |
2 ms |
1868 KB |
Output is correct |
9 |
Correct |
1 ms |
1900 KB |
Output is correct |
10 |
Correct |
1 ms |
1900 KB |
Output is correct |
11 |
Correct |
1 ms |
1896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1868 KB |
Output is correct |
2 |
Correct |
1 ms |
1868 KB |
Output is correct |
3 |
Correct |
1 ms |
1868 KB |
Output is correct |
4 |
Correct |
1 ms |
1868 KB |
Output is correct |
5 |
Correct |
1 ms |
1868 KB |
Output is correct |
6 |
Correct |
1 ms |
1868 KB |
Output is correct |
7 |
Correct |
1 ms |
1868 KB |
Output is correct |
8 |
Correct |
2 ms |
1868 KB |
Output is correct |
9 |
Correct |
1 ms |
1900 KB |
Output is correct |
10 |
Correct |
1 ms |
1900 KB |
Output is correct |
11 |
Correct |
1 ms |
1896 KB |
Output is correct |
12 |
Correct |
1 ms |
1868 KB |
Output is correct |
13 |
Correct |
1 ms |
1868 KB |
Output is correct |
14 |
Correct |
1 ms |
1868 KB |
Output is correct |
15 |
Correct |
1 ms |
1868 KB |
Output is correct |
16 |
Correct |
1 ms |
1868 KB |
Output is correct |
17 |
Correct |
2 ms |
1900 KB |
Output is correct |
18 |
Correct |
1 ms |
1892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1868 KB |
Output is correct |
2 |
Correct |
1 ms |
1868 KB |
Output is correct |
3 |
Correct |
1 ms |
1868 KB |
Output is correct |
4 |
Correct |
1 ms |
1868 KB |
Output is correct |
5 |
Correct |
1 ms |
1868 KB |
Output is correct |
6 |
Correct |
1 ms |
1868 KB |
Output is correct |
7 |
Correct |
1 ms |
1868 KB |
Output is correct |
8 |
Correct |
2 ms |
1868 KB |
Output is correct |
9 |
Correct |
1 ms |
1900 KB |
Output is correct |
10 |
Correct |
1 ms |
1900 KB |
Output is correct |
11 |
Correct |
1 ms |
1896 KB |
Output is correct |
12 |
Correct |
1 ms |
1868 KB |
Output is correct |
13 |
Correct |
1 ms |
1868 KB |
Output is correct |
14 |
Correct |
1 ms |
1868 KB |
Output is correct |
15 |
Correct |
1 ms |
1868 KB |
Output is correct |
16 |
Correct |
1 ms |
1868 KB |
Output is correct |
17 |
Correct |
2 ms |
1900 KB |
Output is correct |
18 |
Correct |
1 ms |
1892 KB |
Output is correct |
19 |
Correct |
1 ms |
1868 KB |
Output is correct |
20 |
Correct |
2 ms |
1868 KB |
Output is correct |
21 |
Correct |
1 ms |
1868 KB |
Output is correct |
22 |
Correct |
2 ms |
1868 KB |
Output is correct |
23 |
Correct |
2 ms |
1868 KB |
Output is correct |
24 |
Correct |
2 ms |
1868 KB |
Output is correct |
25 |
Correct |
2 ms |
1896 KB |
Output is correct |
26 |
Correct |
1 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
8388 KB |
Output is correct |
2 |
Correct |
55 ms |
8400 KB |
Output is correct |
3 |
Correct |
55 ms |
8444 KB |
Output is correct |
4 |
Correct |
52 ms |
8448 KB |
Output is correct |
5 |
Correct |
38 ms |
7724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
3532 KB |
Output is correct |
2 |
Correct |
13 ms |
3532 KB |
Output is correct |
3 |
Correct |
17 ms |
3464 KB |
Output is correct |
4 |
Correct |
12 ms |
3276 KB |
Output is correct |
5 |
Correct |
2 ms |
1972 KB |
Output is correct |
6 |
Correct |
11 ms |
3268 KB |
Output is correct |
7 |
Correct |
13 ms |
3552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
5136 KB |
Output is correct |
2 |
Correct |
24 ms |
5184 KB |
Output is correct |
3 |
Correct |
47 ms |
8384 KB |
Output is correct |
4 |
Correct |
41 ms |
7704 KB |
Output is correct |
5 |
Correct |
19 ms |
4812 KB |
Output is correct |
6 |
Correct |
31 ms |
7468 KB |
Output is correct |
7 |
Correct |
36 ms |
8188 KB |
Output is correct |
8 |
Correct |
22 ms |
5100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1868 KB |
Output is correct |
2 |
Correct |
1 ms |
1868 KB |
Output is correct |
3 |
Correct |
1 ms |
1868 KB |
Output is correct |
4 |
Correct |
1 ms |
1868 KB |
Output is correct |
5 |
Correct |
1 ms |
1868 KB |
Output is correct |
6 |
Correct |
1 ms |
1868 KB |
Output is correct |
7 |
Correct |
1 ms |
1868 KB |
Output is correct |
8 |
Correct |
2 ms |
1868 KB |
Output is correct |
9 |
Correct |
1 ms |
1900 KB |
Output is correct |
10 |
Correct |
1 ms |
1900 KB |
Output is correct |
11 |
Correct |
1 ms |
1896 KB |
Output is correct |
12 |
Correct |
1 ms |
1868 KB |
Output is correct |
13 |
Correct |
1 ms |
1868 KB |
Output is correct |
14 |
Correct |
1 ms |
1868 KB |
Output is correct |
15 |
Correct |
1 ms |
1868 KB |
Output is correct |
16 |
Correct |
1 ms |
1868 KB |
Output is correct |
17 |
Correct |
2 ms |
1900 KB |
Output is correct |
18 |
Correct |
1 ms |
1892 KB |
Output is correct |
19 |
Correct |
1 ms |
1868 KB |
Output is correct |
20 |
Correct |
2 ms |
1868 KB |
Output is correct |
21 |
Correct |
1 ms |
1868 KB |
Output is correct |
22 |
Correct |
2 ms |
1868 KB |
Output is correct |
23 |
Correct |
2 ms |
1868 KB |
Output is correct |
24 |
Correct |
2 ms |
1868 KB |
Output is correct |
25 |
Correct |
2 ms |
1896 KB |
Output is correct |
26 |
Correct |
1 ms |
1868 KB |
Output is correct |
27 |
Correct |
56 ms |
8388 KB |
Output is correct |
28 |
Correct |
55 ms |
8400 KB |
Output is correct |
29 |
Correct |
55 ms |
8444 KB |
Output is correct |
30 |
Correct |
52 ms |
8448 KB |
Output is correct |
31 |
Correct |
38 ms |
7724 KB |
Output is correct |
32 |
Correct |
14 ms |
3532 KB |
Output is correct |
33 |
Correct |
13 ms |
3532 KB |
Output is correct |
34 |
Correct |
17 ms |
3464 KB |
Output is correct |
35 |
Correct |
12 ms |
3276 KB |
Output is correct |
36 |
Correct |
2 ms |
1972 KB |
Output is correct |
37 |
Correct |
11 ms |
3268 KB |
Output is correct |
38 |
Correct |
13 ms |
3552 KB |
Output is correct |
39 |
Correct |
23 ms |
5136 KB |
Output is correct |
40 |
Correct |
24 ms |
5184 KB |
Output is correct |
41 |
Correct |
47 ms |
8384 KB |
Output is correct |
42 |
Correct |
41 ms |
7704 KB |
Output is correct |
43 |
Correct |
19 ms |
4812 KB |
Output is correct |
44 |
Correct |
31 ms |
7468 KB |
Output is correct |
45 |
Correct |
36 ms |
8188 KB |
Output is correct |
46 |
Correct |
22 ms |
5100 KB |
Output is correct |
47 |
Correct |
25 ms |
5192 KB |
Output is correct |
48 |
Correct |
28 ms |
5100 KB |
Output is correct |
49 |
Correct |
53 ms |
8372 KB |
Output is correct |
50 |
Correct |
39 ms |
7700 KB |
Output is correct |
51 |
Correct |
30 ms |
6152 KB |
Output is correct |
52 |
Correct |
36 ms |
7728 KB |
Output is correct |
53 |
Correct |
33 ms |
7708 KB |
Output is correct |
54 |
Correct |
38 ms |
8452 KB |
Output is correct |
55 |
Correct |
42 ms |
8404 KB |
Output is correct |