답안 #162907

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
162907 2019-11-10T08:58:39 Z abacaba Bigger segments (IZhO19_segments) C++14
100 / 100
703 ms 60136 KB
#include <iostream>
#include <string>
#include <unordered_map>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
 
#define pii pair<long long, long long>
#define mp make_pair
#define f first
#define se second
#define max3(a, b, c) max(a, max(b, c))
#define int long long
 
const int inf = 2e9;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
struct node {
    node *l, *r;
    int key, pr;
    pii val, mx;
    node(int _key, pii _val) {
        pr = uniform_int_distribution<>(0, inf)(rng);
        l = r = NULL;
        key = _key, mx = val = _val;
    }
};
 
typedef node* pnode;
 
inline pii val(pnode t) {
    return t ? t->mx : mp(0LL, 0LL);
}
 
inline void upd(pnode &t) {
    if(t)
        t->mx = max3(t->val, val(t->l), val(t->r));
}
 
void split(pnode t, pnode &l, pnode &r, int key) {
    if(!t)
        return void(l = r = t);
    if(t->key <= key)
        split(t->r, t->r, r, key), l = t;
    else
        split(t->l, l, t->l, key), r = t;
    upd(l);
    upd(r);
}
 
void merge(pnode &t, pnode l, pnode r) {
    if(!l || !r)
        t = l ? l : r;
    else if(l->pr > r->pr)
        merge(l->r, l->r, r), t = l;
    else
        merge(r->l, l, r->l), t = r;
    upd(t);
}
 
pnode root = NULL;
 
const int mod = 1e9 + 7;
const int N = 5e5 + 15;
int n, a[N], p[N];
pii dp[N];

inline void insert(pnode &t, pnode nw) {
    pnode t1, t2, t3, t4;
    split(root, t1, t2, nw->key - 1);
    split(t2, t3, t4, nw->key);
    if(t3)
        t3->val = max(t3->val, nw->val);
    else
        t3 = nw;
    merge(t2, t3, t4);
    merge(root, t1, t2);
}

main() {
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        p[i] = p[i-1] + a[i];
    }
    root = new node(0, mp(1, 0));
    for(int i = 1; i <= n; ++i) {
        pnode t1, t2;
        split(root, t1, t2, p[i]);
        dp[i] = val(t1);
        merge(root, t1, t2);
        insert(root, new node(2 * p[i] - p[dp[i].se], mp(dp[i].f + 1, i)));
    }
    cout << dp[n].f << endl;
    return 0;
}

Compilation message

segments.cpp:95:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 380 KB Output is correct
31 Correct 4 ms 632 KB Output is correct
32 Correct 5 ms 760 KB Output is correct
33 Correct 5 ms 760 KB Output is correct
34 Correct 4 ms 760 KB Output is correct
35 Correct 4 ms 720 KB Output is correct
36 Correct 5 ms 764 KB Output is correct
37 Correct 4 ms 632 KB Output is correct
38 Correct 4 ms 632 KB Output is correct
39 Correct 5 ms 732 KB Output is correct
40 Correct 5 ms 760 KB Output is correct
41 Correct 4 ms 760 KB Output is correct
42 Correct 4 ms 632 KB Output is correct
43 Correct 5 ms 632 KB Output is correct
44 Correct 4 ms 760 KB Output is correct
45 Correct 4 ms 728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 380 KB Output is correct
31 Correct 4 ms 632 KB Output is correct
32 Correct 5 ms 760 KB Output is correct
33 Correct 5 ms 760 KB Output is correct
34 Correct 4 ms 760 KB Output is correct
35 Correct 4 ms 720 KB Output is correct
36 Correct 5 ms 764 KB Output is correct
37 Correct 4 ms 632 KB Output is correct
38 Correct 4 ms 632 KB Output is correct
39 Correct 5 ms 732 KB Output is correct
40 Correct 5 ms 760 KB Output is correct
41 Correct 4 ms 760 KB Output is correct
42 Correct 4 ms 632 KB Output is correct
43 Correct 5 ms 632 KB Output is correct
44 Correct 4 ms 760 KB Output is correct
45 Correct 4 ms 728 KB Output is correct
46 Correct 66 ms 11784 KB Output is correct
47 Correct 123 ms 11768 KB Output is correct
48 Correct 106 ms 12252 KB Output is correct
49 Correct 88 ms 12280 KB Output is correct
50 Correct 65 ms 12280 KB Output is correct
51 Correct 119 ms 12324 KB Output is correct
52 Correct 55 ms 6392 KB Output is correct
53 Correct 33 ms 3960 KB Output is correct
54 Correct 108 ms 11516 KB Output is correct
55 Correct 115 ms 12280 KB Output is correct
56 Correct 59 ms 11768 KB Output is correct
57 Correct 71 ms 11768 KB Output is correct
58 Correct 87 ms 11936 KB Output is correct
59 Correct 59 ms 11976 KB Output is correct
60 Correct 88 ms 11928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 380 KB Output is correct
31 Correct 4 ms 632 KB Output is correct
32 Correct 5 ms 760 KB Output is correct
33 Correct 5 ms 760 KB Output is correct
34 Correct 4 ms 760 KB Output is correct
35 Correct 4 ms 720 KB Output is correct
36 Correct 5 ms 764 KB Output is correct
37 Correct 4 ms 632 KB Output is correct
38 Correct 4 ms 632 KB Output is correct
39 Correct 5 ms 732 KB Output is correct
40 Correct 5 ms 760 KB Output is correct
41 Correct 4 ms 760 KB Output is correct
42 Correct 4 ms 632 KB Output is correct
43 Correct 5 ms 632 KB Output is correct
44 Correct 4 ms 760 KB Output is correct
45 Correct 4 ms 728 KB Output is correct
46 Correct 66 ms 11784 KB Output is correct
47 Correct 123 ms 11768 KB Output is correct
48 Correct 106 ms 12252 KB Output is correct
49 Correct 88 ms 12280 KB Output is correct
50 Correct 65 ms 12280 KB Output is correct
51 Correct 119 ms 12324 KB Output is correct
52 Correct 55 ms 6392 KB Output is correct
53 Correct 33 ms 3960 KB Output is correct
54 Correct 108 ms 11516 KB Output is correct
55 Correct 115 ms 12280 KB Output is correct
56 Correct 59 ms 11768 KB Output is correct
57 Correct 71 ms 11768 KB Output is correct
58 Correct 87 ms 11936 KB Output is correct
59 Correct 59 ms 11976 KB Output is correct
60 Correct 88 ms 11928 KB Output is correct
61 Correct 393 ms 57188 KB Output is correct
62 Correct 497 ms 57196 KB Output is correct
63 Correct 703 ms 57780 KB Output is correct
64 Correct 579 ms 59692 KB Output is correct
65 Correct 333 ms 60136 KB Output is correct
66 Correct 584 ms 59996 KB Output is correct
67 Correct 491 ms 48120 KB Output is correct
68 Correct 225 ms 24196 KB Output is correct
69 Correct 609 ms 56384 KB Output is correct
70 Correct 609 ms 60024 KB Output is correct
71 Correct 306 ms 57224 KB Output is correct
72 Correct 373 ms 57536 KB Output is correct
73 Correct 333 ms 58104 KB Output is correct
74 Correct 327 ms 58448 KB Output is correct
75 Correct 397 ms 58488 KB Output is correct