Submission #685068

# Submission time Handle Problem Language Result Execution time Memory
685068 2023-01-23T08:37:40 Z stevancv Bigger segments (IZhO19_segments) C++14
100 / 100
786 ms 251596 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 5e5 + 2;
const int S = 40 * N;
const ll M = 1e15;
ll a[N];
pair<int, int> st[S];
int lc[S], rc[S], tsz;
void Set(int &node, ll l, ll r, ll p, int x, int y) {
    if (!node) node = ++tsz;
    if (l == r) {
        st[node] = {x, y};
        return;
    }
    ll mid = l + r >> 1;
    if (p <= mid) Set(lc[node], l, mid, p, x, y);
    else Set(rc[node], mid + 1, r, p, x, y);
    st[node] = max(st[lc[node]], st[rc[node]]);
}
pair<int, int> Get(int node, ll l, ll r, ll ql, ll qr) {
    if (r < ql || qr < l || node == 0) return st[0];
    if (ql <= l && r <= qr) return st[node];
    ll mid = l + r >> 1;
    return max(Get(lc[node], l, mid, ql, qr), Get(rc[node], mid + 1, r, ql, qr));
}
int prv[N], dp[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    st[0] = {0, -1};
    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    int root = 0;
    Set(root, 0, M, 0, 0, 0);
    for (int i = 1; i <= n; i++) {
        auto u = Get(root, 0, M, 0, a[i]);
        dp[i] = u.first + 1;
        prv[i] = u.second;
        Set(root, 0, M, 2 * a[i] - a[prv[i]], dp[i], i);
    }
    cout << dp[n] << en;
    return 0;
}

Compilation message

segments.cpp: In function 'void Set(int&, long long int, long long int, long long int, int, int)':
segments.cpp:21:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |     ll mid = l + r >> 1;
      |              ~~^~~
segments.cpp: In function 'std::pair<int, int> Get(int, long long int, long long int, long long int, long long int)':
segments.cpp:29:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |     ll mid = l + r >> 1;
      |              ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 524 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 524 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 3 ms 1108 KB Output is correct
32 Correct 5 ms 1364 KB Output is correct
33 Correct 4 ms 1620 KB Output is correct
34 Correct 4 ms 1492 KB Output is correct
35 Correct 5 ms 1760 KB Output is correct
36 Correct 4 ms 1748 KB Output is correct
37 Correct 3 ms 1540 KB Output is correct
38 Correct 3 ms 1236 KB Output is correct
39 Correct 4 ms 596 KB Output is correct
40 Correct 4 ms 1748 KB Output is correct
41 Correct 3 ms 596 KB Output is correct
42 Correct 4 ms 724 KB Output is correct
43 Correct 3 ms 468 KB Output is correct
44 Correct 3 ms 980 KB Output is correct
45 Correct 3 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 524 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 3 ms 1108 KB Output is correct
32 Correct 5 ms 1364 KB Output is correct
33 Correct 4 ms 1620 KB Output is correct
34 Correct 4 ms 1492 KB Output is correct
35 Correct 5 ms 1760 KB Output is correct
36 Correct 4 ms 1748 KB Output is correct
37 Correct 3 ms 1540 KB Output is correct
38 Correct 3 ms 1236 KB Output is correct
39 Correct 4 ms 596 KB Output is correct
40 Correct 4 ms 1748 KB Output is correct
41 Correct 3 ms 596 KB Output is correct
42 Correct 4 ms 724 KB Output is correct
43 Correct 3 ms 468 KB Output is correct
44 Correct 3 ms 980 KB Output is correct
45 Correct 3 ms 980 KB Output is correct
46 Correct 83 ms 19008 KB Output is correct
47 Correct 98 ms 21404 KB Output is correct
48 Correct 117 ms 42140 KB Output is correct
49 Correct 125 ms 45248 KB Output is correct
50 Correct 169 ms 49916 KB Output is correct
51 Correct 117 ms 49084 KB Output is correct
52 Correct 61 ms 24792 KB Output is correct
53 Correct 43 ms 14928 KB Output is correct
54 Correct 87 ms 7532 KB Output is correct
55 Correct 127 ms 47520 KB Output is correct
56 Correct 118 ms 22476 KB Output is correct
57 Correct 104 ms 18744 KB Output is correct
58 Correct 110 ms 20552 KB Output is correct
59 Correct 122 ms 28756 KB Output is correct
60 Correct 113 ms 28636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 524 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 3 ms 1108 KB Output is correct
32 Correct 5 ms 1364 KB Output is correct
33 Correct 4 ms 1620 KB Output is correct
34 Correct 4 ms 1492 KB Output is correct
35 Correct 5 ms 1760 KB Output is correct
36 Correct 4 ms 1748 KB Output is correct
37 Correct 3 ms 1540 KB Output is correct
38 Correct 3 ms 1236 KB Output is correct
39 Correct 4 ms 596 KB Output is correct
40 Correct 4 ms 1748 KB Output is correct
41 Correct 3 ms 596 KB Output is correct
42 Correct 4 ms 724 KB Output is correct
43 Correct 3 ms 468 KB Output is correct
44 Correct 3 ms 980 KB Output is correct
45 Correct 3 ms 980 KB Output is correct
46 Correct 83 ms 19008 KB Output is correct
47 Correct 98 ms 21404 KB Output is correct
48 Correct 117 ms 42140 KB Output is correct
49 Correct 125 ms 45248 KB Output is correct
50 Correct 169 ms 49916 KB Output is correct
51 Correct 117 ms 49084 KB Output is correct
52 Correct 61 ms 24792 KB Output is correct
53 Correct 43 ms 14928 KB Output is correct
54 Correct 87 ms 7532 KB Output is correct
55 Correct 127 ms 47520 KB Output is correct
56 Correct 118 ms 22476 KB Output is correct
57 Correct 104 ms 18744 KB Output is correct
58 Correct 110 ms 20552 KB Output is correct
59 Correct 122 ms 28756 KB Output is correct
60 Correct 113 ms 28636 KB Output is correct
61 Correct 408 ms 87540 KB Output is correct
62 Correct 440 ms 84476 KB Output is correct
63 Correct 484 ms 106468 KB Output is correct
64 Correct 668 ms 232620 KB Output is correct
65 Correct 786 ms 251596 KB Output is correct
66 Correct 576 ms 249196 KB Output is correct
67 Correct 443 ms 199628 KB Output is correct
68 Correct 240 ms 99896 KB Output is correct
69 Correct 435 ms 37848 KB Output is correct
70 Correct 673 ms 244048 KB Output is correct
71 Correct 520 ms 84008 KB Output is correct
72 Correct 594 ms 107876 KB Output is correct
73 Correct 608 ms 142604 KB Output is correct
74 Correct 706 ms 163872 KB Output is correct
75 Correct 623 ms 163944 KB Output is correct