답안 #166807

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
166807 2019-12-04T07:19:28 Z Yaroslaff Bigger segments (IZhO19_segments) C++14
100 / 100
675 ms 60020 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 4 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 4 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 2 ms 376 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 420 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 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 4 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 2 ms 376 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 420 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 4 ms 760 KB Output is correct
32 Correct 5 ms 636 KB Output is correct
33 Correct 5 ms 760 KB Output is correct
34 Correct 4 ms 788 KB Output is correct
35 Correct 4 ms 760 KB Output is correct
36 Correct 5 ms 700 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 680 KB Output is correct
40 Correct 5 ms 760 KB Output is correct
41 Correct 3 ms 632 KB Output is correct
42 Correct 4 ms 760 KB Output is correct
43 Correct 5 ms 760 KB Output is correct
44 Correct 3 ms 632 KB Output is correct
45 Correct 4 ms 632 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 4 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 2 ms 376 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 420 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 4 ms 760 KB Output is correct
32 Correct 5 ms 636 KB Output is correct
33 Correct 5 ms 760 KB Output is correct
34 Correct 4 ms 788 KB Output is correct
35 Correct 4 ms 760 KB Output is correct
36 Correct 5 ms 700 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 680 KB Output is correct
40 Correct 5 ms 760 KB Output is correct
41 Correct 3 ms 632 KB Output is correct
42 Correct 4 ms 760 KB Output is correct
43 Correct 5 ms 760 KB Output is correct
44 Correct 3 ms 632 KB Output is correct
45 Correct 4 ms 632 KB Output is correct
46 Correct 73 ms 11736 KB Output is correct
47 Correct 122 ms 11796 KB Output is correct
48 Correct 109 ms 12092 KB Output is correct
49 Correct 88 ms 12200 KB Output is correct
50 Correct 62 ms 12280 KB Output is correct
51 Correct 112 ms 12252 KB Output is correct
52 Correct 56 ms 6288 KB Output is correct
53 Correct 33 ms 3960 KB Output is correct
54 Correct 107 ms 11512 KB Output is correct
55 Correct 110 ms 12280 KB Output is correct
56 Correct 62 ms 11768 KB Output is correct
57 Correct 84 ms 11768 KB Output is correct
58 Correct 83 ms 11744 KB Output is correct
59 Correct 126 ms 11896 KB Output is correct
60 Correct 90 ms 11912 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 4 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 2 ms 376 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 420 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 4 ms 760 KB Output is correct
32 Correct 5 ms 636 KB Output is correct
33 Correct 5 ms 760 KB Output is correct
34 Correct 4 ms 788 KB Output is correct
35 Correct 4 ms 760 KB Output is correct
36 Correct 5 ms 700 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 680 KB Output is correct
40 Correct 5 ms 760 KB Output is correct
41 Correct 3 ms 632 KB Output is correct
42 Correct 4 ms 760 KB Output is correct
43 Correct 5 ms 760 KB Output is correct
44 Correct 3 ms 632 KB Output is correct
45 Correct 4 ms 632 KB Output is correct
46 Correct 73 ms 11736 KB Output is correct
47 Correct 122 ms 11796 KB Output is correct
48 Correct 109 ms 12092 KB Output is correct
49 Correct 88 ms 12200 KB Output is correct
50 Correct 62 ms 12280 KB Output is correct
51 Correct 112 ms 12252 KB Output is correct
52 Correct 56 ms 6288 KB Output is correct
53 Correct 33 ms 3960 KB Output is correct
54 Correct 107 ms 11512 KB Output is correct
55 Correct 110 ms 12280 KB Output is correct
56 Correct 62 ms 11768 KB Output is correct
57 Correct 84 ms 11768 KB Output is correct
58 Correct 83 ms 11744 KB Output is correct
59 Correct 126 ms 11896 KB Output is correct
60 Correct 90 ms 11912 KB Output is correct
61 Correct 364 ms 57088 KB Output is correct
62 Correct 484 ms 57112 KB Output is correct
63 Correct 675 ms 57564 KB Output is correct
64 Correct 573 ms 59536 KB Output is correct
65 Correct 346 ms 60020 KB Output is correct
66 Correct 625 ms 59888 KB Output is correct
67 Correct 467 ms 48132 KB Output is correct
68 Correct 247 ms 24184 KB Output is correct
69 Correct 547 ms 56412 KB Output is correct
70 Correct 585 ms 59900 KB Output is correct
71 Correct 313 ms 57068 KB Output is correct
72 Correct 373 ms 57528 KB Output is correct
73 Correct 419 ms 58084 KB Output is correct
74 Correct 334 ms 58436 KB Output is correct
75 Correct 370 ms 58560 KB Output is correct