#include <bits/stdc++.h>
using i64 = long long;
const int inf = 1E9;
const int M = 800000;
int mx[M];
void Modify(int p, int l, int r, int i, int v) {
mx[p] = std::max(mx[p], v);
if (l == r) {
return;
}
int mid = (l + r) / 2;
if (i <= mid) {
Modify(p * 2, l, mid, i, v);
} else {
Modify(p * 2 + 1, mid + 1, r, i, v);
}
}
int Get(int p, int l, int r, int ql, int qr) {
if (l > r || l > qr || r < ql) {
return -inf;
}
if (ql <= l && r <= qr) {
return mx[p];
}
int mid = (l + r) / 2;
return std::max(Get(p * 2, l, mid, ql, qr), Get(p * 2 + 1, mid + 1, r, ql, qr));
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
n += 1;
std::vector<int> a(n);
for (int i = 1; i < n; i++) {
std::cin >> a[i];
a[i] -= i * m;
}
std::vector<int> xs = a;
std::sort(xs.begin(), xs.end());
xs.erase(std::unique(xs.begin(), xs.end()), xs.end());
int k = (int) xs.size();
for (int i = 0; i < n; i++) {
a[i] = std::lower_bound(xs.begin(), xs.end(), a[i]) - xs.begin();
}
std::vector<int> dp(n, -inf);
dp[0] = 1;
for (int i = 0; i < M; i++) {
mx[i] = -inf;
}
Modify(1, 0, k, a[0], 1);
for (int i = 1; i < n; i++) {
dp[i] = Get(1, 0, k, a[i], k) + 1;
Modify(1, 0, k, a[i], dp[i]);
}
std::cout << n - *std::max_element(dp.begin(), dp.end()) << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
3 ms |
3412 KB |
Output is correct |
5 |
Correct |
3 ms |
3348 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
3 ms |
3412 KB |
Output is correct |
9 |
Correct |
2 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3412 KB |
Output is correct |
11 |
Correct |
2 ms |
3412 KB |
Output is correct |
12 |
Correct |
2 ms |
3412 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
2 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
2 ms |
3412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
3 ms |
3412 KB |
Output is correct |
5 |
Correct |
3 ms |
3348 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
3 ms |
3412 KB |
Output is correct |
9 |
Correct |
2 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3412 KB |
Output is correct |
11 |
Correct |
2 ms |
3412 KB |
Output is correct |
12 |
Correct |
2 ms |
3412 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
2 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
2 ms |
3412 KB |
Output is correct |
17 |
Correct |
2 ms |
3412 KB |
Output is correct |
18 |
Correct |
3 ms |
3412 KB |
Output is correct |
19 |
Correct |
3 ms |
3412 KB |
Output is correct |
20 |
Correct |
3 ms |
3412 KB |
Output is correct |
21 |
Correct |
4 ms |
3412 KB |
Output is correct |
22 |
Correct |
4 ms |
3464 KB |
Output is correct |
23 |
Correct |
4 ms |
3440 KB |
Output is correct |
24 |
Correct |
3 ms |
3540 KB |
Output is correct |
25 |
Correct |
3 ms |
3408 KB |
Output is correct |
26 |
Correct |
3 ms |
3412 KB |
Output is correct |
27 |
Correct |
2 ms |
3412 KB |
Output is correct |
28 |
Correct |
3 ms |
3408 KB |
Output is correct |
29 |
Correct |
3 ms |
3408 KB |
Output is correct |
30 |
Correct |
3 ms |
3412 KB |
Output is correct |
31 |
Correct |
3 ms |
3492 KB |
Output is correct |
32 |
Correct |
3 ms |
3544 KB |
Output is correct |
33 |
Correct |
5 ms |
3412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
3 ms |
3412 KB |
Output is correct |
3 |
Correct |
3 ms |
3412 KB |
Output is correct |
4 |
Correct |
3 ms |
3412 KB |
Output is correct |
5 |
Correct |
4 ms |
3412 KB |
Output is correct |
6 |
Correct |
4 ms |
3464 KB |
Output is correct |
7 |
Correct |
4 ms |
3440 KB |
Output is correct |
8 |
Correct |
3 ms |
3540 KB |
Output is correct |
9 |
Correct |
3 ms |
3408 KB |
Output is correct |
10 |
Correct |
3 ms |
3412 KB |
Output is correct |
11 |
Correct |
2 ms |
3412 KB |
Output is correct |
12 |
Correct |
3 ms |
3408 KB |
Output is correct |
13 |
Correct |
3 ms |
3408 KB |
Output is correct |
14 |
Correct |
3 ms |
3412 KB |
Output is correct |
15 |
Correct |
3 ms |
3492 KB |
Output is correct |
16 |
Correct |
3 ms |
3544 KB |
Output is correct |
17 |
Correct |
5 ms |
3412 KB |
Output is correct |
18 |
Correct |
2 ms |
3412 KB |
Output is correct |
19 |
Correct |
2 ms |
3412 KB |
Output is correct |
20 |
Correct |
2 ms |
3412 KB |
Output is correct |
21 |
Correct |
3 ms |
3412 KB |
Output is correct |
22 |
Correct |
3 ms |
3348 KB |
Output is correct |
23 |
Correct |
2 ms |
3412 KB |
Output is correct |
24 |
Correct |
2 ms |
3412 KB |
Output is correct |
25 |
Correct |
3 ms |
3412 KB |
Output is correct |
26 |
Correct |
2 ms |
3412 KB |
Output is correct |
27 |
Correct |
2 ms |
3412 KB |
Output is correct |
28 |
Correct |
2 ms |
3412 KB |
Output is correct |
29 |
Correct |
2 ms |
3412 KB |
Output is correct |
30 |
Correct |
2 ms |
3412 KB |
Output is correct |
31 |
Correct |
2 ms |
3412 KB |
Output is correct |
32 |
Correct |
2 ms |
3412 KB |
Output is correct |
33 |
Correct |
2 ms |
3412 KB |
Output is correct |
34 |
Correct |
4 ms |
3540 KB |
Output is correct |
35 |
Correct |
4 ms |
3472 KB |
Output is correct |
36 |
Correct |
5 ms |
3540 KB |
Output is correct |
37 |
Correct |
3 ms |
3540 KB |
Output is correct |
38 |
Correct |
3 ms |
3468 KB |
Output is correct |
39 |
Correct |
2 ms |
3540 KB |
Output is correct |
40 |
Correct |
3 ms |
3412 KB |
Output is correct |
41 |
Correct |
3 ms |
3420 KB |
Output is correct |
42 |
Correct |
4 ms |
3424 KB |
Output is correct |
43 |
Correct |
3 ms |
3540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
3540 KB |
Output is correct |
2 |
Correct |
4 ms |
3472 KB |
Output is correct |
3 |
Correct |
5 ms |
3540 KB |
Output is correct |
4 |
Correct |
3 ms |
3540 KB |
Output is correct |
5 |
Correct |
3 ms |
3468 KB |
Output is correct |
6 |
Correct |
2 ms |
3540 KB |
Output is correct |
7 |
Correct |
3 ms |
3412 KB |
Output is correct |
8 |
Correct |
3 ms |
3420 KB |
Output is correct |
9 |
Correct |
4 ms |
3424 KB |
Output is correct |
10 |
Correct |
3 ms |
3540 KB |
Output is correct |
11 |
Correct |
2 ms |
3412 KB |
Output is correct |
12 |
Correct |
3 ms |
3412 KB |
Output is correct |
13 |
Correct |
3 ms |
3412 KB |
Output is correct |
14 |
Correct |
3 ms |
3412 KB |
Output is correct |
15 |
Correct |
4 ms |
3412 KB |
Output is correct |
16 |
Correct |
4 ms |
3464 KB |
Output is correct |
17 |
Correct |
4 ms |
3440 KB |
Output is correct |
18 |
Correct |
3 ms |
3540 KB |
Output is correct |
19 |
Correct |
3 ms |
3408 KB |
Output is correct |
20 |
Correct |
3 ms |
3412 KB |
Output is correct |
21 |
Correct |
2 ms |
3412 KB |
Output is correct |
22 |
Correct |
3 ms |
3408 KB |
Output is correct |
23 |
Correct |
3 ms |
3408 KB |
Output is correct |
24 |
Correct |
3 ms |
3412 KB |
Output is correct |
25 |
Correct |
3 ms |
3492 KB |
Output is correct |
26 |
Correct |
3 ms |
3544 KB |
Output is correct |
27 |
Correct |
5 ms |
3412 KB |
Output is correct |
28 |
Correct |
2 ms |
3412 KB |
Output is correct |
29 |
Correct |
2 ms |
3412 KB |
Output is correct |
30 |
Correct |
2 ms |
3412 KB |
Output is correct |
31 |
Correct |
3 ms |
3412 KB |
Output is correct |
32 |
Correct |
3 ms |
3348 KB |
Output is correct |
33 |
Correct |
2 ms |
3412 KB |
Output is correct |
34 |
Correct |
2 ms |
3412 KB |
Output is correct |
35 |
Correct |
3 ms |
3412 KB |
Output is correct |
36 |
Correct |
2 ms |
3412 KB |
Output is correct |
37 |
Correct |
2 ms |
3412 KB |
Output is correct |
38 |
Correct |
2 ms |
3412 KB |
Output is correct |
39 |
Correct |
2 ms |
3412 KB |
Output is correct |
40 |
Correct |
2 ms |
3412 KB |
Output is correct |
41 |
Correct |
2 ms |
3412 KB |
Output is correct |
42 |
Correct |
2 ms |
3412 KB |
Output is correct |
43 |
Correct |
2 ms |
3412 KB |
Output is correct |
44 |
Correct |
60 ms |
6192 KB |
Output is correct |
45 |
Correct |
129 ms |
7732 KB |
Output is correct |
46 |
Correct |
112 ms |
7616 KB |
Output is correct |
47 |
Correct |
120 ms |
7628 KB |
Output is correct |
48 |
Correct |
67 ms |
6668 KB |
Output is correct |
49 |
Correct |
67 ms |
6868 KB |
Output is correct |
50 |
Correct |
31 ms |
7628 KB |
Output is correct |
51 |
Correct |
28 ms |
7736 KB |
Output is correct |
52 |
Correct |
54 ms |
6676 KB |
Output is correct |
53 |
Correct |
28 ms |
6968 KB |
Output is correct |
54 |
Correct |
73 ms |
6780 KB |
Output is correct |
55 |
Correct |
68 ms |
6788 KB |
Output is correct |