#include <bits/stdc++.h>
using namespace std;
int n, m;
int h[200010];
int bit[200010];
const int MAX = 200005;
vector<tuple<int, int, int> > vq;
vector<int> cmp;
void init(){
for(int i = 1; i <= MAX; i++) bit[i] = 1e9;
}
void update(int x, int val){
for(; x <= MAX; x += x & (-x)) bit[x] = min(bit[x], val);
}
int query(int x){
int ret = 1e9;
for(; x; x -= x & (-x)) ret = min(ret, bit[x]);
return ret;
}
int getIdx(int val){
return (int) (upper_bound(cmp.begin(), cmp.end(), val) - cmp.begin());
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> h[i];
if(h[i] <= i * m) cmp.emplace_back(i * m - h[i]);
}
cmp.emplace_back(0);
sort(cmp.begin(), cmp.end());
cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end());
// for(auto &k : cmp) cerr << k << " ";
// cerr << "\n";
init();
update(getIdx(0), 0);
for(int i = 1; i <= n; i++){
if(h[i] > i * m) continue;
int delta = getIdx(i * m - h[i]);
// cerr << "Index of delta: " << delta << " will update with value " << i + query(delta) - 1 << "\n";
update(delta, query(delta) - 1);
}
cout << n + query(MAX) << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1152 KB |
Output is correct |
2 |
Correct |
1 ms |
1152 KB |
Output is correct |
3 |
Correct |
1 ms |
1152 KB |
Output is correct |
4 |
Correct |
1 ms |
1152 KB |
Output is correct |
5 |
Correct |
1 ms |
1152 KB |
Output is correct |
6 |
Correct |
1 ms |
1152 KB |
Output is correct |
7 |
Correct |
1 ms |
1152 KB |
Output is correct |
8 |
Correct |
1 ms |
1152 KB |
Output is correct |
9 |
Correct |
1 ms |
1152 KB |
Output is correct |
10 |
Correct |
1 ms |
1152 KB |
Output is correct |
11 |
Correct |
1 ms |
1152 KB |
Output is correct |
12 |
Correct |
1 ms |
1152 KB |
Output is correct |
13 |
Correct |
1 ms |
1152 KB |
Output is correct |
14 |
Correct |
1 ms |
1152 KB |
Output is correct |
15 |
Correct |
1 ms |
1152 KB |
Output is correct |
16 |
Correct |
1 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1152 KB |
Output is correct |
2 |
Correct |
1 ms |
1152 KB |
Output is correct |
3 |
Correct |
1 ms |
1152 KB |
Output is correct |
4 |
Correct |
2 ms |
1152 KB |
Output is correct |
5 |
Correct |
2 ms |
1152 KB |
Output is correct |
6 |
Correct |
1 ms |
1152 KB |
Output is correct |
7 |
Correct |
2 ms |
1152 KB |
Output is correct |
8 |
Correct |
2 ms |
1152 KB |
Output is correct |
9 |
Correct |
2 ms |
1280 KB |
Output is correct |
10 |
Correct |
2 ms |
1280 KB |
Output is correct |
11 |
Correct |
2 ms |
1152 KB |
Output is correct |
12 |
Correct |
1 ms |
1152 KB |
Output is correct |
13 |
Correct |
2 ms |
1152 KB |
Output is correct |
14 |
Correct |
2 ms |
1152 KB |
Output is correct |
15 |
Correct |
2 ms |
1152 KB |
Output is correct |
16 |
Correct |
2 ms |
1152 KB |
Output is correct |
17 |
Correct |
2 ms |
1280 KB |
Output is correct |
18 |
Correct |
1 ms |
1152 KB |
Output is correct |
19 |
Correct |
1 ms |
1152 KB |
Output is correct |
20 |
Correct |
1 ms |
1152 KB |
Output is correct |
21 |
Correct |
1 ms |
1152 KB |
Output is correct |
22 |
Correct |
1 ms |
1152 KB |
Output is correct |
23 |
Correct |
1 ms |
1152 KB |
Output is correct |
24 |
Correct |
1 ms |
1152 KB |
Output is correct |
25 |
Correct |
1 ms |
1152 KB |
Output is correct |
26 |
Correct |
1 ms |
1152 KB |
Output is correct |
27 |
Correct |
1 ms |
1152 KB |
Output is correct |
28 |
Correct |
1 ms |
1152 KB |
Output is correct |
29 |
Correct |
1 ms |
1152 KB |
Output is correct |
30 |
Correct |
1 ms |
1152 KB |
Output is correct |
31 |
Correct |
1 ms |
1152 KB |
Output is correct |
32 |
Correct |
1 ms |
1152 KB |
Output is correct |
33 |
Correct |
1 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1152 KB |
Output is correct |
2 |
Correct |
2 ms |
1152 KB |
Output is correct |
3 |
Correct |
3 ms |
1152 KB |
Output is correct |
4 |
Correct |
2 ms |
1280 KB |
Output is correct |
5 |
Correct |
2 ms |
1280 KB |
Output is correct |
6 |
Correct |
2 ms |
1280 KB |
Output is correct |
7 |
Correct |
2 ms |
1152 KB |
Output is correct |
8 |
Correct |
2 ms |
1152 KB |
Output is correct |
9 |
Correct |
2 ms |
1280 KB |
Output is correct |
10 |
Correct |
2 ms |
1236 KB |
Output is correct |
11 |
Correct |
1 ms |
1152 KB |
Output is correct |
12 |
Correct |
1 ms |
1152 KB |
Output is correct |
13 |
Correct |
1 ms |
1152 KB |
Output is correct |
14 |
Correct |
2 ms |
1152 KB |
Output is correct |
15 |
Correct |
2 ms |
1152 KB |
Output is correct |
16 |
Correct |
1 ms |
1152 KB |
Output is correct |
17 |
Correct |
2 ms |
1152 KB |
Output is correct |
18 |
Correct |
2 ms |
1152 KB |
Output is correct |
19 |
Correct |
2 ms |
1280 KB |
Output is correct |
20 |
Correct |
2 ms |
1280 KB |
Output is correct |
21 |
Correct |
2 ms |
1152 KB |
Output is correct |
22 |
Correct |
1 ms |
1152 KB |
Output is correct |
23 |
Correct |
2 ms |
1152 KB |
Output is correct |
24 |
Correct |
2 ms |
1152 KB |
Output is correct |
25 |
Correct |
2 ms |
1152 KB |
Output is correct |
26 |
Correct |
2 ms |
1152 KB |
Output is correct |
27 |
Correct |
2 ms |
1280 KB |
Output is correct |
28 |
Correct |
1 ms |
1152 KB |
Output is correct |
29 |
Correct |
1 ms |
1152 KB |
Output is correct |
30 |
Correct |
1 ms |
1152 KB |
Output is correct |
31 |
Correct |
1 ms |
1152 KB |
Output is correct |
32 |
Correct |
1 ms |
1152 KB |
Output is correct |
33 |
Correct |
1 ms |
1152 KB |
Output is correct |
34 |
Correct |
1 ms |
1152 KB |
Output is correct |
35 |
Correct |
1 ms |
1152 KB |
Output is correct |
36 |
Correct |
1 ms |
1152 KB |
Output is correct |
37 |
Correct |
1 ms |
1152 KB |
Output is correct |
38 |
Correct |
1 ms |
1152 KB |
Output is correct |
39 |
Correct |
1 ms |
1152 KB |
Output is correct |
40 |
Correct |
1 ms |
1152 KB |
Output is correct |
41 |
Correct |
1 ms |
1152 KB |
Output is correct |
42 |
Correct |
1 ms |
1152 KB |
Output is correct |
43 |
Correct |
1 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1152 KB |
Output is correct |
2 |
Correct |
2 ms |
1152 KB |
Output is correct |
3 |
Correct |
3 ms |
1152 KB |
Output is correct |
4 |
Correct |
2 ms |
1280 KB |
Output is correct |
5 |
Correct |
2 ms |
1280 KB |
Output is correct |
6 |
Correct |
2 ms |
1280 KB |
Output is correct |
7 |
Correct |
2 ms |
1152 KB |
Output is correct |
8 |
Correct |
2 ms |
1152 KB |
Output is correct |
9 |
Correct |
2 ms |
1280 KB |
Output is correct |
10 |
Correct |
2 ms |
1236 KB |
Output is correct |
11 |
Correct |
1 ms |
1152 KB |
Output is correct |
12 |
Correct |
1 ms |
1152 KB |
Output is correct |
13 |
Correct |
1 ms |
1152 KB |
Output is correct |
14 |
Correct |
2 ms |
1152 KB |
Output is correct |
15 |
Correct |
2 ms |
1152 KB |
Output is correct |
16 |
Correct |
1 ms |
1152 KB |
Output is correct |
17 |
Correct |
2 ms |
1152 KB |
Output is correct |
18 |
Correct |
2 ms |
1152 KB |
Output is correct |
19 |
Correct |
2 ms |
1280 KB |
Output is correct |
20 |
Correct |
2 ms |
1280 KB |
Output is correct |
21 |
Correct |
2 ms |
1152 KB |
Output is correct |
22 |
Correct |
1 ms |
1152 KB |
Output is correct |
23 |
Correct |
2 ms |
1152 KB |
Output is correct |
24 |
Correct |
2 ms |
1152 KB |
Output is correct |
25 |
Correct |
2 ms |
1152 KB |
Output is correct |
26 |
Correct |
2 ms |
1152 KB |
Output is correct |
27 |
Correct |
2 ms |
1280 KB |
Output is correct |
28 |
Correct |
52 ms |
3180 KB |
Output is correct |
29 |
Correct |
33 ms |
3832 KB |
Output is correct |
30 |
Correct |
68 ms |
4388 KB |
Output is correct |
31 |
Correct |
58 ms |
4340 KB |
Output is correct |
32 |
Correct |
57 ms |
3688 KB |
Output is correct |
33 |
Correct |
63 ms |
3952 KB |
Output is correct |
34 |
Correct |
41 ms |
4592 KB |
Output is correct |
35 |
Correct |
41 ms |
4720 KB |
Output is correct |
36 |
Correct |
37 ms |
3704 KB |
Output is correct |
37 |
Correct |
25 ms |
3200 KB |
Output is correct |
38 |
Correct |
68 ms |
3820 KB |
Output is correct |
39 |
Correct |
62 ms |
3820 KB |
Output is correct |
40 |
Correct |
1 ms |
1152 KB |
Output is correct |
41 |
Correct |
1 ms |
1152 KB |
Output is correct |
42 |
Correct |
1 ms |
1152 KB |
Output is correct |
43 |
Correct |
1 ms |
1152 KB |
Output is correct |
44 |
Correct |
1 ms |
1152 KB |
Output is correct |
45 |
Correct |
1 ms |
1152 KB |
Output is correct |
46 |
Correct |
1 ms |
1152 KB |
Output is correct |
47 |
Correct |
1 ms |
1152 KB |
Output is correct |
48 |
Correct |
1 ms |
1152 KB |
Output is correct |
49 |
Correct |
1 ms |
1152 KB |
Output is correct |
50 |
Correct |
1 ms |
1152 KB |
Output is correct |
51 |
Correct |
1 ms |
1152 KB |
Output is correct |
52 |
Correct |
1 ms |
1152 KB |
Output is correct |
53 |
Correct |
1 ms |
1152 KB |
Output is correct |
54 |
Correct |
1 ms |
1152 KB |
Output is correct |
55 |
Correct |
1 ms |
1152 KB |
Output is correct |