#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
const ll NMAX = 200005;
const ll VMAX = 26;
const ll INF = (1LL << 55);
const ll MOD = 90000000000000001;
const ll BLOCK = 1000000;
const ll base = 1000000001;
const ll nr_of_bits = 18;
ll v[NMAX];
int dp[NMAX];
vector <int> nrm;
unordered_map <int, int> mp;
int aint[NMAX * 4];
void update(int node, int st, int dr, int a, int b){
if(st == dr){
aint[node] = min(aint[node], b);
return;
}
int mid = (st + dr) / 2;
if(a <= mid)
update(node * 2, st, mid, a, b);
else
update(node * 2 + 1, mid + 1, dr, a, b);
aint[node] = min(aint[node * 2], aint[node * 2 + 1]);
}
int query(int node, int st, int dr, int a, int b){
if(a <= st && dr <= b)
return aint[node];
int mid = (st + dr) / 2;
int minim = 2e9;
if(a <= mid)
minim = min(minim, query(node * 2, st, mid, a, b));
if(b > mid)
minim = min(minim, query(node * 2 + 1, mid + 1, dr, a, b));
return minim;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, i, m;
for(i = 1; i < NMAX * 4; i++)
aint[i] = 2e9;
cin >> n >> m;
nrm.push_back(0);
nrm.push_back(-2e9);
for(i = 2; i <= n + 1; i++){
cin >> v[i];
v[i] -= m * (i - 1);
nrm.push_back(v[i]);
}
sort(nrm.begin(), nrm.end());
int cnt = 0;
for(i = 0; i < nrm.size(); i++){
if(i == 0 || nrm[i] != nrm[i - 1])
cnt++;
mp[nrm[i]] = cnt;
}
for(i = 1; i <= n + 1; i++)
v[i] = mp[v[i]];
n += 2;
v[n] = 1; /// numar artificial
int minim = 0;
for(i = 1; i <= n; i++){
dp[i] = i - 1 + query(1, 1, NMAX, v[i], NMAX);
if(i == 1)
dp[i] = 0;
update(1, 1, NMAX, v[i], dp[i] - i);
}
cout << dp[n];
return 0;
}
Compilation message
triusis.cpp: In function 'int main()':
triusis.cpp:65:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(i = 0; i < nrm.size(); i++){
| ~~^~~~~~~~~~~~
triusis.cpp:74:9: warning: unused variable 'minim' [-Wunused-variable]
74 | int minim = 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 |
3464 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
2 ms |
3460 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
2 ms |
3456 KB |
Output is correct |
9 |
Correct |
2 ms |
3412 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 |
3412 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
2 ms |
3460 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
2 ms |
3456 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 |
3464 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
2 ms |
3460 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3412 KB |
Output is correct |
8 |
Correct |
2 ms |
3456 KB |
Output is correct |
9 |
Correct |
2 ms |
3412 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 |
3412 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
2 ms |
3460 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
2 ms |
3456 KB |
Output is correct |
17 |
Correct |
2 ms |
3412 KB |
Output is correct |
18 |
Correct |
2 ms |
3464 KB |
Output is correct |
19 |
Correct |
2 ms |
3412 KB |
Output is correct |
20 |
Correct |
4 ms |
3668 KB |
Output is correct |
21 |
Correct |
4 ms |
3668 KB |
Output is correct |
22 |
Correct |
4 ms |
3668 KB |
Output is correct |
23 |
Correct |
5 ms |
3732 KB |
Output is correct |
24 |
Correct |
4 ms |
3668 KB |
Output is correct |
25 |
Correct |
4 ms |
3668 KB |
Output is correct |
26 |
Correct |
5 ms |
3744 KB |
Output is correct |
27 |
Correct |
4 ms |
3540 KB |
Output is correct |
28 |
Correct |
4 ms |
3540 KB |
Output is correct |
29 |
Correct |
5 ms |
3668 KB |
Output is correct |
30 |
Correct |
4 ms |
3732 KB |
Output is correct |
31 |
Correct |
4 ms |
3596 KB |
Output is correct |
32 |
Correct |
4 ms |
3724 KB |
Output is correct |
33 |
Correct |
5 ms |
3724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3464 KB |
Output is correct |
3 |
Correct |
2 ms |
3412 KB |
Output is correct |
4 |
Correct |
4 ms |
3668 KB |
Output is correct |
5 |
Correct |
4 ms |
3668 KB |
Output is correct |
6 |
Correct |
4 ms |
3668 KB |
Output is correct |
7 |
Correct |
5 ms |
3732 KB |
Output is correct |
8 |
Correct |
4 ms |
3668 KB |
Output is correct |
9 |
Correct |
4 ms |
3668 KB |
Output is correct |
10 |
Correct |
5 ms |
3744 KB |
Output is correct |
11 |
Correct |
4 ms |
3540 KB |
Output is correct |
12 |
Correct |
4 ms |
3540 KB |
Output is correct |
13 |
Correct |
5 ms |
3668 KB |
Output is correct |
14 |
Correct |
4 ms |
3732 KB |
Output is correct |
15 |
Correct |
4 ms |
3596 KB |
Output is correct |
16 |
Correct |
4 ms |
3724 KB |
Output is correct |
17 |
Correct |
5 ms |
3724 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 |
3464 KB |
Output is correct |
21 |
Correct |
2 ms |
3412 KB |
Output is correct |
22 |
Correct |
2 ms |
3460 KB |
Output is correct |
23 |
Correct |
2 ms |
3412 KB |
Output is correct |
24 |
Correct |
2 ms |
3412 KB |
Output is correct |
25 |
Correct |
2 ms |
3456 KB |
Output is correct |
26 |
Correct |
2 ms |
3412 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 |
3412 KB |
Output is correct |
30 |
Correct |
2 ms |
3412 KB |
Output is correct |
31 |
Correct |
2 ms |
3460 KB |
Output is correct |
32 |
Correct |
2 ms |
3412 KB |
Output is correct |
33 |
Correct |
2 ms |
3456 KB |
Output is correct |
34 |
Correct |
6 ms |
3732 KB |
Output is correct |
35 |
Correct |
4 ms |
3796 KB |
Output is correct |
36 |
Correct |
5 ms |
3796 KB |
Output is correct |
37 |
Correct |
4 ms |
3668 KB |
Output is correct |
38 |
Correct |
4 ms |
3604 KB |
Output is correct |
39 |
Correct |
4 ms |
3540 KB |
Output is correct |
40 |
Correct |
4 ms |
3668 KB |
Output is correct |
41 |
Correct |
3 ms |
3540 KB |
Output is correct |
42 |
Correct |
4 ms |
3668 KB |
Output is correct |
43 |
Correct |
5 ms |
3780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
3732 KB |
Output is correct |
2 |
Correct |
4 ms |
3796 KB |
Output is correct |
3 |
Correct |
5 ms |
3796 KB |
Output is correct |
4 |
Correct |
4 ms |
3668 KB |
Output is correct |
5 |
Correct |
4 ms |
3604 KB |
Output is correct |
6 |
Correct |
4 ms |
3540 KB |
Output is correct |
7 |
Correct |
4 ms |
3668 KB |
Output is correct |
8 |
Correct |
3 ms |
3540 KB |
Output is correct |
9 |
Correct |
4 ms |
3668 KB |
Output is correct |
10 |
Correct |
5 ms |
3780 KB |
Output is correct |
11 |
Correct |
2 ms |
3412 KB |
Output is correct |
12 |
Correct |
2 ms |
3464 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
4 ms |
3668 KB |
Output is correct |
15 |
Correct |
4 ms |
3668 KB |
Output is correct |
16 |
Correct |
4 ms |
3668 KB |
Output is correct |
17 |
Correct |
5 ms |
3732 KB |
Output is correct |
18 |
Correct |
4 ms |
3668 KB |
Output is correct |
19 |
Correct |
4 ms |
3668 KB |
Output is correct |
20 |
Correct |
5 ms |
3744 KB |
Output is correct |
21 |
Correct |
4 ms |
3540 KB |
Output is correct |
22 |
Correct |
4 ms |
3540 KB |
Output is correct |
23 |
Correct |
5 ms |
3668 KB |
Output is correct |
24 |
Correct |
4 ms |
3732 KB |
Output is correct |
25 |
Correct |
4 ms |
3596 KB |
Output is correct |
26 |
Correct |
4 ms |
3724 KB |
Output is correct |
27 |
Correct |
5 ms |
3724 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 |
3464 KB |
Output is correct |
31 |
Correct |
2 ms |
3412 KB |
Output is correct |
32 |
Correct |
2 ms |
3460 KB |
Output is correct |
33 |
Correct |
2 ms |
3412 KB |
Output is correct |
34 |
Correct |
2 ms |
3412 KB |
Output is correct |
35 |
Correct |
2 ms |
3456 KB |
Output is correct |
36 |
Correct |
2 ms |
3412 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 |
3412 KB |
Output is correct |
40 |
Correct |
2 ms |
3412 KB |
Output is correct |
41 |
Correct |
2 ms |
3460 KB |
Output is correct |
42 |
Correct |
2 ms |
3412 KB |
Output is correct |
43 |
Correct |
2 ms |
3456 KB |
Output is correct |
44 |
Correct |
100 ms |
15868 KB |
Output is correct |
45 |
Correct |
142 ms |
17512 KB |
Output is correct |
46 |
Correct |
148 ms |
17488 KB |
Output is correct |
47 |
Correct |
164 ms |
17460 KB |
Output is correct |
48 |
Correct |
114 ms |
16420 KB |
Output is correct |
49 |
Correct |
130 ms |
16700 KB |
Output is correct |
50 |
Correct |
97 ms |
8636 KB |
Output is correct |
51 |
Correct |
77 ms |
8600 KB |
Output is correct |
52 |
Correct |
75 ms |
11860 KB |
Output is correct |
53 |
Correct |
67 ms |
7880 KB |
Output is correct |
54 |
Correct |
113 ms |
16520 KB |
Output is correct |
55 |
Correct |
106 ms |
16576 KB |
Output is correct |