Submission #268616

# Submission time Handle Problem Language Result Execution time Memory
268616 2020-08-16T14:19:38 Z Osama_Alkhodairy Bigger segments (IZhO19_segments) C++17
100 / 100
590 ms 37116 KB
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 500001;
const ll INF = 1e18;

int n;
vector <int> a;
ll sum[N], dp[N], tree[4 * N], lazy[4 * N];

void push(int l, int r, int node){
    tree[node] += lazy[node];
    if(l != r){
        lazy[2 * node] += lazy[node];
        lazy[2 * node + 1] += lazy[node];
    }
    lazy[node] = 0;
}
void update(int l, int r, int node, int s, int e, ll v){
    if(r < l) return;
    push(l, r, node);
    if(r < s || l > e) return;
    if(s <= l && r <= e){
        lazy[node] += v;
        push(l, r, node);
        return;
    }
    int mid = (l + r) / 2;
    update(l, mid, 2 * node, s, e, v);
    update(mid + 1, r, 2 * node + 1, s, e, v);
    tree[node] = min(tree[2 * node], tree[2 * node + 1]);
}
int query(int l, int r, int node, int p){
    if(r < l || l > p) return -1;
    push(l, r, node);
    if(r <= p && tree[node] > 0) return -1;
    if(l == r) return l;
    int mid = (l + r) / 2;
    int ret = query(mid + 1, r, 2 * node + 1, p);
    if(ret != -1) return ret;
    return query(l, mid, 2 * node, p);
}
ll get_sum(int l, int r){
    return sum[r] - sum[l - 1];
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    for(int i = 0 ; i < 4 * N ; i++){
        tree[i] = INF;
    }
    cin >> n;
    a.resize(n + 1);
    for(int i = 1 ; i <= n ; i++){
        cin >> a[i];
    }
    for(int i = 1 ; i <= n ; i++){
        sum[i] = sum[i - 1] + a[i];
    }
    update(0, n, 1, 0, 0, -INF);
    vector <int> ans(n + 1);
    for(int i = 1 ; i <= n ; i++){
        update(0, n, 1, 0, i - 1, -a[i]);
        int idx = query(0, n, 1, i - 1);
        ans[i] = ans[idx] + 1;
        update(0, n, 1, i, i, -INF + get_sum(idx + 1, i));
    }
    cout << ans[n] << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16000 KB Output is correct
2 Correct 9 ms 16000 KB Output is correct
3 Correct 9 ms 16000 KB Output is correct
4 Correct 8 ms 16000 KB Output is correct
5 Correct 10 ms 16000 KB Output is correct
6 Correct 11 ms 16000 KB Output is correct
7 Correct 9 ms 15976 KB Output is correct
8 Correct 9 ms 16000 KB Output is correct
9 Correct 9 ms 16000 KB Output is correct
10 Correct 9 ms 16000 KB Output is correct
11 Correct 9 ms 16000 KB Output is correct
12 Correct 9 ms 16000 KB Output is correct
13 Correct 9 ms 16000 KB Output is correct
14 Correct 10 ms 16000 KB Output is correct
15 Correct 9 ms 16028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16000 KB Output is correct
2 Correct 9 ms 16000 KB Output is correct
3 Correct 9 ms 16000 KB Output is correct
4 Correct 8 ms 16000 KB Output is correct
5 Correct 10 ms 16000 KB Output is correct
6 Correct 11 ms 16000 KB Output is correct
7 Correct 9 ms 15976 KB Output is correct
8 Correct 9 ms 16000 KB Output is correct
9 Correct 9 ms 16000 KB Output is correct
10 Correct 9 ms 16000 KB Output is correct
11 Correct 9 ms 16000 KB Output is correct
12 Correct 9 ms 16000 KB Output is correct
13 Correct 9 ms 16000 KB Output is correct
14 Correct 10 ms 16000 KB Output is correct
15 Correct 9 ms 16028 KB Output is correct
16 Correct 10 ms 16128 KB Output is correct
17 Correct 9 ms 16000 KB Output is correct
18 Correct 9 ms 16000 KB Output is correct
19 Correct 9 ms 16000 KB Output is correct
20 Correct 11 ms 16000 KB Output is correct
21 Correct 9 ms 16000 KB Output is correct
22 Correct 9 ms 16000 KB Output is correct
23 Correct 9 ms 16000 KB Output is correct
24 Correct 10 ms 16000 KB Output is correct
25 Correct 9 ms 16000 KB Output is correct
26 Correct 11 ms 16000 KB Output is correct
27 Correct 11 ms 16000 KB Output is correct
28 Correct 9 ms 16000 KB Output is correct
29 Correct 11 ms 16000 KB Output is correct
30 Correct 10 ms 16000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16000 KB Output is correct
2 Correct 9 ms 16000 KB Output is correct
3 Correct 9 ms 16000 KB Output is correct
4 Correct 8 ms 16000 KB Output is correct
5 Correct 10 ms 16000 KB Output is correct
6 Correct 11 ms 16000 KB Output is correct
7 Correct 9 ms 15976 KB Output is correct
8 Correct 9 ms 16000 KB Output is correct
9 Correct 9 ms 16000 KB Output is correct
10 Correct 9 ms 16000 KB Output is correct
11 Correct 9 ms 16000 KB Output is correct
12 Correct 9 ms 16000 KB Output is correct
13 Correct 9 ms 16000 KB Output is correct
14 Correct 10 ms 16000 KB Output is correct
15 Correct 9 ms 16028 KB Output is correct
16 Correct 10 ms 16128 KB Output is correct
17 Correct 9 ms 16000 KB Output is correct
18 Correct 9 ms 16000 KB Output is correct
19 Correct 9 ms 16000 KB Output is correct
20 Correct 11 ms 16000 KB Output is correct
21 Correct 9 ms 16000 KB Output is correct
22 Correct 9 ms 16000 KB Output is correct
23 Correct 9 ms 16000 KB Output is correct
24 Correct 10 ms 16000 KB Output is correct
25 Correct 9 ms 16000 KB Output is correct
26 Correct 11 ms 16000 KB Output is correct
27 Correct 11 ms 16000 KB Output is correct
28 Correct 9 ms 16000 KB Output is correct
29 Correct 11 ms 16000 KB Output is correct
30 Correct 10 ms 16000 KB Output is correct
31 Correct 12 ms 16160 KB Output is correct
32 Correct 12 ms 16128 KB Output is correct
33 Correct 12 ms 16128 KB Output is correct
34 Correct 11 ms 16128 KB Output is correct
35 Correct 11 ms 16128 KB Output is correct
36 Correct 12 ms 16160 KB Output is correct
37 Correct 12 ms 16256 KB Output is correct
38 Correct 12 ms 16128 KB Output is correct
39 Correct 12 ms 16128 KB Output is correct
40 Correct 15 ms 16128 KB Output is correct
41 Correct 11 ms 16128 KB Output is correct
42 Correct 12 ms 16128 KB Output is correct
43 Correct 11 ms 16128 KB Output is correct
44 Correct 12 ms 16128 KB Output is correct
45 Correct 11 ms 16128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16000 KB Output is correct
2 Correct 9 ms 16000 KB Output is correct
3 Correct 9 ms 16000 KB Output is correct
4 Correct 8 ms 16000 KB Output is correct
5 Correct 10 ms 16000 KB Output is correct
6 Correct 11 ms 16000 KB Output is correct
7 Correct 9 ms 15976 KB Output is correct
8 Correct 9 ms 16000 KB Output is correct
9 Correct 9 ms 16000 KB Output is correct
10 Correct 9 ms 16000 KB Output is correct
11 Correct 9 ms 16000 KB Output is correct
12 Correct 9 ms 16000 KB Output is correct
13 Correct 9 ms 16000 KB Output is correct
14 Correct 10 ms 16000 KB Output is correct
15 Correct 9 ms 16028 KB Output is correct
16 Correct 10 ms 16128 KB Output is correct
17 Correct 9 ms 16000 KB Output is correct
18 Correct 9 ms 16000 KB Output is correct
19 Correct 9 ms 16000 KB Output is correct
20 Correct 11 ms 16000 KB Output is correct
21 Correct 9 ms 16000 KB Output is correct
22 Correct 9 ms 16000 KB Output is correct
23 Correct 9 ms 16000 KB Output is correct
24 Correct 10 ms 16000 KB Output is correct
25 Correct 9 ms 16000 KB Output is correct
26 Correct 11 ms 16000 KB Output is correct
27 Correct 11 ms 16000 KB Output is correct
28 Correct 9 ms 16000 KB Output is correct
29 Correct 11 ms 16000 KB Output is correct
30 Correct 10 ms 16000 KB Output is correct
31 Correct 12 ms 16160 KB Output is correct
32 Correct 12 ms 16128 KB Output is correct
33 Correct 12 ms 16128 KB Output is correct
34 Correct 11 ms 16128 KB Output is correct
35 Correct 11 ms 16128 KB Output is correct
36 Correct 12 ms 16160 KB Output is correct
37 Correct 12 ms 16256 KB Output is correct
38 Correct 12 ms 16128 KB Output is correct
39 Correct 12 ms 16128 KB Output is correct
40 Correct 15 ms 16128 KB Output is correct
41 Correct 11 ms 16128 KB Output is correct
42 Correct 12 ms 16128 KB Output is correct
43 Correct 11 ms 16128 KB Output is correct
44 Correct 12 ms 16128 KB Output is correct
45 Correct 11 ms 16128 KB Output is correct
46 Correct 112 ms 19576 KB Output is correct
47 Correct 109 ms 20216 KB Output is correct
48 Correct 112 ms 20600 KB Output is correct
49 Correct 107 ms 20688 KB Output is correct
50 Correct 101 ms 20600 KB Output is correct
51 Correct 110 ms 20600 KB Output is correct
52 Correct 56 ms 18296 KB Output is correct
53 Correct 36 ms 17272 KB Output is correct
54 Correct 102 ms 19788 KB Output is correct
55 Correct 109 ms 20600 KB Output is correct
56 Correct 96 ms 20216 KB Output is correct
57 Correct 103 ms 20088 KB Output is correct
58 Correct 99 ms 20088 KB Output is correct
59 Correct 95 ms 20216 KB Output is correct
60 Correct 102 ms 20160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16000 KB Output is correct
2 Correct 9 ms 16000 KB Output is correct
3 Correct 9 ms 16000 KB Output is correct
4 Correct 8 ms 16000 KB Output is correct
5 Correct 10 ms 16000 KB Output is correct
6 Correct 11 ms 16000 KB Output is correct
7 Correct 9 ms 15976 KB Output is correct
8 Correct 9 ms 16000 KB Output is correct
9 Correct 9 ms 16000 KB Output is correct
10 Correct 9 ms 16000 KB Output is correct
11 Correct 9 ms 16000 KB Output is correct
12 Correct 9 ms 16000 KB Output is correct
13 Correct 9 ms 16000 KB Output is correct
14 Correct 10 ms 16000 KB Output is correct
15 Correct 9 ms 16028 KB Output is correct
16 Correct 10 ms 16128 KB Output is correct
17 Correct 9 ms 16000 KB Output is correct
18 Correct 9 ms 16000 KB Output is correct
19 Correct 9 ms 16000 KB Output is correct
20 Correct 11 ms 16000 KB Output is correct
21 Correct 9 ms 16000 KB Output is correct
22 Correct 9 ms 16000 KB Output is correct
23 Correct 9 ms 16000 KB Output is correct
24 Correct 10 ms 16000 KB Output is correct
25 Correct 9 ms 16000 KB Output is correct
26 Correct 11 ms 16000 KB Output is correct
27 Correct 11 ms 16000 KB Output is correct
28 Correct 9 ms 16000 KB Output is correct
29 Correct 11 ms 16000 KB Output is correct
30 Correct 10 ms 16000 KB Output is correct
31 Correct 12 ms 16160 KB Output is correct
32 Correct 12 ms 16128 KB Output is correct
33 Correct 12 ms 16128 KB Output is correct
34 Correct 11 ms 16128 KB Output is correct
35 Correct 11 ms 16128 KB Output is correct
36 Correct 12 ms 16160 KB Output is correct
37 Correct 12 ms 16256 KB Output is correct
38 Correct 12 ms 16128 KB Output is correct
39 Correct 12 ms 16128 KB Output is correct
40 Correct 15 ms 16128 KB Output is correct
41 Correct 11 ms 16128 KB Output is correct
42 Correct 12 ms 16128 KB Output is correct
43 Correct 11 ms 16128 KB Output is correct
44 Correct 12 ms 16128 KB Output is correct
45 Correct 11 ms 16128 KB Output is correct
46 Correct 112 ms 19576 KB Output is correct
47 Correct 109 ms 20216 KB Output is correct
48 Correct 112 ms 20600 KB Output is correct
49 Correct 107 ms 20688 KB Output is correct
50 Correct 101 ms 20600 KB Output is correct
51 Correct 110 ms 20600 KB Output is correct
52 Correct 56 ms 18296 KB Output is correct
53 Correct 36 ms 17272 KB Output is correct
54 Correct 102 ms 19788 KB Output is correct
55 Correct 109 ms 20600 KB Output is correct
56 Correct 96 ms 20216 KB Output is correct
57 Correct 103 ms 20088 KB Output is correct
58 Correct 99 ms 20088 KB Output is correct
59 Correct 95 ms 20216 KB Output is correct
60 Correct 102 ms 20160 KB Output is correct
61 Correct 590 ms 34064 KB Output is correct
62 Correct 581 ms 34020 KB Output is correct
63 Correct 584 ms 34376 KB Output is correct
64 Correct 529 ms 36600 KB Output is correct
65 Correct 508 ms 36948 KB Output is correct
66 Correct 572 ms 36856 KB Output is correct
67 Correct 453 ms 34428 KB Output is correct
68 Correct 217 ms 25208 KB Output is correct
69 Correct 540 ms 33088 KB Output is correct
70 Correct 567 ms 37116 KB Output is correct
71 Correct 489 ms 34120 KB Output is correct
72 Correct 527 ms 34436 KB Output is correct
73 Correct 505 ms 34936 KB Output is correct
74 Correct 498 ms 35576 KB Output is correct
75 Correct 504 ms 35448 KB Output is correct