#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define open(g) string _name_ = g; freopen((_name_ + ".in").c_str(), "r", stdin); freopen((_name_ + ".out").c_str(), "w", stdout)
#define printArr(a, len) for(int asdf = 0; asdf < (len); ++asdf) cout << (a)[asdf] << ' '; cout << '\n';
#define boost() cin.sync_with_stdio(0); cin.tie(0)
#define forR(i, x) for(int i = 0; i < x; ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(i) i.begin(), i.end()
#define pii pair<int, int>
#define vi vector<int>
#define si set<int>
#define usi unordered_set<int>
#define mii map<int, int>
#define umii unordered_map<int, int>
template <class K, class V> using ht = gp_hash_table<K, V, hash<K>, equal_to<K>, direct_mask_range_hashing<>,
linear_probe_fn<>, hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<>, true>>;
const int MN = 2e5 + 300, MAX = 3 * MN;
int bit[MAX];
int& get(int i){
return bit[i];
}
void upd(ll i, int diff){
i = MN - i;
assert(0 < i && i < MAX);
for(; 0 < i && i < MAX; i += i&-i) get(i) = min(get((int) i), diff);
}
int qu(int i){
i = MN - i;
assert(0 < i && i < MAX);
int ma = MAX;
for(; i > 0; i -= i&-i) ma = min(ma, get(i));
return ma;
}
int dp[MN], arr[MN], a[MN];
signed main() {
boost();
int n, m;
cin >> n >> m;
REP(i, 1, n + 1) cin >> arr[i];
for(int& i : bit) i = MAX;
forR(i, n + 1) a[i] = arr[i] - i * m;
set<int> sv;
forR(i, n + 1) sv.insert(a[i]);
vector<int> val;
for(int i : sv) val.push_back(i);
forR(i, n + 1) a[i] = lower_bound(all(val), a[i]) - val.begin() + 1;
upd(a[0], 0);
REP(i, 1, n + 1){
dp[i] = qu(a[i]) + i - 1;
upd(a[i], dp[i] - i);
}
int mi = n;
REP(i, 1, n + 1) {
mi = min(mi, dp[i] + n - i);
}
cout << mi << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2624 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
1 ms |
2644 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2624 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
1 ms |
2644 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
1 ms |
2644 KB |
Output is correct |
16 |
Correct |
1 ms |
2644 KB |
Output is correct |
17 |
Correct |
1 ms |
2644 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2644 KB |
Output is correct |
20 |
Correct |
2 ms |
2900 KB |
Output is correct |
21 |
Correct |
3 ms |
3028 KB |
Output is correct |
22 |
Correct |
3 ms |
2900 KB |
Output is correct |
23 |
Correct |
3 ms |
3028 KB |
Output is correct |
24 |
Correct |
3 ms |
3028 KB |
Output is correct |
25 |
Correct |
3 ms |
3028 KB |
Output is correct |
26 |
Correct |
3 ms |
3028 KB |
Output is correct |
27 |
Correct |
2 ms |
2644 KB |
Output is correct |
28 |
Correct |
2 ms |
2644 KB |
Output is correct |
29 |
Correct |
3 ms |
3028 KB |
Output is correct |
30 |
Correct |
4 ms |
3028 KB |
Output is correct |
31 |
Correct |
3 ms |
2900 KB |
Output is correct |
32 |
Correct |
3 ms |
3028 KB |
Output is correct |
33 |
Correct |
3 ms |
3028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2900 KB |
Output is correct |
5 |
Correct |
3 ms |
3028 KB |
Output is correct |
6 |
Correct |
3 ms |
2900 KB |
Output is correct |
7 |
Correct |
3 ms |
3028 KB |
Output is correct |
8 |
Correct |
3 ms |
3028 KB |
Output is correct |
9 |
Correct |
3 ms |
3028 KB |
Output is correct |
10 |
Correct |
3 ms |
3028 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
3 ms |
3028 KB |
Output is correct |
14 |
Correct |
4 ms |
3028 KB |
Output is correct |
15 |
Correct |
3 ms |
2900 KB |
Output is correct |
16 |
Correct |
3 ms |
3028 KB |
Output is correct |
17 |
Correct |
3 ms |
3028 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
2 ms |
2624 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
21 |
Correct |
1 ms |
2644 KB |
Output is correct |
22 |
Correct |
1 ms |
2644 KB |
Output is correct |
23 |
Correct |
2 ms |
2644 KB |
Output is correct |
24 |
Correct |
2 ms |
2644 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
1 ms |
2644 KB |
Output is correct |
27 |
Correct |
1 ms |
2644 KB |
Output is correct |
28 |
Correct |
1 ms |
2644 KB |
Output is correct |
29 |
Correct |
1 ms |
2644 KB |
Output is correct |
30 |
Correct |
1 ms |
2644 KB |
Output is correct |
31 |
Correct |
2 ms |
2644 KB |
Output is correct |
32 |
Correct |
1 ms |
2644 KB |
Output is correct |
33 |
Correct |
1 ms |
2644 KB |
Output is correct |
34 |
Correct |
3 ms |
3020 KB |
Output is correct |
35 |
Correct |
3 ms |
3028 KB |
Output is correct |
36 |
Correct |
3 ms |
3028 KB |
Output is correct |
37 |
Correct |
3 ms |
3028 KB |
Output is correct |
38 |
Correct |
2 ms |
2644 KB |
Output is correct |
39 |
Correct |
2 ms |
2644 KB |
Output is correct |
40 |
Correct |
3 ms |
2900 KB |
Output is correct |
41 |
Correct |
2 ms |
2644 KB |
Output is correct |
42 |
Correct |
3 ms |
2936 KB |
Output is correct |
43 |
Correct |
3 ms |
3028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3020 KB |
Output is correct |
2 |
Correct |
3 ms |
3028 KB |
Output is correct |
3 |
Correct |
3 ms |
3028 KB |
Output is correct |
4 |
Correct |
3 ms |
3028 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
3 ms |
2900 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
3 ms |
2936 KB |
Output is correct |
10 |
Correct |
3 ms |
3028 KB |
Output is correct |
11 |
Correct |
1 ms |
2644 KB |
Output is correct |
12 |
Correct |
1 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2900 KB |
Output is correct |
15 |
Correct |
3 ms |
3028 KB |
Output is correct |
16 |
Correct |
3 ms |
2900 KB |
Output is correct |
17 |
Correct |
3 ms |
3028 KB |
Output is correct |
18 |
Correct |
3 ms |
3028 KB |
Output is correct |
19 |
Correct |
3 ms |
3028 KB |
Output is correct |
20 |
Correct |
3 ms |
3028 KB |
Output is correct |
21 |
Correct |
2 ms |
2644 KB |
Output is correct |
22 |
Correct |
2 ms |
2644 KB |
Output is correct |
23 |
Correct |
3 ms |
3028 KB |
Output is correct |
24 |
Correct |
4 ms |
3028 KB |
Output is correct |
25 |
Correct |
3 ms |
2900 KB |
Output is correct |
26 |
Correct |
3 ms |
3028 KB |
Output is correct |
27 |
Correct |
3 ms |
3028 KB |
Output is correct |
28 |
Correct |
1 ms |
2644 KB |
Output is correct |
29 |
Correct |
2 ms |
2624 KB |
Output is correct |
30 |
Correct |
1 ms |
2644 KB |
Output is correct |
31 |
Correct |
1 ms |
2644 KB |
Output is correct |
32 |
Correct |
1 ms |
2644 KB |
Output is correct |
33 |
Correct |
2 ms |
2644 KB |
Output is correct |
34 |
Correct |
2 ms |
2644 KB |
Output is correct |
35 |
Correct |
2 ms |
2644 KB |
Output is correct |
36 |
Correct |
1 ms |
2644 KB |
Output is correct |
37 |
Correct |
1 ms |
2644 KB |
Output is correct |
38 |
Correct |
1 ms |
2644 KB |
Output is correct |
39 |
Correct |
1 ms |
2644 KB |
Output is correct |
40 |
Correct |
1 ms |
2644 KB |
Output is correct |
41 |
Correct |
2 ms |
2644 KB |
Output is correct |
42 |
Correct |
1 ms |
2644 KB |
Output is correct |
43 |
Correct |
1 ms |
2644 KB |
Output is correct |
44 |
Correct |
74 ms |
15344 KB |
Output is correct |
45 |
Correct |
153 ms |
16884 KB |
Output is correct |
46 |
Correct |
134 ms |
17232 KB |
Output is correct |
47 |
Correct |
132 ms |
17180 KB |
Output is correct |
48 |
Correct |
61 ms |
15972 KB |
Output is correct |
49 |
Correct |
66 ms |
16448 KB |
Output is correct |
50 |
Correct |
31 ms |
6928 KB |
Output is correct |
51 |
Correct |
28 ms |
6876 KB |
Output is correct |
52 |
Correct |
51 ms |
11048 KB |
Output is correct |
53 |
Correct |
23 ms |
6228 KB |
Output is correct |
54 |
Correct |
73 ms |
16192 KB |
Output is correct |
55 |
Correct |
68 ms |
16168 KB |
Output is correct |