#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
typedef pair<long, long>pll;
// #define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll mod = (1000000007LL);
inline ll Mod(ll a, ll b){return (a%b);}
inline ll poww(ll a, ll b){ll res = 1;while (b > 0){if(b & 1) res = (res * a)%mod;a = (a * a)%mod;b >>= 1;}return res;}
ll gcd (ll a, ll b) { while (b) { a %= b,swap(a, b);}return a;}
void read(vector<int> &w, int n){w.resize(n);for(int i = 0; i < n; i++) cin>>w[i];}
void print(vector<int> &w){for(int i =0; i < sz(w); i++){if(i == sz(w) - 1) cout<<w[i]<<"\n";else cout<<w[i]<<" ";}}
int prodmod(vector<int> w);
int summod(vector<int> w);
///CUIDADO COM MAXN
#define N 500050
int n, m, q, k, v[N], ans;
ll pref[N];
pii w[N];
string s;
struct node{
ll a, b;
pll v;
node *l, *r;
node(ll a_, ll b_, ll v_ = 0, ll id=0){
a = a_, b = b_;
v = {v_, id};
l = r = NULL;
}
void upd(ll p, ll x, ll id){
if(p < a || p > b) return;
if(a == b){
v = max(v, {x, id});
return;
}
ll mid = (a+b)/2;
if(p <= mid){
if(l == NULL) l = new node(a, mid);
l->upd(p, x,id);
}
else{
if(r == NULL) r = new node(mid + 1, b);
r ->upd(p, x,id);
}
v = max(( (l == NULL)?pll(0,0):l->v ), ( (r == NULL)?pll(0,0): r-> v ));
}
pll query(ll i, ll j){
if(i > b || j < a) return {0,0};
if(i <= a && j >= b) return v;
pll A = (l == NULL)?pll(0,0):l->query(i, j);
pll B = (r == NULL)?pll(0,0):r->query(i, j);
return max(A,B);
}
};
int32_t main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>n;
for(int i = 1; i <= n; i++){
cin>>v[i];
pref[i]=pref[i-1]+v[i];
}
node *tree = new node(0, n*((ll)(1e9)));
// ll sum = 0, ans = 0, ant = -1;
vector<int> dp(n + 1);
for(int i = 1; i <= n; i++){
auto cara = tree->query(0, pref[i]);
dp[i] = cara.f + 1;
// if(cara.s == 0) cara.s = 1;
tree->upd(2LL*pref[i] - pref[cara.s], dp[i], i);
}
cout<<dp[n]<<"\n";
// if(sum >= ant) ans ++;
// cout<<ans<<"\n";
}
/*
CUIDADO COM MAXN, MOD, OVERFLOW
>Colocar (>DEFINE INT LONG LONG<) no inicio do template
>mod = (1e9 + 7), por padrao (NAO ESQUECER DE ALTERAR)
>NAO ESQUECER DEFINE INT LONG LONG
> N = 1 ?
*/
int summod(vector<int> w){int curr=0;for(int i=0;i<sz(w); i++){curr = (curr+w[i])%mod;if(curr<0)curr+=mod;}return curr;}
int prodmod(vector<int> w){int curr = 1;
for(int i = 0; i < sz(w); i++){if(w[i] >= mod) w[i] %= mod;curr = (curr * w[i]) % mod;if(curr < 0) curr += mod;}return curr;}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
896 KB |
Output is correct |
17 |
Correct |
2 ms |
1024 KB |
Output is correct |
18 |
Correct |
2 ms |
1280 KB |
Output is correct |
19 |
Correct |
2 ms |
1152 KB |
Output is correct |
20 |
Correct |
2 ms |
1280 KB |
Output is correct |
21 |
Correct |
2 ms |
1280 KB |
Output is correct |
22 |
Correct |
2 ms |
1152 KB |
Output is correct |
23 |
Correct |
1 ms |
896 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
1152 KB |
Output is correct |
26 |
Correct |
1 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
640 KB |
Output is correct |
30 |
Correct |
1 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
896 KB |
Output is correct |
17 |
Correct |
2 ms |
1024 KB |
Output is correct |
18 |
Correct |
2 ms |
1280 KB |
Output is correct |
19 |
Correct |
2 ms |
1152 KB |
Output is correct |
20 |
Correct |
2 ms |
1280 KB |
Output is correct |
21 |
Correct |
2 ms |
1280 KB |
Output is correct |
22 |
Correct |
2 ms |
1152 KB |
Output is correct |
23 |
Correct |
1 ms |
896 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
1152 KB |
Output is correct |
26 |
Correct |
1 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
640 KB |
Output is correct |
30 |
Correct |
1 ms |
640 KB |
Output is correct |
31 |
Correct |
7 ms |
3456 KB |
Output is correct |
32 |
Correct |
8 ms |
4384 KB |
Output is correct |
33 |
Correct |
9 ms |
5248 KB |
Output is correct |
34 |
Correct |
9 ms |
4992 KB |
Output is correct |
35 |
Correct |
11 ms |
6144 KB |
Output is correct |
36 |
Correct |
9 ms |
6144 KB |
Output is correct |
37 |
Correct |
11 ms |
5120 KB |
Output is correct |
38 |
Correct |
6 ms |
4224 KB |
Output is correct |
39 |
Correct |
5 ms |
1152 KB |
Output is correct |
40 |
Correct |
11 ms |
5632 KB |
Output is correct |
41 |
Correct |
5 ms |
1184 KB |
Output is correct |
42 |
Correct |
6 ms |
1920 KB |
Output is correct |
43 |
Correct |
5 ms |
1024 KB |
Output is correct |
44 |
Correct |
6 ms |
2688 KB |
Output is correct |
45 |
Correct |
7 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
896 KB |
Output is correct |
17 |
Correct |
2 ms |
1024 KB |
Output is correct |
18 |
Correct |
2 ms |
1280 KB |
Output is correct |
19 |
Correct |
2 ms |
1152 KB |
Output is correct |
20 |
Correct |
2 ms |
1280 KB |
Output is correct |
21 |
Correct |
2 ms |
1280 KB |
Output is correct |
22 |
Correct |
2 ms |
1152 KB |
Output is correct |
23 |
Correct |
1 ms |
896 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
1152 KB |
Output is correct |
26 |
Correct |
1 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
640 KB |
Output is correct |
30 |
Correct |
1 ms |
640 KB |
Output is correct |
31 |
Correct |
7 ms |
3456 KB |
Output is correct |
32 |
Correct |
8 ms |
4384 KB |
Output is correct |
33 |
Correct |
9 ms |
5248 KB |
Output is correct |
34 |
Correct |
9 ms |
4992 KB |
Output is correct |
35 |
Correct |
11 ms |
6144 KB |
Output is correct |
36 |
Correct |
9 ms |
6144 KB |
Output is correct |
37 |
Correct |
11 ms |
5120 KB |
Output is correct |
38 |
Correct |
6 ms |
4224 KB |
Output is correct |
39 |
Correct |
5 ms |
1152 KB |
Output is correct |
40 |
Correct |
11 ms |
5632 KB |
Output is correct |
41 |
Correct |
5 ms |
1184 KB |
Output is correct |
42 |
Correct |
6 ms |
1920 KB |
Output is correct |
43 |
Correct |
5 ms |
1024 KB |
Output is correct |
44 |
Correct |
6 ms |
2688 KB |
Output is correct |
45 |
Correct |
7 ms |
2688 KB |
Output is correct |
46 |
Correct |
165 ms |
70392 KB |
Output is correct |
47 |
Correct |
212 ms |
80596 KB |
Output is correct |
48 |
Correct |
285 ms |
163356 KB |
Output is correct |
49 |
Correct |
309 ms |
175776 KB |
Output is correct |
50 |
Correct |
337 ms |
194572 KB |
Output is correct |
51 |
Correct |
303 ms |
191272 KB |
Output is correct |
52 |
Correct |
151 ms |
95784 KB |
Output is correct |
53 |
Correct |
92 ms |
57592 KB |
Output is correct |
54 |
Correct |
160 ms |
25080 KB |
Output is correct |
55 |
Correct |
317 ms |
184184 KB |
Output is correct |
56 |
Correct |
214 ms |
84344 KB |
Output is correct |
57 |
Correct |
196 ms |
69368 KB |
Output is correct |
58 |
Correct |
216 ms |
76736 KB |
Output is correct |
59 |
Correct |
247 ms |
109688 KB |
Output is correct |
60 |
Correct |
239 ms |
109048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
896 KB |
Output is correct |
17 |
Correct |
2 ms |
1024 KB |
Output is correct |
18 |
Correct |
2 ms |
1280 KB |
Output is correct |
19 |
Correct |
2 ms |
1152 KB |
Output is correct |
20 |
Correct |
2 ms |
1280 KB |
Output is correct |
21 |
Correct |
2 ms |
1280 KB |
Output is correct |
22 |
Correct |
2 ms |
1152 KB |
Output is correct |
23 |
Correct |
1 ms |
896 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
1152 KB |
Output is correct |
26 |
Correct |
1 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
640 KB |
Output is correct |
30 |
Correct |
1 ms |
640 KB |
Output is correct |
31 |
Correct |
7 ms |
3456 KB |
Output is correct |
32 |
Correct |
8 ms |
4384 KB |
Output is correct |
33 |
Correct |
9 ms |
5248 KB |
Output is correct |
34 |
Correct |
9 ms |
4992 KB |
Output is correct |
35 |
Correct |
11 ms |
6144 KB |
Output is correct |
36 |
Correct |
9 ms |
6144 KB |
Output is correct |
37 |
Correct |
11 ms |
5120 KB |
Output is correct |
38 |
Correct |
6 ms |
4224 KB |
Output is correct |
39 |
Correct |
5 ms |
1152 KB |
Output is correct |
40 |
Correct |
11 ms |
5632 KB |
Output is correct |
41 |
Correct |
5 ms |
1184 KB |
Output is correct |
42 |
Correct |
6 ms |
1920 KB |
Output is correct |
43 |
Correct |
5 ms |
1024 KB |
Output is correct |
44 |
Correct |
6 ms |
2688 KB |
Output is correct |
45 |
Correct |
7 ms |
2688 KB |
Output is correct |
46 |
Correct |
165 ms |
70392 KB |
Output is correct |
47 |
Correct |
212 ms |
80596 KB |
Output is correct |
48 |
Correct |
285 ms |
163356 KB |
Output is correct |
49 |
Correct |
309 ms |
175776 KB |
Output is correct |
50 |
Correct |
337 ms |
194572 KB |
Output is correct |
51 |
Correct |
303 ms |
191272 KB |
Output is correct |
52 |
Correct |
151 ms |
95784 KB |
Output is correct |
53 |
Correct |
92 ms |
57592 KB |
Output is correct |
54 |
Correct |
160 ms |
25080 KB |
Output is correct |
55 |
Correct |
317 ms |
184184 KB |
Output is correct |
56 |
Correct |
214 ms |
84344 KB |
Output is correct |
57 |
Correct |
196 ms |
69368 KB |
Output is correct |
58 |
Correct |
216 ms |
76736 KB |
Output is correct |
59 |
Correct |
247 ms |
109688 KB |
Output is correct |
60 |
Correct |
239 ms |
109048 KB |
Output is correct |
61 |
Runtime error |
707 ms |
262148 KB |
Execution killed with signal 9 |
62 |
Halted |
0 ms |
0 KB |
- |