#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>
#define fi first
#define se second
#define TASK "rabbitcarrot"
#define ll long long
#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define pb push_back
#define MASK(i) (1 << (i))
#define BIT(x, i) ((x >> (i)) & 1)
using namespace std;
const int oo = 1e9 + 7;
const ll loo = (ll)1e18 + 7;
const int N = 2e5 + 7;
ll n, a[N], m, c[N];
struct segtree{
vector<int> t;
segtree(){
t.resize(N * 4 + 7);
}
void update(int v, int lt, int rt, int pos, int value){
if (lt == rt) return (void)(t[v]= value);
int middle = (rt + lt) / 2;
if (pos <= middle) update(v * 2, lt, middle, pos, value);
else update(v * 2 + 1, middle + 1, rt, pos, value);
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
int getmax(int v, int lt, int rt, int l, int r){
if (l > r) return -oo;
if (lt == l && rt == r) return t[v];
int middle = (rt + lt) / 2;
return max(getmax(v * 2, lt, middle, l, min(middle, r)), getmax(v * 2 + 1, middle + 1, rt, max(middle + 1, l), r));
}
};
vector<ll> id;
int newid[N];
int getcompressedvalue(ll x){
return lower_bound(all(id), x) - id.begin();
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen(TASK".inp", "r", stdin);
// freopen(TASK".out", "w", stdout);
cin >> n >> m;
segtree seg;
for (int i = 1; i <= n; i++){
cin >> a[i];
c[i] = m * i - a[i];
id.pb(c[i]);
}
sort(all(id));
id.resize(unique(all(id)) - id.begin());
for (int i = 1; i <= n; i++){
newid[i] = getcompressedvalue(c[i]) + 2;
}
int res = 0;
// for (int i = 1; i <= n; i++) cout << c[i] << " ";
for (int i = 1; i <= n; i++){
if (c[i] < 0) continue;
int temp = seg.getmax(1, 1, N, 1, newid[i]) + 1;
res = max(res, temp);
seg.update(1, 1, N, newid[i], temp);
}
cout << n - res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3408 KB |
Output is correct |
8 |
Correct |
2 ms |
3412 KB |
Output is correct |
9 |
Correct |
2 ms |
3416 KB |
Output is correct |
10 |
Correct |
2 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 |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
3 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
2 ms |
3412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3408 KB |
Output is correct |
8 |
Correct |
2 ms |
3412 KB |
Output is correct |
9 |
Correct |
2 ms |
3416 KB |
Output is correct |
10 |
Correct |
2 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 |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
3 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 |
3416 KB |
Output is correct |
18 |
Correct |
2 ms |
3412 KB |
Output is correct |
19 |
Correct |
2 ms |
3412 KB |
Output is correct |
20 |
Correct |
4 ms |
3584 KB |
Output is correct |
21 |
Correct |
4 ms |
3668 KB |
Output is correct |
22 |
Correct |
3 ms |
3680 KB |
Output is correct |
23 |
Correct |
4 ms |
3668 KB |
Output is correct |
24 |
Correct |
4 ms |
3680 KB |
Output is correct |
25 |
Correct |
4 ms |
3668 KB |
Output is correct |
26 |
Correct |
5 ms |
3668 KB |
Output is correct |
27 |
Correct |
3 ms |
3668 KB |
Output is correct |
28 |
Correct |
3 ms |
3668 KB |
Output is correct |
29 |
Correct |
4 ms |
3668 KB |
Output is correct |
30 |
Correct |
4 ms |
3668 KB |
Output is correct |
31 |
Correct |
3 ms |
3668 KB |
Output is correct |
32 |
Correct |
6 ms |
3668 KB |
Output is correct |
33 |
Correct |
6 ms |
3668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3416 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
4 ms |
3584 KB |
Output is correct |
5 |
Correct |
4 ms |
3668 KB |
Output is correct |
6 |
Correct |
3 ms |
3680 KB |
Output is correct |
7 |
Correct |
4 ms |
3668 KB |
Output is correct |
8 |
Correct |
4 ms |
3680 KB |
Output is correct |
9 |
Correct |
4 ms |
3668 KB |
Output is correct |
10 |
Correct |
5 ms |
3668 KB |
Output is correct |
11 |
Correct |
3 ms |
3668 KB |
Output is correct |
12 |
Correct |
3 ms |
3668 KB |
Output is correct |
13 |
Correct |
4 ms |
3668 KB |
Output is correct |
14 |
Correct |
4 ms |
3668 KB |
Output is correct |
15 |
Correct |
3 ms |
3668 KB |
Output is correct |
16 |
Correct |
6 ms |
3668 KB |
Output is correct |
17 |
Correct |
6 ms |
3668 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 |
2 ms |
3412 KB |
Output is correct |
22 |
Correct |
2 ms |
3412 KB |
Output is correct |
23 |
Correct |
2 ms |
3412 KB |
Output is correct |
24 |
Correct |
2 ms |
3408 KB |
Output is correct |
25 |
Correct |
2 ms |
3412 KB |
Output is correct |
26 |
Correct |
2 ms |
3416 KB |
Output is correct |
27 |
Correct |
2 ms |
3412 KB |
Output is correct |
28 |
Correct |
2 ms |
3412 KB |
Output is correct |
29 |
Correct |
3 ms |
3408 KB |
Output is correct |
30 |
Correct |
2 ms |
3412 KB |
Output is correct |
31 |
Correct |
3 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 |
3 ms |
3668 KB |
Output is correct |
35 |
Correct |
3 ms |
3668 KB |
Output is correct |
36 |
Correct |
4 ms |
3696 KB |
Output is correct |
37 |
Correct |
3 ms |
3668 KB |
Output is correct |
38 |
Correct |
4 ms |
3668 KB |
Output is correct |
39 |
Correct |
3 ms |
3668 KB |
Output is correct |
40 |
Correct |
4 ms |
3680 KB |
Output is correct |
41 |
Correct |
3 ms |
3668 KB |
Output is correct |
42 |
Correct |
4 ms |
3680 KB |
Output is correct |
43 |
Correct |
6 ms |
3668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3668 KB |
Output is correct |
2 |
Correct |
3 ms |
3668 KB |
Output is correct |
3 |
Correct |
4 ms |
3696 KB |
Output is correct |
4 |
Correct |
3 ms |
3668 KB |
Output is correct |
5 |
Correct |
4 ms |
3668 KB |
Output is correct |
6 |
Correct |
3 ms |
3668 KB |
Output is correct |
7 |
Correct |
4 ms |
3680 KB |
Output is correct |
8 |
Correct |
3 ms |
3668 KB |
Output is correct |
9 |
Correct |
4 ms |
3680 KB |
Output is correct |
10 |
Correct |
6 ms |
3668 KB |
Output is correct |
11 |
Correct |
2 ms |
3416 KB |
Output is correct |
12 |
Correct |
2 ms |
3412 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
4 ms |
3584 KB |
Output is correct |
15 |
Correct |
4 ms |
3668 KB |
Output is correct |
16 |
Correct |
3 ms |
3680 KB |
Output is correct |
17 |
Correct |
4 ms |
3668 KB |
Output is correct |
18 |
Correct |
4 ms |
3680 KB |
Output is correct |
19 |
Correct |
4 ms |
3668 KB |
Output is correct |
20 |
Correct |
5 ms |
3668 KB |
Output is correct |
21 |
Correct |
3 ms |
3668 KB |
Output is correct |
22 |
Correct |
3 ms |
3668 KB |
Output is correct |
23 |
Correct |
4 ms |
3668 KB |
Output is correct |
24 |
Correct |
4 ms |
3668 KB |
Output is correct |
25 |
Correct |
3 ms |
3668 KB |
Output is correct |
26 |
Correct |
6 ms |
3668 KB |
Output is correct |
27 |
Correct |
6 ms |
3668 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 |
2 ms |
3408 KB |
Output is correct |
35 |
Correct |
2 ms |
3412 KB |
Output is correct |
36 |
Correct |
2 ms |
3416 KB |
Output is correct |
37 |
Correct |
2 ms |
3412 KB |
Output is correct |
38 |
Correct |
2 ms |
3412 KB |
Output is correct |
39 |
Correct |
3 ms |
3408 KB |
Output is correct |
40 |
Correct |
2 ms |
3412 KB |
Output is correct |
41 |
Correct |
3 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 |
73 ms |
9388 KB |
Output is correct |
45 |
Correct |
74 ms |
10920 KB |
Output is correct |
46 |
Correct |
110 ms |
10980 KB |
Output is correct |
47 |
Correct |
112 ms |
10988 KB |
Output is correct |
48 |
Correct |
77 ms |
9884 KB |
Output is correct |
49 |
Correct |
80 ms |
10188 KB |
Output is correct |
50 |
Correct |
58 ms |
10988 KB |
Output is correct |
51 |
Correct |
66 ms |
10960 KB |
Output is correct |
52 |
Correct |
71 ms |
9952 KB |
Output is correct |
53 |
Correct |
25 ms |
10316 KB |
Output is correct |
54 |
Correct |
88 ms |
10060 KB |
Output is correct |
55 |
Correct |
96 ms |
10044 KB |
Output is correct |