#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
using namespace std;
const int nmax = 10000001;
struct line{
ll k, b;
line(ll k, ll b) : k(k), b(b){
}
line(){
k = 0, b = 1e18;
}
ll get(ll x){
return k * x + b;
}
};
vector <line> t;
vector <int> le(nmax), ri(nmax);
void add(int v, int l, int r, line nw){
int m = (l + r) / 2;
if(l > r){
return;
}
bool left = t[v].get(l) < nw.get(l);
bool mid = t[v].get(m) < nw.get(m);
if(!mid) swap(t[v], nw);
if(mid == left){
if(ri[v] == 0){
ri[v] = t.size();
t.pb(nw);
return;
}
add(ri[v], m + 1, r, nw);
}
else{
if(le[v] == 0)
le[v] = t.size(), t.pb(nw);
else add(le[v], l, m, nw);
}
}
ll get(int v, int l, int r, ll pos){
if(l > r || v == 0) return 1e18;
ll m = (l + r) / 2;
if(pos > m)
return min(t[v].get(pos), get(ri[v], m + 1, r, pos));
return min(t[v].get(pos), get(le[v], l, m, pos));
}
line empt;
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(0);
t.pb(empt);
int n; cin >> n;
t.pb({n, 0});
vector <int> a(n + 1);
vector <int> b;
int mx = 0;
for(int i = 1; i <= n; ++i){
cin >> a[i];
if(a[i] > mx){
b.pb(i);
mx = a[i];
}
}
ll ans = 0;
for(int i= 0; i < b.size(); i++){
int x = b[i];
ll val = get(1, 1, 1e9, a[x]);
ans = val;
if(i != b.size() - 1){
int x = b[i + 1] - 1;
add(1, 1, 1e9, {n - x, ans});
}
}
cout << ans;
return 0;
}
Compilation message
Discharging.cpp: In function 'int32_t main()':
Discharging.cpp:82:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for(int i= 0; i < b.size(); i++){
| ~~^~~~~~~~~~
Discharging.cpp:86:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | if(i != b.size() - 1){
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
78540 KB |
Output is correct |
2 |
Correct |
32 ms |
78504 KB |
Output is correct |
3 |
Correct |
32 ms |
78492 KB |
Output is correct |
4 |
Correct |
31 ms |
78608 KB |
Output is correct |
5 |
Correct |
31 ms |
78588 KB |
Output is correct |
6 |
Correct |
30 ms |
78588 KB |
Output is correct |
7 |
Correct |
31 ms |
78556 KB |
Output is correct |
8 |
Correct |
31 ms |
78548 KB |
Output is correct |
9 |
Correct |
31 ms |
78540 KB |
Output is correct |
10 |
Correct |
35 ms |
78540 KB |
Output is correct |
11 |
Correct |
30 ms |
78528 KB |
Output is correct |
12 |
Correct |
33 ms |
78552 KB |
Output is correct |
13 |
Correct |
31 ms |
78548 KB |
Output is correct |
14 |
Correct |
31 ms |
78588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
78620 KB |
Output is correct |
2 |
Correct |
30 ms |
78588 KB |
Output is correct |
3 |
Correct |
32 ms |
78544 KB |
Output is correct |
4 |
Correct |
31 ms |
78604 KB |
Output is correct |
5 |
Correct |
32 ms |
78588 KB |
Output is correct |
6 |
Correct |
32 ms |
78556 KB |
Output is correct |
7 |
Correct |
33 ms |
78616 KB |
Output is correct |
8 |
Correct |
35 ms |
78604 KB |
Output is correct |
9 |
Correct |
33 ms |
78604 KB |
Output is correct |
10 |
Correct |
29 ms |
78636 KB |
Output is correct |
11 |
Correct |
30 ms |
78552 KB |
Output is correct |
12 |
Correct |
31 ms |
78548 KB |
Output is correct |
13 |
Correct |
32 ms |
78724 KB |
Output is correct |
14 |
Correct |
30 ms |
78620 KB |
Output is correct |
15 |
Correct |
30 ms |
78524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
78620 KB |
Output is correct |
2 |
Correct |
30 ms |
78588 KB |
Output is correct |
3 |
Correct |
32 ms |
78544 KB |
Output is correct |
4 |
Correct |
31 ms |
78604 KB |
Output is correct |
5 |
Correct |
32 ms |
78588 KB |
Output is correct |
6 |
Correct |
32 ms |
78556 KB |
Output is correct |
7 |
Correct |
33 ms |
78616 KB |
Output is correct |
8 |
Correct |
35 ms |
78604 KB |
Output is correct |
9 |
Correct |
33 ms |
78604 KB |
Output is correct |
10 |
Correct |
29 ms |
78636 KB |
Output is correct |
11 |
Correct |
30 ms |
78552 KB |
Output is correct |
12 |
Correct |
31 ms |
78548 KB |
Output is correct |
13 |
Correct |
32 ms |
78724 KB |
Output is correct |
14 |
Correct |
30 ms |
78620 KB |
Output is correct |
15 |
Correct |
30 ms |
78524 KB |
Output is correct |
16 |
Correct |
199 ms |
89480 KB |
Output is correct |
17 |
Correct |
236 ms |
90548 KB |
Output is correct |
18 |
Correct |
173 ms |
89020 KB |
Output is correct |
19 |
Correct |
219 ms |
90556 KB |
Output is correct |
20 |
Correct |
232 ms |
90456 KB |
Output is correct |
21 |
Correct |
232 ms |
90448 KB |
Output is correct |
22 |
Correct |
219 ms |
89924 KB |
Output is correct |
23 |
Correct |
270 ms |
92528 KB |
Output is correct |
24 |
Correct |
247 ms |
92644 KB |
Output is correct |
25 |
Correct |
256 ms |
92916 KB |
Output is correct |
26 |
Correct |
276 ms |
92368 KB |
Output is correct |
27 |
Correct |
199 ms |
89364 KB |
Output is correct |
28 |
Correct |
229 ms |
90684 KB |
Output is correct |
29 |
Correct |
262 ms |
92680 KB |
Output is correct |
30 |
Correct |
282 ms |
92360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
123 ms |
92096 KB |
Output is correct |
2 |
Correct |
146 ms |
92100 KB |
Output is correct |
3 |
Correct |
122 ms |
92108 KB |
Output is correct |
4 |
Correct |
126 ms |
92164 KB |
Output is correct |
5 |
Correct |
120 ms |
92108 KB |
Output is correct |
6 |
Correct |
131 ms |
92108 KB |
Output is correct |
7 |
Correct |
125 ms |
92236 KB |
Output is correct |
8 |
Correct |
119 ms |
92140 KB |
Output is correct |
9 |
Correct |
124 ms |
92188 KB |
Output is correct |
10 |
Correct |
121 ms |
92188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
78540 KB |
Output is correct |
2 |
Correct |
32 ms |
78504 KB |
Output is correct |
3 |
Correct |
32 ms |
78492 KB |
Output is correct |
4 |
Correct |
31 ms |
78608 KB |
Output is correct |
5 |
Correct |
31 ms |
78588 KB |
Output is correct |
6 |
Correct |
30 ms |
78588 KB |
Output is correct |
7 |
Correct |
31 ms |
78556 KB |
Output is correct |
8 |
Correct |
31 ms |
78548 KB |
Output is correct |
9 |
Correct |
31 ms |
78540 KB |
Output is correct |
10 |
Correct |
35 ms |
78540 KB |
Output is correct |
11 |
Correct |
30 ms |
78528 KB |
Output is correct |
12 |
Correct |
33 ms |
78552 KB |
Output is correct |
13 |
Correct |
31 ms |
78548 KB |
Output is correct |
14 |
Correct |
31 ms |
78588 KB |
Output is correct |
15 |
Correct |
32 ms |
78620 KB |
Output is correct |
16 |
Correct |
30 ms |
78588 KB |
Output is correct |
17 |
Correct |
32 ms |
78544 KB |
Output is correct |
18 |
Correct |
31 ms |
78604 KB |
Output is correct |
19 |
Correct |
32 ms |
78588 KB |
Output is correct |
20 |
Correct |
32 ms |
78556 KB |
Output is correct |
21 |
Correct |
33 ms |
78616 KB |
Output is correct |
22 |
Correct |
35 ms |
78604 KB |
Output is correct |
23 |
Correct |
33 ms |
78604 KB |
Output is correct |
24 |
Correct |
29 ms |
78636 KB |
Output is correct |
25 |
Correct |
30 ms |
78552 KB |
Output is correct |
26 |
Correct |
31 ms |
78548 KB |
Output is correct |
27 |
Correct |
32 ms |
78724 KB |
Output is correct |
28 |
Correct |
30 ms |
78620 KB |
Output is correct |
29 |
Correct |
30 ms |
78524 KB |
Output is correct |
30 |
Correct |
28 ms |
78500 KB |
Output is correct |
31 |
Correct |
31 ms |
78676 KB |
Output is correct |
32 |
Correct |
31 ms |
78484 KB |
Output is correct |
33 |
Correct |
30 ms |
78544 KB |
Output is correct |
34 |
Correct |
29 ms |
78596 KB |
Output is correct |
35 |
Correct |
31 ms |
78568 KB |
Output is correct |
36 |
Correct |
28 ms |
78540 KB |
Output is correct |
37 |
Correct |
30 ms |
78508 KB |
Output is correct |
38 |
Correct |
30 ms |
78596 KB |
Output is correct |
39 |
Correct |
29 ms |
78556 KB |
Output is correct |
40 |
Correct |
30 ms |
78492 KB |
Output is correct |
41 |
Correct |
30 ms |
78548 KB |
Output is correct |
42 |
Correct |
30 ms |
78600 KB |
Output is correct |
43 |
Correct |
30 ms |
78540 KB |
Output is correct |
44 |
Correct |
29 ms |
78548 KB |
Output is correct |
45 |
Correct |
30 ms |
78560 KB |
Output is correct |
46 |
Correct |
31 ms |
78592 KB |
Output is correct |
47 |
Correct |
30 ms |
78548 KB |
Output is correct |
48 |
Correct |
30 ms |
78564 KB |
Output is correct |
49 |
Correct |
29 ms |
78484 KB |
Output is correct |
50 |
Correct |
30 ms |
78548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
78540 KB |
Output is correct |
2 |
Correct |
32 ms |
78504 KB |
Output is correct |
3 |
Correct |
32 ms |
78492 KB |
Output is correct |
4 |
Correct |
31 ms |
78608 KB |
Output is correct |
5 |
Correct |
31 ms |
78588 KB |
Output is correct |
6 |
Correct |
30 ms |
78588 KB |
Output is correct |
7 |
Correct |
31 ms |
78556 KB |
Output is correct |
8 |
Correct |
31 ms |
78548 KB |
Output is correct |
9 |
Correct |
31 ms |
78540 KB |
Output is correct |
10 |
Correct |
35 ms |
78540 KB |
Output is correct |
11 |
Correct |
30 ms |
78528 KB |
Output is correct |
12 |
Correct |
33 ms |
78552 KB |
Output is correct |
13 |
Correct |
31 ms |
78548 KB |
Output is correct |
14 |
Correct |
31 ms |
78588 KB |
Output is correct |
15 |
Correct |
32 ms |
78620 KB |
Output is correct |
16 |
Correct |
30 ms |
78588 KB |
Output is correct |
17 |
Correct |
32 ms |
78544 KB |
Output is correct |
18 |
Correct |
31 ms |
78604 KB |
Output is correct |
19 |
Correct |
32 ms |
78588 KB |
Output is correct |
20 |
Correct |
32 ms |
78556 KB |
Output is correct |
21 |
Correct |
33 ms |
78616 KB |
Output is correct |
22 |
Correct |
35 ms |
78604 KB |
Output is correct |
23 |
Correct |
33 ms |
78604 KB |
Output is correct |
24 |
Correct |
29 ms |
78636 KB |
Output is correct |
25 |
Correct |
30 ms |
78552 KB |
Output is correct |
26 |
Correct |
31 ms |
78548 KB |
Output is correct |
27 |
Correct |
32 ms |
78724 KB |
Output is correct |
28 |
Correct |
30 ms |
78620 KB |
Output is correct |
29 |
Correct |
30 ms |
78524 KB |
Output is correct |
30 |
Correct |
199 ms |
89480 KB |
Output is correct |
31 |
Correct |
236 ms |
90548 KB |
Output is correct |
32 |
Correct |
173 ms |
89020 KB |
Output is correct |
33 |
Correct |
219 ms |
90556 KB |
Output is correct |
34 |
Correct |
232 ms |
90456 KB |
Output is correct |
35 |
Correct |
232 ms |
90448 KB |
Output is correct |
36 |
Correct |
219 ms |
89924 KB |
Output is correct |
37 |
Correct |
270 ms |
92528 KB |
Output is correct |
38 |
Correct |
247 ms |
92644 KB |
Output is correct |
39 |
Correct |
256 ms |
92916 KB |
Output is correct |
40 |
Correct |
276 ms |
92368 KB |
Output is correct |
41 |
Correct |
199 ms |
89364 KB |
Output is correct |
42 |
Correct |
229 ms |
90684 KB |
Output is correct |
43 |
Correct |
262 ms |
92680 KB |
Output is correct |
44 |
Correct |
282 ms |
92360 KB |
Output is correct |
45 |
Correct |
123 ms |
92096 KB |
Output is correct |
46 |
Correct |
146 ms |
92100 KB |
Output is correct |
47 |
Correct |
122 ms |
92108 KB |
Output is correct |
48 |
Correct |
126 ms |
92164 KB |
Output is correct |
49 |
Correct |
120 ms |
92108 KB |
Output is correct |
50 |
Correct |
131 ms |
92108 KB |
Output is correct |
51 |
Correct |
125 ms |
92236 KB |
Output is correct |
52 |
Correct |
119 ms |
92140 KB |
Output is correct |
53 |
Correct |
124 ms |
92188 KB |
Output is correct |
54 |
Correct |
121 ms |
92188 KB |
Output is correct |
55 |
Correct |
28 ms |
78500 KB |
Output is correct |
56 |
Correct |
31 ms |
78676 KB |
Output is correct |
57 |
Correct |
31 ms |
78484 KB |
Output is correct |
58 |
Correct |
30 ms |
78544 KB |
Output is correct |
59 |
Correct |
29 ms |
78596 KB |
Output is correct |
60 |
Correct |
31 ms |
78568 KB |
Output is correct |
61 |
Correct |
28 ms |
78540 KB |
Output is correct |
62 |
Correct |
30 ms |
78508 KB |
Output is correct |
63 |
Correct |
30 ms |
78596 KB |
Output is correct |
64 |
Correct |
29 ms |
78556 KB |
Output is correct |
65 |
Correct |
30 ms |
78492 KB |
Output is correct |
66 |
Correct |
30 ms |
78548 KB |
Output is correct |
67 |
Correct |
30 ms |
78600 KB |
Output is correct |
68 |
Correct |
30 ms |
78540 KB |
Output is correct |
69 |
Correct |
29 ms |
78548 KB |
Output is correct |
70 |
Correct |
30 ms |
78560 KB |
Output is correct |
71 |
Correct |
31 ms |
78592 KB |
Output is correct |
72 |
Correct |
30 ms |
78548 KB |
Output is correct |
73 |
Correct |
30 ms |
78564 KB |
Output is correct |
74 |
Correct |
29 ms |
78484 KB |
Output is correct |
75 |
Correct |
30 ms |
78548 KB |
Output is correct |
76 |
Correct |
107 ms |
88508 KB |
Output is correct |
77 |
Correct |
110 ms |
88556 KB |
Output is correct |
78 |
Correct |
110 ms |
87872 KB |
Output is correct |
79 |
Correct |
100 ms |
88132 KB |
Output is correct |
80 |
Correct |
111 ms |
88776 KB |
Output is correct |
81 |
Correct |
108 ms |
87992 KB |
Output is correct |
82 |
Correct |
108 ms |
88012 KB |
Output is correct |
83 |
Correct |
103 ms |
88388 KB |
Output is correct |
84 |
Correct |
103 ms |
88252 KB |
Output is correct |
85 |
Correct |
104 ms |
88548 KB |
Output is correct |
86 |
Correct |
104 ms |
87876 KB |
Output is correct |
87 |
Correct |
106 ms |
87776 KB |
Output is correct |
88 |
Correct |
99 ms |
88200 KB |
Output is correct |
89 |
Correct |
98 ms |
88000 KB |
Output is correct |
90 |
Correct |
102 ms |
87868 KB |
Output is correct |
91 |
Correct |
94 ms |
87756 KB |
Output is correct |
92 |
Correct |
254 ms |
91552 KB |
Output is correct |
93 |
Correct |
227 ms |
90536 KB |
Output is correct |
94 |
Correct |
93 ms |
87372 KB |
Output is correct |
95 |
Correct |
104 ms |
88880 KB |
Output is correct |
96 |
Correct |
96 ms |
87756 KB |
Output is correct |
97 |
Correct |
106 ms |
88136 KB |
Output is correct |
98 |
Correct |
98 ms |
88252 KB |
Output is correct |
99 |
Correct |
96 ms |
87876 KB |
Output is correct |
100 |
Correct |
115 ms |
88216 KB |
Output is correct |