#include <iostream>
#define int long long
#define INF 1e12
using namespace std;
const int maxN = 2e5+5;
int f[maxN];
int a[maxN];
int N,M;
struct node{
int val,lc,rc;
node(){};
}tree[maxN<<4];
int cnt;
void init(){
cnt = 1;
tree[cnt].lc = tree[cnt].rc = 0;
tree[cnt].val = -INF;
return;
}
int build(){
tree[++cnt].val = -INF;
tree[cnt].lc = 0;
tree[cnt].rc = 0;
return cnt;
}
void pushup(int p){
tree[p].val = max(tree[tree[p].lc].val,tree[tree[p].rc].val);
return;
}
void update(int p, int l, int r, int a, int b, int val){
if(a > r || b < l)return;
if(a <= l && r <= b){
tree[p].val = max(tree[p].val,val);
return;
}
int mid = (l+r)>>1;
if(tree[p].lc == 0)tree[p].lc = build();
if(tree[p].rc == 0)tree[p].rc = build();
update(tree[p].lc,l,mid,a,b,val);
update(tree[p].rc,mid+1,r,a,b,val);
pushup(p);
return;
}
int query(int p, int l, int r, int a, int b){
if(a > r || b < l)return -INF;
if(a <= l && r <= b)return tree[p].val;
int mid = (l+r)>>1;
return max(query(tree[p].lc,l,mid,a,b),query(tree[p].rc,mid+1,r,a,b));
}
void testIO(){
freopen("../test.in","r",stdin);
return;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
//testIO();
cin >> N >> M;
for(int i = 1; i <= N; ++i)cin >> a[i];
a[0] = 0;
f[0] = 0;
//O(NlogN)
init();
for(int i = 1; i <= N; ++i){
if(a[i] > M*i)continue;
f[i] = max(f[i], query(1,-INF,INF,a[i]-M*i,INF) +1);
update(1,-INF,INF,a[i]-M*i,a[i]-M*i,f[i]);
}
int res = 0;
for(int i = 1; i <= N; ++i)res = max(res,f[i]);
cout << N - res << '\n';
return 0;
}
Compilation message
triusis.cpp: In function 'void testIO()':
triusis.cpp:61:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
61 | freopen("../test.in","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
5 ms |
716 KB |
Output is correct |
21 |
Correct |
7 ms |
1356 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
8 ms |
3148 KB |
Output is correct |
24 |
Correct |
8 ms |
3416 KB |
Output is correct |
25 |
Correct |
7 ms |
1476 KB |
Output is correct |
26 |
Correct |
9 ms |
2492 KB |
Output is correct |
27 |
Correct |
4 ms |
332 KB |
Output is correct |
28 |
Correct |
5 ms |
332 KB |
Output is correct |
29 |
Correct |
7 ms |
1356 KB |
Output is correct |
30 |
Correct |
7 ms |
1484 KB |
Output is correct |
31 |
Correct |
5 ms |
460 KB |
Output is correct |
32 |
Correct |
9 ms |
2812 KB |
Output is correct |
33 |
Correct |
8 ms |
2764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
5 ms |
716 KB |
Output is correct |
5 |
Correct |
7 ms |
1356 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
8 ms |
3148 KB |
Output is correct |
8 |
Correct |
8 ms |
3416 KB |
Output is correct |
9 |
Correct |
7 ms |
1476 KB |
Output is correct |
10 |
Correct |
9 ms |
2492 KB |
Output is correct |
11 |
Correct |
4 ms |
332 KB |
Output is correct |
12 |
Correct |
5 ms |
332 KB |
Output is correct |
13 |
Correct |
7 ms |
1356 KB |
Output is correct |
14 |
Correct |
7 ms |
1484 KB |
Output is correct |
15 |
Correct |
5 ms |
460 KB |
Output is correct |
16 |
Correct |
9 ms |
2812 KB |
Output is correct |
17 |
Correct |
8 ms |
2764 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
2 ms |
460 KB |
Output is correct |
37 |
Correct |
8 ms |
2440 KB |
Output is correct |
38 |
Correct |
4 ms |
332 KB |
Output is correct |
39 |
Correct |
5 ms |
332 KB |
Output is correct |
40 |
Correct |
6 ms |
464 KB |
Output is correct |
41 |
Correct |
2 ms |
332 KB |
Output is correct |
42 |
Correct |
9 ms |
3148 KB |
Output is correct |
43 |
Correct |
9 ms |
3148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
8 ms |
2440 KB |
Output is correct |
5 |
Correct |
4 ms |
332 KB |
Output is correct |
6 |
Correct |
5 ms |
332 KB |
Output is correct |
7 |
Correct |
6 ms |
464 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
9 ms |
3148 KB |
Output is correct |
10 |
Correct |
9 ms |
3148 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
5 ms |
716 KB |
Output is correct |
15 |
Correct |
7 ms |
1356 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
8 ms |
3148 KB |
Output is correct |
18 |
Correct |
8 ms |
3416 KB |
Output is correct |
19 |
Correct |
7 ms |
1476 KB |
Output is correct |
20 |
Correct |
9 ms |
2492 KB |
Output is correct |
21 |
Correct |
4 ms |
332 KB |
Output is correct |
22 |
Correct |
5 ms |
332 KB |
Output is correct |
23 |
Correct |
7 ms |
1356 KB |
Output is correct |
24 |
Correct |
7 ms |
1484 KB |
Output is correct |
25 |
Correct |
5 ms |
460 KB |
Output is correct |
26 |
Correct |
9 ms |
2812 KB |
Output is correct |
27 |
Correct |
8 ms |
2764 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
265 ms |
43496 KB |
Output is correct |
45 |
Correct |
24 ms |
1796 KB |
Output is correct |
46 |
Correct |
230 ms |
65304 KB |
Output is correct |
47 |
Correct |
210 ms |
65308 KB |
Output is correct |
48 |
Correct |
276 ms |
46664 KB |
Output is correct |
49 |
Incorrect |
272 ms |
78488 KB |
Output isn't correct |
50 |
Halted |
0 ms |
0 KB |
- |