#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (1000005)
struct node {
node *l, *r;
ll s,e,m,v;
node(ll _s,ll _e){
s = _s;
e = _e;
m = (s + e) / 2;
v = 0;
if(s != e){
l = new node(s,m);
r = new node(m + 1,e);
}
}
void update(ll x,ll val){
if(s == e){
v = val;
return;
}
else if(x > m) r -> update(x,val);
if(x <= m) l -> update(x,val);
v = max(l -> v,r -> v);
}
long long rmq(ll S,ll E){
if(s == S && e == E) return v;
else if(S > m) return r -> rmq(S,E);
else if(E <= m) return l -> rmq(S,E);
else return max(l -> rmq(S,m),r -> rmq(m + 1,E));
}
} *root;
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
ll N,M;
cin>>N>>M;
root = new node(0,N + 5);
ll arr[N];
for(ll i = 0;i < N;i++){
cin>>arr[i];
}
ll num[N];
for(ll i = 0;i < N;i++){
num[i] = 1;
}
for(ll i = 0;i < N;i++){
if(arr[i] > (i + 1) * M){
num[i] = 0;
}
}
vector<pair<ll,ll> > v;
for(ll i = 0;i < N;i++){
v.push_back(make_pair(min(arr[i],(i + 1) * M) - (i * M),-1 * i));
}
sort(v.begin(),v.end(),greater<pair<ll,ll> >());
ll index[N];
memset(index,0,sizeof(index));
for(ll i = 0;i < N;i++){
index[-1 * v[i].second] = i;
}
ll sum = 0;
ll dp[N];
memset(dp,0,sizeof(dp));
for(ll i = 0;i < N;i++){
ll a = root -> rmq(0,index[i]);
dp[i] = a + num[i];
sum = max(sum,dp[i]);
root -> update(index[i],dp[i]);
}
cout<<N - sum<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
288 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
288 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
316 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
2 ms |
972 KB |
Output is correct |
21 |
Correct |
4 ms |
1248 KB |
Output is correct |
22 |
Correct |
3 ms |
1228 KB |
Output is correct |
23 |
Correct |
3 ms |
1228 KB |
Output is correct |
24 |
Correct |
2 ms |
1212 KB |
Output is correct |
25 |
Correct |
3 ms |
1216 KB |
Output is correct |
26 |
Correct |
2 ms |
1228 KB |
Output is correct |
27 |
Correct |
3 ms |
1228 KB |
Output is correct |
28 |
Correct |
3 ms |
1228 KB |
Output is correct |
29 |
Correct |
2 ms |
1212 KB |
Output is correct |
30 |
Correct |
2 ms |
1200 KB |
Output is correct |
31 |
Correct |
2 ms |
1216 KB |
Output is correct |
32 |
Correct |
3 ms |
1232 KB |
Output is correct |
33 |
Correct |
2 ms |
1208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
972 KB |
Output is correct |
5 |
Correct |
4 ms |
1248 KB |
Output is correct |
6 |
Correct |
3 ms |
1228 KB |
Output is correct |
7 |
Correct |
3 ms |
1228 KB |
Output is correct |
8 |
Correct |
2 ms |
1212 KB |
Output is correct |
9 |
Correct |
3 ms |
1216 KB |
Output is correct |
10 |
Correct |
2 ms |
1228 KB |
Output is correct |
11 |
Correct |
3 ms |
1228 KB |
Output is correct |
12 |
Correct |
3 ms |
1228 KB |
Output is correct |
13 |
Correct |
2 ms |
1212 KB |
Output is correct |
14 |
Correct |
2 ms |
1200 KB |
Output is correct |
15 |
Correct |
2 ms |
1216 KB |
Output is correct |
16 |
Correct |
3 ms |
1232 KB |
Output is correct |
17 |
Correct |
2 ms |
1208 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
308 KB |
Output is correct |
24 |
Correct |
1 ms |
288 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
316 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
312 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
308 KB |
Output is correct |
34 |
Correct |
3 ms |
1256 KB |
Output is correct |
35 |
Correct |
3 ms |
1352 KB |
Output is correct |
36 |
Correct |
3 ms |
1344 KB |
Output is correct |
37 |
Correct |
2 ms |
1208 KB |
Output is correct |
38 |
Correct |
3 ms |
1208 KB |
Output is correct |
39 |
Correct |
3 ms |
1344 KB |
Output is correct |
40 |
Correct |
2 ms |
1236 KB |
Output is correct |
41 |
Correct |
2 ms |
1216 KB |
Output is correct |
42 |
Correct |
3 ms |
1228 KB |
Output is correct |
43 |
Correct |
3 ms |
1228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1256 KB |
Output is correct |
2 |
Correct |
3 ms |
1352 KB |
Output is correct |
3 |
Correct |
3 ms |
1344 KB |
Output is correct |
4 |
Correct |
2 ms |
1208 KB |
Output is correct |
5 |
Correct |
3 ms |
1208 KB |
Output is correct |
6 |
Correct |
3 ms |
1344 KB |
Output is correct |
7 |
Correct |
2 ms |
1236 KB |
Output is correct |
8 |
Correct |
2 ms |
1216 KB |
Output is correct |
9 |
Correct |
3 ms |
1228 KB |
Output is correct |
10 |
Correct |
3 ms |
1228 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
2 ms |
972 KB |
Output is correct |
15 |
Correct |
4 ms |
1248 KB |
Output is correct |
16 |
Correct |
3 ms |
1228 KB |
Output is correct |
17 |
Correct |
3 ms |
1228 KB |
Output is correct |
18 |
Correct |
2 ms |
1212 KB |
Output is correct |
19 |
Correct |
3 ms |
1216 KB |
Output is correct |
20 |
Correct |
2 ms |
1228 KB |
Output is correct |
21 |
Correct |
3 ms |
1228 KB |
Output is correct |
22 |
Correct |
3 ms |
1228 KB |
Output is correct |
23 |
Correct |
2 ms |
1212 KB |
Output is correct |
24 |
Correct |
2 ms |
1200 KB |
Output is correct |
25 |
Correct |
2 ms |
1216 KB |
Output is correct |
26 |
Correct |
3 ms |
1232 KB |
Output is correct |
27 |
Correct |
2 ms |
1208 KB |
Output is correct |
28 |
Correct |
1 ms |
316 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
0 ms |
308 KB |
Output is correct |
34 |
Correct |
1 ms |
288 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
0 ms |
204 KB |
Output is correct |
37 |
Correct |
1 ms |
204 KB |
Output is correct |
38 |
Correct |
1 ms |
316 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
1 ms |
312 KB |
Output is correct |
41 |
Correct |
1 ms |
204 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
308 KB |
Output is correct |
44 |
Correct |
73 ms |
35220 KB |
Output is correct |
45 |
Correct |
86 ms |
36720 KB |
Output is correct |
46 |
Correct |
124 ms |
36792 KB |
Output is correct |
47 |
Correct |
119 ms |
36732 KB |
Output is correct |
48 |
Correct |
76 ms |
35760 KB |
Output is correct |
49 |
Correct |
78 ms |
35948 KB |
Output is correct |
50 |
Correct |
96 ms |
36788 KB |
Output is correct |
51 |
Correct |
99 ms |
36716 KB |
Output is correct |
52 |
Correct |
87 ms |
35660 KB |
Output is correct |
53 |
Correct |
84 ms |
36136 KB |
Output is correct |
54 |
Correct |
84 ms |
35888 KB |
Output is correct |
55 |
Correct |
79 ms |
35824 KB |
Output is correct |