#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
const int N = 5*1e5+11;
int n, off = 1;
ll a[N], b[N], z[N], ak[N];
ll t[4*N], lazy[4*N];
void clear (int x) {
t[x] += lazy[x];
if (x < off) {
lazy[x*2] += lazy[x];
lazy[x*2+1] += lazy[x];
}
lazy[x] = 0;
}
ll update(int cf, int ct, int lf, int lt, ll c, int node) {
clear(node);
if (cf > lt || ct < lf) return t[node];
if (cf >= lf && ct <= lt) {
lazy[node] += c;
clear(node);
return t[node];
}
int mid = (cf+ct)/2;
update(cf, mid, lf, lt, c, node*2);
update(mid+1, ct, lf, lt, c, node*2+1);
return t[node] = max(t[node*2], t[node*2+1]);
}
int upit(int cf, int ct, int node) {
clear(node); clear(node*2); clear(node*2+1);
int mid = (cf+ct)/2;
if (cf == ct) return cf;
if (t[node*2+1] >= 0) return upit(mid+1, ct, node*2+1);
return upit(cf, mid, node*2);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
while (off < n+1) off *= 2;
for (int i=0;i<n;i++) {
cin >> a[i];
ak[i] = a[i];
if (i > 0) ak[i] += ak[i-1];
}
memset(t, -1, sizeof t);
b[0] = a[0]; z[0] = -1;
update(0, off-1, 0, 0, a[0]+1, 1);
for (int i=1;i<n;i++) {
update(0, off-1, i, i, -b[i-1]+1, 1);
update(0, off-1, 0, i, a[i], 1);
int pos = upit(0, off-1, 1);
z[i] = pos-1;
b[i] = ak[i];
if (pos > 0) b[i] -= ak[pos-1];
}
int br = 0;
int x = n-1;
while (x >= 0) {
br++;
x = z[x];
}
cout << br;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
15980 KB |
Output is correct |
2 |
Correct |
9 ms |
15980 KB |
Output is correct |
3 |
Correct |
9 ms |
15980 KB |
Output is correct |
4 |
Correct |
9 ms |
15980 KB |
Output is correct |
5 |
Correct |
9 ms |
15980 KB |
Output is correct |
6 |
Correct |
9 ms |
15980 KB |
Output is correct |
7 |
Correct |
9 ms |
15980 KB |
Output is correct |
8 |
Correct |
9 ms |
15980 KB |
Output is correct |
9 |
Correct |
9 ms |
16108 KB |
Output is correct |
10 |
Correct |
9 ms |
15980 KB |
Output is correct |
11 |
Correct |
9 ms |
15980 KB |
Output is correct |
12 |
Correct |
9 ms |
15980 KB |
Output is correct |
13 |
Correct |
9 ms |
15980 KB |
Output is correct |
14 |
Correct |
9 ms |
15980 KB |
Output is correct |
15 |
Correct |
9 ms |
15980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
15980 KB |
Output is correct |
2 |
Correct |
9 ms |
15980 KB |
Output is correct |
3 |
Correct |
9 ms |
15980 KB |
Output is correct |
4 |
Correct |
9 ms |
15980 KB |
Output is correct |
5 |
Correct |
9 ms |
15980 KB |
Output is correct |
6 |
Correct |
9 ms |
15980 KB |
Output is correct |
7 |
Correct |
9 ms |
15980 KB |
Output is correct |
8 |
Correct |
9 ms |
15980 KB |
Output is correct |
9 |
Correct |
9 ms |
16108 KB |
Output is correct |
10 |
Correct |
9 ms |
15980 KB |
Output is correct |
11 |
Correct |
9 ms |
15980 KB |
Output is correct |
12 |
Correct |
9 ms |
15980 KB |
Output is correct |
13 |
Correct |
9 ms |
15980 KB |
Output is correct |
14 |
Correct |
9 ms |
15980 KB |
Output is correct |
15 |
Correct |
9 ms |
15980 KB |
Output is correct |
16 |
Correct |
9 ms |
16108 KB |
Output is correct |
17 |
Correct |
9 ms |
16108 KB |
Output is correct |
18 |
Correct |
9 ms |
16108 KB |
Output is correct |
19 |
Correct |
9 ms |
16108 KB |
Output is correct |
20 |
Correct |
10 ms |
16256 KB |
Output is correct |
21 |
Correct |
9 ms |
16108 KB |
Output is correct |
22 |
Correct |
8 ms |
16108 KB |
Output is correct |
23 |
Correct |
8 ms |
16108 KB |
Output is correct |
24 |
Correct |
9 ms |
16108 KB |
Output is correct |
25 |
Correct |
9 ms |
16108 KB |
Output is correct |
26 |
Correct |
8 ms |
16108 KB |
Output is correct |
27 |
Correct |
9 ms |
16108 KB |
Output is correct |
28 |
Correct |
9 ms |
16128 KB |
Output is correct |
29 |
Correct |
8 ms |
16108 KB |
Output is correct |
30 |
Correct |
9 ms |
16108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
15980 KB |
Output is correct |
2 |
Correct |
9 ms |
15980 KB |
Output is correct |
3 |
Correct |
9 ms |
15980 KB |
Output is correct |
4 |
Correct |
9 ms |
15980 KB |
Output is correct |
5 |
Correct |
9 ms |
15980 KB |
Output is correct |
6 |
Correct |
9 ms |
15980 KB |
Output is correct |
7 |
Correct |
9 ms |
15980 KB |
Output is correct |
8 |
Correct |
9 ms |
15980 KB |
Output is correct |
9 |
Correct |
9 ms |
16108 KB |
Output is correct |
10 |
Correct |
9 ms |
15980 KB |
Output is correct |
11 |
Correct |
9 ms |
15980 KB |
Output is correct |
12 |
Correct |
9 ms |
15980 KB |
Output is correct |
13 |
Correct |
9 ms |
15980 KB |
Output is correct |
14 |
Correct |
9 ms |
15980 KB |
Output is correct |
15 |
Correct |
9 ms |
15980 KB |
Output is correct |
16 |
Correct |
9 ms |
16108 KB |
Output is correct |
17 |
Correct |
9 ms |
16108 KB |
Output is correct |
18 |
Correct |
9 ms |
16108 KB |
Output is correct |
19 |
Correct |
9 ms |
16108 KB |
Output is correct |
20 |
Correct |
10 ms |
16256 KB |
Output is correct |
21 |
Correct |
9 ms |
16108 KB |
Output is correct |
22 |
Correct |
8 ms |
16108 KB |
Output is correct |
23 |
Correct |
8 ms |
16108 KB |
Output is correct |
24 |
Correct |
9 ms |
16108 KB |
Output is correct |
25 |
Correct |
9 ms |
16108 KB |
Output is correct |
26 |
Correct |
8 ms |
16108 KB |
Output is correct |
27 |
Correct |
9 ms |
16108 KB |
Output is correct |
28 |
Correct |
9 ms |
16128 KB |
Output is correct |
29 |
Correct |
8 ms |
16108 KB |
Output is correct |
30 |
Correct |
9 ms |
16108 KB |
Output is correct |
31 |
Correct |
11 ms |
16236 KB |
Output is correct |
32 |
Correct |
10 ms |
16236 KB |
Output is correct |
33 |
Correct |
13 ms |
16236 KB |
Output is correct |
34 |
Correct |
10 ms |
16236 KB |
Output is correct |
35 |
Correct |
13 ms |
16236 KB |
Output is correct |
36 |
Correct |
12 ms |
16236 KB |
Output is correct |
37 |
Correct |
13 ms |
16240 KB |
Output is correct |
38 |
Correct |
11 ms |
16236 KB |
Output is correct |
39 |
Correct |
13 ms |
16236 KB |
Output is correct |
40 |
Correct |
13 ms |
16240 KB |
Output is correct |
41 |
Correct |
11 ms |
16236 KB |
Output is correct |
42 |
Correct |
13 ms |
16236 KB |
Output is correct |
43 |
Correct |
10 ms |
16236 KB |
Output is correct |
44 |
Correct |
12 ms |
16236 KB |
Output is correct |
45 |
Correct |
12 ms |
16236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
15980 KB |
Output is correct |
2 |
Correct |
9 ms |
15980 KB |
Output is correct |
3 |
Correct |
9 ms |
15980 KB |
Output is correct |
4 |
Correct |
9 ms |
15980 KB |
Output is correct |
5 |
Correct |
9 ms |
15980 KB |
Output is correct |
6 |
Correct |
9 ms |
15980 KB |
Output is correct |
7 |
Correct |
9 ms |
15980 KB |
Output is correct |
8 |
Correct |
9 ms |
15980 KB |
Output is correct |
9 |
Correct |
9 ms |
16108 KB |
Output is correct |
10 |
Correct |
9 ms |
15980 KB |
Output is correct |
11 |
Correct |
9 ms |
15980 KB |
Output is correct |
12 |
Correct |
9 ms |
15980 KB |
Output is correct |
13 |
Correct |
9 ms |
15980 KB |
Output is correct |
14 |
Correct |
9 ms |
15980 KB |
Output is correct |
15 |
Correct |
9 ms |
15980 KB |
Output is correct |
16 |
Correct |
9 ms |
16108 KB |
Output is correct |
17 |
Correct |
9 ms |
16108 KB |
Output is correct |
18 |
Correct |
9 ms |
16108 KB |
Output is correct |
19 |
Correct |
9 ms |
16108 KB |
Output is correct |
20 |
Correct |
10 ms |
16256 KB |
Output is correct |
21 |
Correct |
9 ms |
16108 KB |
Output is correct |
22 |
Correct |
8 ms |
16108 KB |
Output is correct |
23 |
Correct |
8 ms |
16108 KB |
Output is correct |
24 |
Correct |
9 ms |
16108 KB |
Output is correct |
25 |
Correct |
9 ms |
16108 KB |
Output is correct |
26 |
Correct |
8 ms |
16108 KB |
Output is correct |
27 |
Correct |
9 ms |
16108 KB |
Output is correct |
28 |
Correct |
9 ms |
16128 KB |
Output is correct |
29 |
Correct |
8 ms |
16108 KB |
Output is correct |
30 |
Correct |
9 ms |
16108 KB |
Output is correct |
31 |
Correct |
11 ms |
16236 KB |
Output is correct |
32 |
Correct |
10 ms |
16236 KB |
Output is correct |
33 |
Correct |
13 ms |
16236 KB |
Output is correct |
34 |
Correct |
10 ms |
16236 KB |
Output is correct |
35 |
Correct |
13 ms |
16236 KB |
Output is correct |
36 |
Correct |
12 ms |
16236 KB |
Output is correct |
37 |
Correct |
13 ms |
16240 KB |
Output is correct |
38 |
Correct |
11 ms |
16236 KB |
Output is correct |
39 |
Correct |
13 ms |
16236 KB |
Output is correct |
40 |
Correct |
13 ms |
16240 KB |
Output is correct |
41 |
Correct |
11 ms |
16236 KB |
Output is correct |
42 |
Correct |
13 ms |
16236 KB |
Output is correct |
43 |
Correct |
10 ms |
16236 KB |
Output is correct |
44 |
Correct |
12 ms |
16236 KB |
Output is correct |
45 |
Correct |
12 ms |
16236 KB |
Output is correct |
46 |
Correct |
123 ms |
21156 KB |
Output is correct |
47 |
Correct |
114 ms |
22252 KB |
Output is correct |
48 |
Correct |
131 ms |
23148 KB |
Output is correct |
49 |
Correct |
118 ms |
23148 KB |
Output is correct |
50 |
Correct |
120 ms |
23276 KB |
Output is correct |
51 |
Correct |
123 ms |
23276 KB |
Output is correct |
52 |
Correct |
61 ms |
19692 KB |
Output is correct |
53 |
Correct |
39 ms |
18156 KB |
Output is correct |
54 |
Correct |
114 ms |
22508 KB |
Output is correct |
55 |
Correct |
119 ms |
23276 KB |
Output is correct |
56 |
Correct |
117 ms |
22764 KB |
Output is correct |
57 |
Correct |
115 ms |
22124 KB |
Output is correct |
58 |
Correct |
115 ms |
22440 KB |
Output is correct |
59 |
Correct |
117 ms |
23020 KB |
Output is correct |
60 |
Correct |
122 ms |
22892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
15980 KB |
Output is correct |
2 |
Correct |
9 ms |
15980 KB |
Output is correct |
3 |
Correct |
9 ms |
15980 KB |
Output is correct |
4 |
Correct |
9 ms |
15980 KB |
Output is correct |
5 |
Correct |
9 ms |
15980 KB |
Output is correct |
6 |
Correct |
9 ms |
15980 KB |
Output is correct |
7 |
Correct |
9 ms |
15980 KB |
Output is correct |
8 |
Correct |
9 ms |
15980 KB |
Output is correct |
9 |
Correct |
9 ms |
16108 KB |
Output is correct |
10 |
Correct |
9 ms |
15980 KB |
Output is correct |
11 |
Correct |
9 ms |
15980 KB |
Output is correct |
12 |
Correct |
9 ms |
15980 KB |
Output is correct |
13 |
Correct |
9 ms |
15980 KB |
Output is correct |
14 |
Correct |
9 ms |
15980 KB |
Output is correct |
15 |
Correct |
9 ms |
15980 KB |
Output is correct |
16 |
Correct |
9 ms |
16108 KB |
Output is correct |
17 |
Correct |
9 ms |
16108 KB |
Output is correct |
18 |
Correct |
9 ms |
16108 KB |
Output is correct |
19 |
Correct |
9 ms |
16108 KB |
Output is correct |
20 |
Correct |
10 ms |
16256 KB |
Output is correct |
21 |
Correct |
9 ms |
16108 KB |
Output is correct |
22 |
Correct |
8 ms |
16108 KB |
Output is correct |
23 |
Correct |
8 ms |
16108 KB |
Output is correct |
24 |
Correct |
9 ms |
16108 KB |
Output is correct |
25 |
Correct |
9 ms |
16108 KB |
Output is correct |
26 |
Correct |
8 ms |
16108 KB |
Output is correct |
27 |
Correct |
9 ms |
16108 KB |
Output is correct |
28 |
Correct |
9 ms |
16128 KB |
Output is correct |
29 |
Correct |
8 ms |
16108 KB |
Output is correct |
30 |
Correct |
9 ms |
16108 KB |
Output is correct |
31 |
Correct |
11 ms |
16236 KB |
Output is correct |
32 |
Correct |
10 ms |
16236 KB |
Output is correct |
33 |
Correct |
13 ms |
16236 KB |
Output is correct |
34 |
Correct |
10 ms |
16236 KB |
Output is correct |
35 |
Correct |
13 ms |
16236 KB |
Output is correct |
36 |
Correct |
12 ms |
16236 KB |
Output is correct |
37 |
Correct |
13 ms |
16240 KB |
Output is correct |
38 |
Correct |
11 ms |
16236 KB |
Output is correct |
39 |
Correct |
13 ms |
16236 KB |
Output is correct |
40 |
Correct |
13 ms |
16240 KB |
Output is correct |
41 |
Correct |
11 ms |
16236 KB |
Output is correct |
42 |
Correct |
13 ms |
16236 KB |
Output is correct |
43 |
Correct |
10 ms |
16236 KB |
Output is correct |
44 |
Correct |
12 ms |
16236 KB |
Output is correct |
45 |
Correct |
12 ms |
16236 KB |
Output is correct |
46 |
Correct |
123 ms |
21156 KB |
Output is correct |
47 |
Correct |
114 ms |
22252 KB |
Output is correct |
48 |
Correct |
131 ms |
23148 KB |
Output is correct |
49 |
Correct |
118 ms |
23148 KB |
Output is correct |
50 |
Correct |
120 ms |
23276 KB |
Output is correct |
51 |
Correct |
123 ms |
23276 KB |
Output is correct |
52 |
Correct |
61 ms |
19692 KB |
Output is correct |
53 |
Correct |
39 ms |
18156 KB |
Output is correct |
54 |
Correct |
114 ms |
22508 KB |
Output is correct |
55 |
Correct |
119 ms |
23276 KB |
Output is correct |
56 |
Correct |
117 ms |
22764 KB |
Output is correct |
57 |
Correct |
115 ms |
22124 KB |
Output is correct |
58 |
Correct |
115 ms |
22440 KB |
Output is correct |
59 |
Correct |
117 ms |
23020 KB |
Output is correct |
60 |
Correct |
122 ms |
22892 KB |
Output is correct |
61 |
Correct |
596 ms |
41580 KB |
Output is correct |
62 |
Correct |
595 ms |
42624 KB |
Output is correct |
63 |
Correct |
597 ms |
46316 KB |
Output is correct |
64 |
Runtime error |
679 ms |
99692 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
65 |
Halted |
0 ms |
0 KB |
- |