#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,k,a[200005], dp[200005], key[200005], tree[800020];
vector<int> b;
void update(int pos, int val, int id=1, int l=1, int r=n)
{
if (pos < l or r < pos) return;
if (l==r)
{
tree[id]=val;
return;
}
int mid=(l+r)/2;
update(pos,val,id*2,l,mid);
update(pos,val,id*2+1,mid+1,r);
tree[id]=min(tree[id*2],tree[id*2+1]);
}
int get(int u, int v , int id=1, int l=1, int r=n)
{
if (r < u or v < l) return 1e18;
if (u <= l and r <= v) return tree[id];
int mid=(l+r)/2;
return min(get(u,v,id*2,l,mid),get(u,v,id*2+1,mid+1,r));
}
signed main()
{
fill(tree,tree+800010,1e18);
cin>>n>>k;
n+=2;
for (int i = 2; i < n; i++) cin>>a[i];
for (int i = 1; i <= n; i++)
{
key[i]=a[i]-i*k;
b.push_back(key[i]);
}
sort(b.begin(),b.end());
for (int i = 1; i <= n; i++) key[i]=lower_bound(b.begin(),b.end(),key[i]) - b.begin() + 1;
dp[n]=0;
update(key[n],0+n-1);
for (int i = n-1; i > 0; i--)
{
// for (int i = 1; i <= 4*n; i++) cout<<tree[i]<<' ';cout<<endl;
int cur=get(1,key[i]);
dp[i]=cur-i;
update(key[i],dp[i]+i-1);
// cout<<cur<<' '<<dp[i]<<endl;
}
cout<<dp[1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Correct |
2 ms |
10844 KB |
Output is correct |
3 |
Correct |
2 ms |
10844 KB |
Output is correct |
4 |
Correct |
2 ms |
10844 KB |
Output is correct |
5 |
Correct |
2 ms |
10844 KB |
Output is correct |
6 |
Correct |
2 ms |
10844 KB |
Output is correct |
7 |
Correct |
2 ms |
10840 KB |
Output is correct |
8 |
Correct |
2 ms |
10844 KB |
Output is correct |
9 |
Correct |
2 ms |
10844 KB |
Output is correct |
10 |
Correct |
2 ms |
10844 KB |
Output is correct |
11 |
Correct |
3 ms |
10844 KB |
Output is correct |
12 |
Correct |
2 ms |
10844 KB |
Output is correct |
13 |
Correct |
2 ms |
10844 KB |
Output is correct |
14 |
Correct |
2 ms |
10844 KB |
Output is correct |
15 |
Correct |
2 ms |
10844 KB |
Output is correct |
16 |
Correct |
2 ms |
10880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Correct |
2 ms |
10844 KB |
Output is correct |
3 |
Correct |
2 ms |
10844 KB |
Output is correct |
4 |
Correct |
2 ms |
10844 KB |
Output is correct |
5 |
Correct |
2 ms |
10844 KB |
Output is correct |
6 |
Correct |
2 ms |
10844 KB |
Output is correct |
7 |
Correct |
2 ms |
10840 KB |
Output is correct |
8 |
Correct |
2 ms |
10844 KB |
Output is correct |
9 |
Correct |
2 ms |
10844 KB |
Output is correct |
10 |
Correct |
2 ms |
10844 KB |
Output is correct |
11 |
Correct |
3 ms |
10844 KB |
Output is correct |
12 |
Correct |
2 ms |
10844 KB |
Output is correct |
13 |
Correct |
2 ms |
10844 KB |
Output is correct |
14 |
Correct |
2 ms |
10844 KB |
Output is correct |
15 |
Correct |
2 ms |
10844 KB |
Output is correct |
16 |
Correct |
2 ms |
10880 KB |
Output is correct |
17 |
Correct |
2 ms |
10844 KB |
Output is correct |
18 |
Correct |
2 ms |
10844 KB |
Output is correct |
19 |
Correct |
2 ms |
10844 KB |
Output is correct |
20 |
Correct |
3 ms |
10844 KB |
Output is correct |
21 |
Correct |
4 ms |
11096 KB |
Output is correct |
22 |
Correct |
5 ms |
10840 KB |
Output is correct |
23 |
Correct |
4 ms |
10840 KB |
Output is correct |
24 |
Correct |
4 ms |
10844 KB |
Output is correct |
25 |
Correct |
5 ms |
11008 KB |
Output is correct |
26 |
Correct |
4 ms |
10844 KB |
Output is correct |
27 |
Correct |
4 ms |
10840 KB |
Output is correct |
28 |
Correct |
6 ms |
10844 KB |
Output is correct |
29 |
Correct |
4 ms |
10840 KB |
Output is correct |
30 |
Correct |
4 ms |
10844 KB |
Output is correct |
31 |
Correct |
3 ms |
10844 KB |
Output is correct |
32 |
Correct |
5 ms |
10844 KB |
Output is correct |
33 |
Correct |
4 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10844 KB |
Output is correct |
2 |
Correct |
2 ms |
10844 KB |
Output is correct |
3 |
Correct |
2 ms |
10844 KB |
Output is correct |
4 |
Correct |
3 ms |
10844 KB |
Output is correct |
5 |
Correct |
4 ms |
11096 KB |
Output is correct |
6 |
Correct |
5 ms |
10840 KB |
Output is correct |
7 |
Correct |
4 ms |
10840 KB |
Output is correct |
8 |
Correct |
4 ms |
10844 KB |
Output is correct |
9 |
Correct |
5 ms |
11008 KB |
Output is correct |
10 |
Correct |
4 ms |
10844 KB |
Output is correct |
11 |
Correct |
4 ms |
10840 KB |
Output is correct |
12 |
Correct |
6 ms |
10844 KB |
Output is correct |
13 |
Correct |
4 ms |
10840 KB |
Output is correct |
14 |
Correct |
4 ms |
10844 KB |
Output is correct |
15 |
Correct |
3 ms |
10844 KB |
Output is correct |
16 |
Correct |
5 ms |
10844 KB |
Output is correct |
17 |
Correct |
4 ms |
10844 KB |
Output is correct |
18 |
Correct |
2 ms |
10844 KB |
Output is correct |
19 |
Correct |
2 ms |
10844 KB |
Output is correct |
20 |
Correct |
2 ms |
10844 KB |
Output is correct |
21 |
Correct |
2 ms |
10844 KB |
Output is correct |
22 |
Correct |
2 ms |
10844 KB |
Output is correct |
23 |
Correct |
2 ms |
10844 KB |
Output is correct |
24 |
Correct |
2 ms |
10840 KB |
Output is correct |
25 |
Correct |
2 ms |
10844 KB |
Output is correct |
26 |
Correct |
2 ms |
10844 KB |
Output is correct |
27 |
Correct |
2 ms |
10844 KB |
Output is correct |
28 |
Correct |
3 ms |
10844 KB |
Output is correct |
29 |
Correct |
2 ms |
10844 KB |
Output is correct |
30 |
Correct |
2 ms |
10844 KB |
Output is correct |
31 |
Correct |
2 ms |
10844 KB |
Output is correct |
32 |
Correct |
2 ms |
10844 KB |
Output is correct |
33 |
Correct |
2 ms |
10880 KB |
Output is correct |
34 |
Correct |
7 ms |
10844 KB |
Output is correct |
35 |
Correct |
5 ms |
10844 KB |
Output is correct |
36 |
Correct |
5 ms |
10844 KB |
Output is correct |
37 |
Correct |
5 ms |
10844 KB |
Output is correct |
38 |
Correct |
4 ms |
10924 KB |
Output is correct |
39 |
Correct |
4 ms |
10840 KB |
Output is correct |
40 |
Correct |
5 ms |
10844 KB |
Output is correct |
41 |
Correct |
4 ms |
10856 KB |
Output is correct |
42 |
Correct |
4 ms |
10840 KB |
Output is correct |
43 |
Correct |
4 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10844 KB |
Output is correct |
2 |
Correct |
5 ms |
10844 KB |
Output is correct |
3 |
Correct |
5 ms |
10844 KB |
Output is correct |
4 |
Correct |
5 ms |
10844 KB |
Output is correct |
5 |
Correct |
4 ms |
10924 KB |
Output is correct |
6 |
Correct |
4 ms |
10840 KB |
Output is correct |
7 |
Correct |
5 ms |
10844 KB |
Output is correct |
8 |
Correct |
4 ms |
10856 KB |
Output is correct |
9 |
Correct |
4 ms |
10840 KB |
Output is correct |
10 |
Correct |
4 ms |
10844 KB |
Output is correct |
11 |
Correct |
2 ms |
10844 KB |
Output is correct |
12 |
Correct |
2 ms |
10844 KB |
Output is correct |
13 |
Correct |
2 ms |
10844 KB |
Output is correct |
14 |
Correct |
3 ms |
10844 KB |
Output is correct |
15 |
Correct |
4 ms |
11096 KB |
Output is correct |
16 |
Correct |
5 ms |
10840 KB |
Output is correct |
17 |
Correct |
4 ms |
10840 KB |
Output is correct |
18 |
Correct |
4 ms |
10844 KB |
Output is correct |
19 |
Correct |
5 ms |
11008 KB |
Output is correct |
20 |
Correct |
4 ms |
10844 KB |
Output is correct |
21 |
Correct |
4 ms |
10840 KB |
Output is correct |
22 |
Correct |
6 ms |
10844 KB |
Output is correct |
23 |
Correct |
4 ms |
10840 KB |
Output is correct |
24 |
Correct |
4 ms |
10844 KB |
Output is correct |
25 |
Correct |
3 ms |
10844 KB |
Output is correct |
26 |
Correct |
5 ms |
10844 KB |
Output is correct |
27 |
Correct |
4 ms |
10844 KB |
Output is correct |
28 |
Correct |
2 ms |
10844 KB |
Output is correct |
29 |
Correct |
2 ms |
10844 KB |
Output is correct |
30 |
Correct |
2 ms |
10844 KB |
Output is correct |
31 |
Correct |
2 ms |
10844 KB |
Output is correct |
32 |
Correct |
2 ms |
10844 KB |
Output is correct |
33 |
Correct |
2 ms |
10844 KB |
Output is correct |
34 |
Correct |
2 ms |
10840 KB |
Output is correct |
35 |
Correct |
2 ms |
10844 KB |
Output is correct |
36 |
Correct |
2 ms |
10844 KB |
Output is correct |
37 |
Correct |
2 ms |
10844 KB |
Output is correct |
38 |
Correct |
3 ms |
10844 KB |
Output is correct |
39 |
Correct |
2 ms |
10844 KB |
Output is correct |
40 |
Correct |
2 ms |
10844 KB |
Output is correct |
41 |
Correct |
2 ms |
10844 KB |
Output is correct |
42 |
Correct |
2 ms |
10844 KB |
Output is correct |
43 |
Correct |
2 ms |
10880 KB |
Output is correct |
44 |
Correct |
83 ms |
13780 KB |
Output is correct |
45 |
Correct |
164 ms |
15328 KB |
Output is correct |
46 |
Correct |
162 ms |
15556 KB |
Output is correct |
47 |
Correct |
160 ms |
15280 KB |
Output is correct |
48 |
Correct |
104 ms |
14296 KB |
Output is correct |
49 |
Correct |
100 ms |
14536 KB |
Output is correct |
50 |
Correct |
105 ms |
15308 KB |
Output is correct |
51 |
Correct |
116 ms |
15356 KB |
Output is correct |
52 |
Correct |
84 ms |
14280 KB |
Output is correct |
53 |
Correct |
87 ms |
14788 KB |
Output is correct |
54 |
Correct |
102 ms |
14420 KB |
Output is correct |
55 |
Correct |
98 ms |
14532 KB |
Output is correct |