Submission #255598

# Submission time Handle Problem Language Result Execution time Memory
255598 2020-08-01T11:59:49 Z karma Bigger segments (IZhO19_segments) C++14
100 / 100
129 ms 46296 KB
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
//#define int         int64_t

using namespace std;

const int N = int(5e5) + 7;
const int inf = 2e9 + 1;
typedef pair<ll, ll> pii;

ll s[N], ff;
int f[N], n;

struct TVector {
    vector<pii> f;
    void push(pii cur) {
        while(f.size() && f.back().fi >= cur.fi) f.pop_back();
        if(f.empty() || f.back().se < cur.se) f.pb(cur);
    }
    pii get(pii cur) {
        return *prev(lower_bound(f.begin(), f.end(), cur));
    }
} g, q[N];

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> s[i];
        s[i] += s[i - 1];
    }
    g.push(pii(0, 0)); q[0].push(pii(0, 0));
    for(int i = 1; i <= n; ++i) {
        f[i] = g.get(pii(s[i] + 1, 0)).se + 1;
        ff = -q[f[i] - 1].get(pii(s[i] + 1, 0)).se + s[i];
        g.push(pii(ff + s[i], f[i]));
        q[f[i]].push(pii(ff + s[i], s[i]));
        //cout << f[i] << ' ' << ff << '\n';
    }
    cout << f[n];
}

Compilation message

segments.cpp: In function 'int32_t main()':
segments.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen(Task".out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12032 KB Output is correct
2 Correct 7 ms 12032 KB Output is correct
3 Correct 9 ms 12032 KB Output is correct
4 Correct 7 ms 12032 KB Output is correct
5 Correct 8 ms 12032 KB Output is correct
6 Correct 7 ms 12032 KB Output is correct
7 Correct 7 ms 12032 KB Output is correct
8 Correct 7 ms 12032 KB Output is correct
9 Correct 6 ms 12032 KB Output is correct
10 Correct 8 ms 12032 KB Output is correct
11 Correct 7 ms 12032 KB Output is correct
12 Correct 7 ms 12032 KB Output is correct
13 Correct 7 ms 12032 KB Output is correct
14 Correct 7 ms 12032 KB Output is correct
15 Correct 6 ms 12032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12032 KB Output is correct
2 Correct 7 ms 12032 KB Output is correct
3 Correct 9 ms 12032 KB Output is correct
4 Correct 7 ms 12032 KB Output is correct
5 Correct 8 ms 12032 KB Output is correct
6 Correct 7 ms 12032 KB Output is correct
7 Correct 7 ms 12032 KB Output is correct
8 Correct 7 ms 12032 KB Output is correct
9 Correct 6 ms 12032 KB Output is correct
10 Correct 8 ms 12032 KB Output is correct
11 Correct 7 ms 12032 KB Output is correct
12 Correct 7 ms 12032 KB Output is correct
13 Correct 7 ms 12032 KB Output is correct
14 Correct 7 ms 12032 KB Output is correct
15 Correct 6 ms 12032 KB Output is correct
16 Correct 17 ms 12160 KB Output is correct
17 Correct 8 ms 12160 KB Output is correct
18 Correct 9 ms 12160 KB Output is correct
19 Correct 8 ms 12160 KB Output is correct
20 Correct 8 ms 12160 KB Output is correct
21 Correct 9 ms 12160 KB Output is correct
22 Correct 13 ms 12160 KB Output is correct
23 Correct 9 ms 12160 KB Output is correct
24 Correct 8 ms 12160 KB Output is correct
25 Correct 10 ms 12160 KB Output is correct
26 Correct 9 ms 12160 KB Output is correct
27 Correct 10 ms 12160 KB Output is correct
28 Correct 8 ms 12160 KB Output is correct
29 Correct 8 ms 12160 KB Output is correct
30 Correct 9 ms 12160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12032 KB Output is correct
2 Correct 7 ms 12032 KB Output is correct
3 Correct 9 ms 12032 KB Output is correct
4 Correct 7 ms 12032 KB Output is correct
5 Correct 8 ms 12032 KB Output is correct
6 Correct 7 ms 12032 KB Output is correct
7 Correct 7 ms 12032 KB Output is correct
8 Correct 7 ms 12032 KB Output is correct
9 Correct 6 ms 12032 KB Output is correct
10 Correct 8 ms 12032 KB Output is correct
11 Correct 7 ms 12032 KB Output is correct
12 Correct 7 ms 12032 KB Output is correct
13 Correct 7 ms 12032 KB Output is correct
14 Correct 7 ms 12032 KB Output is correct
15 Correct 6 ms 12032 KB Output is correct
16 Correct 17 ms 12160 KB Output is correct
17 Correct 8 ms 12160 KB Output is correct
18 Correct 9 ms 12160 KB Output is correct
19 Correct 8 ms 12160 KB Output is correct
20 Correct 8 ms 12160 KB Output is correct
21 Correct 9 ms 12160 KB Output is correct
22 Correct 13 ms 12160 KB Output is correct
23 Correct 9 ms 12160 KB Output is correct
24 Correct 8 ms 12160 KB Output is correct
25 Correct 10 ms 12160 KB Output is correct
26 Correct 9 ms 12160 KB Output is correct
27 Correct 10 ms 12160 KB Output is correct
28 Correct 8 ms 12160 KB Output is correct
29 Correct 8 ms 12160 KB Output is correct
30 Correct 9 ms 12160 KB Output is correct
31 Correct 8 ms 12288 KB Output is correct
32 Correct 8 ms 12160 KB Output is correct
33 Correct 9 ms 12160 KB Output is correct
34 Correct 9 ms 12288 KB Output is correct
35 Correct 9 ms 12288 KB Output is correct
36 Correct 8 ms 12160 KB Output is correct
37 Correct 9 ms 12160 KB Output is correct
38 Correct 9 ms 12160 KB Output is correct
39 Correct 8 ms 12160 KB Output is correct
40 Correct 11 ms 12160 KB Output is correct
41 Correct 9 ms 12288 KB Output is correct
42 Correct 11 ms 12288 KB Output is correct
43 Correct 8 ms 12160 KB Output is correct
44 Correct 9 ms 12288 KB Output is correct
45 Correct 9 ms 12288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12032 KB Output is correct
2 Correct 7 ms 12032 KB Output is correct
3 Correct 9 ms 12032 KB Output is correct
4 Correct 7 ms 12032 KB Output is correct
5 Correct 8 ms 12032 KB Output is correct
6 Correct 7 ms 12032 KB Output is correct
7 Correct 7 ms 12032 KB Output is correct
8 Correct 7 ms 12032 KB Output is correct
9 Correct 6 ms 12032 KB Output is correct
10 Correct 8 ms 12032 KB Output is correct
11 Correct 7 ms 12032 KB Output is correct
12 Correct 7 ms 12032 KB Output is correct
13 Correct 7 ms 12032 KB Output is correct
14 Correct 7 ms 12032 KB Output is correct
15 Correct 6 ms 12032 KB Output is correct
16 Correct 17 ms 12160 KB Output is correct
17 Correct 8 ms 12160 KB Output is correct
18 Correct 9 ms 12160 KB Output is correct
19 Correct 8 ms 12160 KB Output is correct
20 Correct 8 ms 12160 KB Output is correct
21 Correct 9 ms 12160 KB Output is correct
22 Correct 13 ms 12160 KB Output is correct
23 Correct 9 ms 12160 KB Output is correct
24 Correct 8 ms 12160 KB Output is correct
25 Correct 10 ms 12160 KB Output is correct
26 Correct 9 ms 12160 KB Output is correct
27 Correct 10 ms 12160 KB Output is correct
28 Correct 8 ms 12160 KB Output is correct
29 Correct 8 ms 12160 KB Output is correct
30 Correct 9 ms 12160 KB Output is correct
31 Correct 8 ms 12288 KB Output is correct
32 Correct 8 ms 12160 KB Output is correct
33 Correct 9 ms 12160 KB Output is correct
34 Correct 9 ms 12288 KB Output is correct
35 Correct 9 ms 12288 KB Output is correct
36 Correct 8 ms 12160 KB Output is correct
37 Correct 9 ms 12160 KB Output is correct
38 Correct 9 ms 12160 KB Output is correct
39 Correct 8 ms 12160 KB Output is correct
40 Correct 11 ms 12160 KB Output is correct
41 Correct 9 ms 12288 KB Output is correct
42 Correct 11 ms 12288 KB Output is correct
43 Correct 8 ms 12160 KB Output is correct
44 Correct 9 ms 12288 KB Output is correct
45 Correct 9 ms 12288 KB Output is correct
46 Correct 21 ms 15728 KB Output is correct
47 Correct 24 ms 15360 KB Output is correct
48 Correct 29 ms 16504 KB Output is correct
49 Correct 30 ms 17388 KB Output is correct
50 Correct 44 ms 18920 KB Output is correct
51 Correct 30 ms 15992 KB Output is correct
52 Correct 20 ms 14080 KB Output is correct
53 Correct 16 ms 13312 KB Output is correct
54 Correct 22 ms 15232 KB Output is correct
55 Correct 30 ms 16248 KB Output is correct
56 Correct 33 ms 18416 KB Output is correct
57 Correct 23 ms 17524 KB Output is correct
58 Correct 27 ms 18420 KB Output is correct
59 Correct 29 ms 18536 KB Output is correct
60 Correct 30 ms 16876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12032 KB Output is correct
2 Correct 7 ms 12032 KB Output is correct
3 Correct 9 ms 12032 KB Output is correct
4 Correct 7 ms 12032 KB Output is correct
5 Correct 8 ms 12032 KB Output is correct
6 Correct 7 ms 12032 KB Output is correct
7 Correct 7 ms 12032 KB Output is correct
8 Correct 7 ms 12032 KB Output is correct
9 Correct 6 ms 12032 KB Output is correct
10 Correct 8 ms 12032 KB Output is correct
11 Correct 7 ms 12032 KB Output is correct
12 Correct 7 ms 12032 KB Output is correct
13 Correct 7 ms 12032 KB Output is correct
14 Correct 7 ms 12032 KB Output is correct
15 Correct 6 ms 12032 KB Output is correct
16 Correct 17 ms 12160 KB Output is correct
17 Correct 8 ms 12160 KB Output is correct
18 Correct 9 ms 12160 KB Output is correct
19 Correct 8 ms 12160 KB Output is correct
20 Correct 8 ms 12160 KB Output is correct
21 Correct 9 ms 12160 KB Output is correct
22 Correct 13 ms 12160 KB Output is correct
23 Correct 9 ms 12160 KB Output is correct
24 Correct 8 ms 12160 KB Output is correct
25 Correct 10 ms 12160 KB Output is correct
26 Correct 9 ms 12160 KB Output is correct
27 Correct 10 ms 12160 KB Output is correct
28 Correct 8 ms 12160 KB Output is correct
29 Correct 8 ms 12160 KB Output is correct
30 Correct 9 ms 12160 KB Output is correct
31 Correct 8 ms 12288 KB Output is correct
32 Correct 8 ms 12160 KB Output is correct
33 Correct 9 ms 12160 KB Output is correct
34 Correct 9 ms 12288 KB Output is correct
35 Correct 9 ms 12288 KB Output is correct
36 Correct 8 ms 12160 KB Output is correct
37 Correct 9 ms 12160 KB Output is correct
38 Correct 9 ms 12160 KB Output is correct
39 Correct 8 ms 12160 KB Output is correct
40 Correct 11 ms 12160 KB Output is correct
41 Correct 9 ms 12288 KB Output is correct
42 Correct 11 ms 12288 KB Output is correct
43 Correct 8 ms 12160 KB Output is correct
44 Correct 9 ms 12288 KB Output is correct
45 Correct 9 ms 12288 KB Output is correct
46 Correct 21 ms 15728 KB Output is correct
47 Correct 24 ms 15360 KB Output is correct
48 Correct 29 ms 16504 KB Output is correct
49 Correct 30 ms 17388 KB Output is correct
50 Correct 44 ms 18920 KB Output is correct
51 Correct 30 ms 15992 KB Output is correct
52 Correct 20 ms 14080 KB Output is correct
53 Correct 16 ms 13312 KB Output is correct
54 Correct 22 ms 15232 KB Output is correct
55 Correct 30 ms 16248 KB Output is correct
56 Correct 33 ms 18416 KB Output is correct
57 Correct 23 ms 17524 KB Output is correct
58 Correct 27 ms 18420 KB Output is correct
59 Correct 29 ms 18536 KB Output is correct
60 Correct 30 ms 16876 KB Output is correct
61 Correct 68 ms 27876 KB Output is correct
62 Correct 80 ms 29668 KB Output is correct
63 Correct 90 ms 27240 KB Output is correct
64 Correct 119 ms 38116 KB Output is correct
65 Correct 129 ms 46296 KB Output is correct
66 Correct 115 ms 31352 KB Output is correct
67 Correct 99 ms 27640 KB Output is correct
68 Correct 50 ms 20220 KB Output is correct
69 Correct 78 ms 27088 KB Output is correct
70 Correct 124 ms 32888 KB Output is correct
71 Correct 100 ms 43352 KB Output is correct
72 Correct 102 ms 39772 KB Output is correct
73 Correct 113 ms 42072 KB Output is correct
74 Correct 120 ms 44760 KB Output is correct
75 Correct 114 ms 42328 KB Output is correct