/*
IN THE NAME OF GOD
*/
#include <bits/stdc++.h>
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;
#define F first
#define S second
#define Mp make_pair
#define pb push_back
#define pf push_front
#define size(x) ((ll)x.size())
#define all(x) (x).begin(),(x).end()
#define kill(x) cout << x << '\n', exit(0);
#define fuck(x) cout << "(" << #x << " , " << x << ")" << endl
#define endl '\n'
const int N = 5e5+23, lg = 19;
ll Mod = 1e9+7; //998244353;
inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
ll ans = 1;
a=MOD(a, mod);
while (b) {
if (b & 1) ans = MOD(ans*a, mod);
b >>= 1;
a = MOD(a*a, mod);
}
return ans;
}
ll t, n, a[N], dp[N], pd[N], seg[4*N];
void update(int ind, ll val) {
if(ind == 0) return;
if(ind >= (1<<lg)) {
seg[ind] = val;
} else {
seg[ind] = min(seg[2*ind], seg[2*ind+1]);
}
update(ind/2, val);
}
ll query(ll val, int ind=1) {
if(ind >= (1<<lg)) {
return (ind - (1<<lg) + 1);
}
if(seg[2*ind+1] <= val) return query(val, 2*ind+1);
return query(val, 2*ind);
}
int main () {
ios_base::sync_with_stdio(false), cin.tie(0);
cin>>n;
for(int i=1; i<=n; i++) {
cin>>a[i];
a[i] += a[i-1];
}
fill(seg, seg+4*N, (ll)1e18);
update((1<<lg), 0);
for(int i=1; i<=n; i++) {
ll x = query(a[i]) - 1;
dp[i] = a[i] - a[x], pd[i] = pd[x] + 1;
update(i+(1<<lg), dp[i]+a[i]);
}
cout<<pd[n]<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
21080 KB |
Output is correct |
2 |
Correct |
3 ms |
21084 KB |
Output is correct |
3 |
Correct |
3 ms |
21084 KB |
Output is correct |
4 |
Correct |
3 ms |
21084 KB |
Output is correct |
5 |
Correct |
3 ms |
21140 KB |
Output is correct |
6 |
Correct |
3 ms |
21084 KB |
Output is correct |
7 |
Correct |
3 ms |
21080 KB |
Output is correct |
8 |
Correct |
3 ms |
21084 KB |
Output is correct |
9 |
Correct |
3 ms |
21084 KB |
Output is correct |
10 |
Correct |
3 ms |
21084 KB |
Output is correct |
11 |
Correct |
3 ms |
21084 KB |
Output is correct |
12 |
Correct |
3 ms |
21084 KB |
Output is correct |
13 |
Correct |
3 ms |
21084 KB |
Output is correct |
14 |
Correct |
3 ms |
21084 KB |
Output is correct |
15 |
Correct |
4 ms |
21080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
21080 KB |
Output is correct |
2 |
Correct |
3 ms |
21084 KB |
Output is correct |
3 |
Correct |
3 ms |
21084 KB |
Output is correct |
4 |
Correct |
3 ms |
21084 KB |
Output is correct |
5 |
Correct |
3 ms |
21140 KB |
Output is correct |
6 |
Correct |
3 ms |
21084 KB |
Output is correct |
7 |
Correct |
3 ms |
21080 KB |
Output is correct |
8 |
Correct |
3 ms |
21084 KB |
Output is correct |
9 |
Correct |
3 ms |
21084 KB |
Output is correct |
10 |
Correct |
3 ms |
21084 KB |
Output is correct |
11 |
Correct |
3 ms |
21084 KB |
Output is correct |
12 |
Correct |
3 ms |
21084 KB |
Output is correct |
13 |
Correct |
3 ms |
21084 KB |
Output is correct |
14 |
Correct |
3 ms |
21084 KB |
Output is correct |
15 |
Correct |
4 ms |
21080 KB |
Output is correct |
16 |
Correct |
3 ms |
21080 KB |
Output is correct |
17 |
Correct |
3 ms |
21336 KB |
Output is correct |
18 |
Correct |
3 ms |
21084 KB |
Output is correct |
19 |
Correct |
3 ms |
21084 KB |
Output is correct |
20 |
Correct |
3 ms |
21084 KB |
Output is correct |
21 |
Correct |
3 ms |
21084 KB |
Output is correct |
22 |
Correct |
3 ms |
21084 KB |
Output is correct |
23 |
Correct |
3 ms |
21084 KB |
Output is correct |
24 |
Correct |
3 ms |
21080 KB |
Output is correct |
25 |
Correct |
3 ms |
21084 KB |
Output is correct |
26 |
Correct |
3 ms |
21084 KB |
Output is correct |
27 |
Correct |
4 ms |
21084 KB |
Output is correct |
28 |
Correct |
3 ms |
21140 KB |
Output is correct |
29 |
Correct |
3 ms |
21084 KB |
Output is correct |
30 |
Correct |
3 ms |
21084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
21080 KB |
Output is correct |
2 |
Correct |
3 ms |
21084 KB |
Output is correct |
3 |
Correct |
3 ms |
21084 KB |
Output is correct |
4 |
Correct |
3 ms |
21084 KB |
Output is correct |
5 |
Correct |
3 ms |
21140 KB |
Output is correct |
6 |
Correct |
3 ms |
21084 KB |
Output is correct |
7 |
Correct |
3 ms |
21080 KB |
Output is correct |
8 |
Correct |
3 ms |
21084 KB |
Output is correct |
9 |
Correct |
3 ms |
21084 KB |
Output is correct |
10 |
Correct |
3 ms |
21084 KB |
Output is correct |
11 |
Correct |
3 ms |
21084 KB |
Output is correct |
12 |
Correct |
3 ms |
21084 KB |
Output is correct |
13 |
Correct |
3 ms |
21084 KB |
Output is correct |
14 |
Correct |
3 ms |
21084 KB |
Output is correct |
15 |
Correct |
4 ms |
21080 KB |
Output is correct |
16 |
Correct |
3 ms |
21080 KB |
Output is correct |
17 |
Correct |
3 ms |
21336 KB |
Output is correct |
18 |
Correct |
3 ms |
21084 KB |
Output is correct |
19 |
Correct |
3 ms |
21084 KB |
Output is correct |
20 |
Correct |
3 ms |
21084 KB |
Output is correct |
21 |
Correct |
3 ms |
21084 KB |
Output is correct |
22 |
Correct |
3 ms |
21084 KB |
Output is correct |
23 |
Correct |
3 ms |
21084 KB |
Output is correct |
24 |
Correct |
3 ms |
21080 KB |
Output is correct |
25 |
Correct |
3 ms |
21084 KB |
Output is correct |
26 |
Correct |
3 ms |
21084 KB |
Output is correct |
27 |
Correct |
4 ms |
21084 KB |
Output is correct |
28 |
Correct |
3 ms |
21140 KB |
Output is correct |
29 |
Correct |
3 ms |
21084 KB |
Output is correct |
30 |
Correct |
3 ms |
21084 KB |
Output is correct |
31 |
Correct |
4 ms |
21080 KB |
Output is correct |
32 |
Correct |
4 ms |
21084 KB |
Output is correct |
33 |
Correct |
4 ms |
21084 KB |
Output is correct |
34 |
Correct |
4 ms |
21084 KB |
Output is correct |
35 |
Correct |
4 ms |
21084 KB |
Output is correct |
36 |
Correct |
3 ms |
21084 KB |
Output is correct |
37 |
Correct |
3 ms |
21164 KB |
Output is correct |
38 |
Correct |
4 ms |
21084 KB |
Output is correct |
39 |
Correct |
3 ms |
21084 KB |
Output is correct |
40 |
Correct |
4 ms |
21080 KB |
Output is correct |
41 |
Correct |
3 ms |
21084 KB |
Output is correct |
42 |
Correct |
3 ms |
21084 KB |
Output is correct |
43 |
Correct |
4 ms |
21084 KB |
Output is correct |
44 |
Correct |
3 ms |
21080 KB |
Output is correct |
45 |
Correct |
3 ms |
21080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
21080 KB |
Output is correct |
2 |
Correct |
3 ms |
21084 KB |
Output is correct |
3 |
Correct |
3 ms |
21084 KB |
Output is correct |
4 |
Correct |
3 ms |
21084 KB |
Output is correct |
5 |
Correct |
3 ms |
21140 KB |
Output is correct |
6 |
Correct |
3 ms |
21084 KB |
Output is correct |
7 |
Correct |
3 ms |
21080 KB |
Output is correct |
8 |
Correct |
3 ms |
21084 KB |
Output is correct |
9 |
Correct |
3 ms |
21084 KB |
Output is correct |
10 |
Correct |
3 ms |
21084 KB |
Output is correct |
11 |
Correct |
3 ms |
21084 KB |
Output is correct |
12 |
Correct |
3 ms |
21084 KB |
Output is correct |
13 |
Correct |
3 ms |
21084 KB |
Output is correct |
14 |
Correct |
3 ms |
21084 KB |
Output is correct |
15 |
Correct |
4 ms |
21080 KB |
Output is correct |
16 |
Correct |
3 ms |
21080 KB |
Output is correct |
17 |
Correct |
3 ms |
21336 KB |
Output is correct |
18 |
Correct |
3 ms |
21084 KB |
Output is correct |
19 |
Correct |
3 ms |
21084 KB |
Output is correct |
20 |
Correct |
3 ms |
21084 KB |
Output is correct |
21 |
Correct |
3 ms |
21084 KB |
Output is correct |
22 |
Correct |
3 ms |
21084 KB |
Output is correct |
23 |
Correct |
3 ms |
21084 KB |
Output is correct |
24 |
Correct |
3 ms |
21080 KB |
Output is correct |
25 |
Correct |
3 ms |
21084 KB |
Output is correct |
26 |
Correct |
3 ms |
21084 KB |
Output is correct |
27 |
Correct |
4 ms |
21084 KB |
Output is correct |
28 |
Correct |
3 ms |
21140 KB |
Output is correct |
29 |
Correct |
3 ms |
21084 KB |
Output is correct |
30 |
Correct |
3 ms |
21084 KB |
Output is correct |
31 |
Correct |
4 ms |
21080 KB |
Output is correct |
32 |
Correct |
4 ms |
21084 KB |
Output is correct |
33 |
Correct |
4 ms |
21084 KB |
Output is correct |
34 |
Correct |
4 ms |
21084 KB |
Output is correct |
35 |
Correct |
4 ms |
21084 KB |
Output is correct |
36 |
Correct |
3 ms |
21084 KB |
Output is correct |
37 |
Correct |
3 ms |
21164 KB |
Output is correct |
38 |
Correct |
4 ms |
21084 KB |
Output is correct |
39 |
Correct |
3 ms |
21084 KB |
Output is correct |
40 |
Correct |
4 ms |
21080 KB |
Output is correct |
41 |
Correct |
3 ms |
21084 KB |
Output is correct |
42 |
Correct |
3 ms |
21084 KB |
Output is correct |
43 |
Correct |
4 ms |
21084 KB |
Output is correct |
44 |
Correct |
3 ms |
21080 KB |
Output is correct |
45 |
Correct |
3 ms |
21080 KB |
Output is correct |
46 |
Correct |
21 ms |
21160 KB |
Output is correct |
47 |
Correct |
19 ms |
21944 KB |
Output is correct |
48 |
Correct |
21 ms |
21840 KB |
Output is correct |
49 |
Correct |
22 ms |
21852 KB |
Output is correct |
50 |
Correct |
21 ms |
22108 KB |
Output is correct |
51 |
Correct |
21 ms |
22108 KB |
Output is correct |
52 |
Correct |
12 ms |
21596 KB |
Output is correct |
53 |
Correct |
11 ms |
21596 KB |
Output is correct |
54 |
Correct |
18 ms |
21340 KB |
Output is correct |
55 |
Correct |
21 ms |
22108 KB |
Output is correct |
56 |
Correct |
19 ms |
21572 KB |
Output is correct |
57 |
Correct |
19 ms |
21576 KB |
Output is correct |
58 |
Correct |
19 ms |
21584 KB |
Output is correct |
59 |
Correct |
20 ms |
21592 KB |
Output is correct |
60 |
Correct |
19 ms |
21596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
21080 KB |
Output is correct |
2 |
Correct |
3 ms |
21084 KB |
Output is correct |
3 |
Correct |
3 ms |
21084 KB |
Output is correct |
4 |
Correct |
3 ms |
21084 KB |
Output is correct |
5 |
Correct |
3 ms |
21140 KB |
Output is correct |
6 |
Correct |
3 ms |
21084 KB |
Output is correct |
7 |
Correct |
3 ms |
21080 KB |
Output is correct |
8 |
Correct |
3 ms |
21084 KB |
Output is correct |
9 |
Correct |
3 ms |
21084 KB |
Output is correct |
10 |
Correct |
3 ms |
21084 KB |
Output is correct |
11 |
Correct |
3 ms |
21084 KB |
Output is correct |
12 |
Correct |
3 ms |
21084 KB |
Output is correct |
13 |
Correct |
3 ms |
21084 KB |
Output is correct |
14 |
Correct |
3 ms |
21084 KB |
Output is correct |
15 |
Correct |
4 ms |
21080 KB |
Output is correct |
16 |
Correct |
3 ms |
21080 KB |
Output is correct |
17 |
Correct |
3 ms |
21336 KB |
Output is correct |
18 |
Correct |
3 ms |
21084 KB |
Output is correct |
19 |
Correct |
3 ms |
21084 KB |
Output is correct |
20 |
Correct |
3 ms |
21084 KB |
Output is correct |
21 |
Correct |
3 ms |
21084 KB |
Output is correct |
22 |
Correct |
3 ms |
21084 KB |
Output is correct |
23 |
Correct |
3 ms |
21084 KB |
Output is correct |
24 |
Correct |
3 ms |
21080 KB |
Output is correct |
25 |
Correct |
3 ms |
21084 KB |
Output is correct |
26 |
Correct |
3 ms |
21084 KB |
Output is correct |
27 |
Correct |
4 ms |
21084 KB |
Output is correct |
28 |
Correct |
3 ms |
21140 KB |
Output is correct |
29 |
Correct |
3 ms |
21084 KB |
Output is correct |
30 |
Correct |
3 ms |
21084 KB |
Output is correct |
31 |
Correct |
4 ms |
21080 KB |
Output is correct |
32 |
Correct |
4 ms |
21084 KB |
Output is correct |
33 |
Correct |
4 ms |
21084 KB |
Output is correct |
34 |
Correct |
4 ms |
21084 KB |
Output is correct |
35 |
Correct |
4 ms |
21084 KB |
Output is correct |
36 |
Correct |
3 ms |
21084 KB |
Output is correct |
37 |
Correct |
3 ms |
21164 KB |
Output is correct |
38 |
Correct |
4 ms |
21084 KB |
Output is correct |
39 |
Correct |
3 ms |
21084 KB |
Output is correct |
40 |
Correct |
4 ms |
21080 KB |
Output is correct |
41 |
Correct |
3 ms |
21084 KB |
Output is correct |
42 |
Correct |
3 ms |
21084 KB |
Output is correct |
43 |
Correct |
4 ms |
21084 KB |
Output is correct |
44 |
Correct |
3 ms |
21080 KB |
Output is correct |
45 |
Correct |
3 ms |
21080 KB |
Output is correct |
46 |
Correct |
21 ms |
21160 KB |
Output is correct |
47 |
Correct |
19 ms |
21944 KB |
Output is correct |
48 |
Correct |
21 ms |
21840 KB |
Output is correct |
49 |
Correct |
22 ms |
21852 KB |
Output is correct |
50 |
Correct |
21 ms |
22108 KB |
Output is correct |
51 |
Correct |
21 ms |
22108 KB |
Output is correct |
52 |
Correct |
12 ms |
21596 KB |
Output is correct |
53 |
Correct |
11 ms |
21596 KB |
Output is correct |
54 |
Correct |
18 ms |
21340 KB |
Output is correct |
55 |
Correct |
21 ms |
22108 KB |
Output is correct |
56 |
Correct |
19 ms |
21572 KB |
Output is correct |
57 |
Correct |
19 ms |
21576 KB |
Output is correct |
58 |
Correct |
19 ms |
21584 KB |
Output is correct |
59 |
Correct |
20 ms |
21592 KB |
Output is correct |
60 |
Correct |
19 ms |
21596 KB |
Output is correct |
61 |
Correct |
100 ms |
29776 KB |
Output is correct |
62 |
Correct |
94 ms |
29792 KB |
Output is correct |
63 |
Correct |
88 ms |
30032 KB |
Output is correct |
64 |
Correct |
99 ms |
32212 KB |
Output is correct |
65 |
Correct |
100 ms |
32592 KB |
Output is correct |
66 |
Correct |
115 ms |
32672 KB |
Output is correct |
67 |
Correct |
79 ms |
31132 KB |
Output is correct |
68 |
Correct |
40 ms |
28984 KB |
Output is correct |
69 |
Correct |
82 ms |
28884 KB |
Output is correct |
70 |
Correct |
102 ms |
32592 KB |
Output is correct |
71 |
Correct |
90 ms |
29792 KB |
Output is correct |
72 |
Correct |
91 ms |
30032 KB |
Output is correct |
73 |
Correct |
100 ms |
30548 KB |
Output is correct |
74 |
Correct |
92 ms |
31056 KB |
Output is correct |
75 |
Correct |
91 ms |
31152 KB |
Output is correct |