답안 #869128

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
869128 2023-11-03T09:27:17 Z 12345678 Bigger segments (IZhO19_segments) C++17
100 / 100
113 ms 31828 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int nx=5e5+5;
ll dp[nx], a[nx], qs[nx], lst[nx], n;

struct segtree
{
    ll d[4*nx];
    void update(int l, int r, int i, int idx, ll vl)
    {
        if (idx<l||r<idx) return;
        if (l==r) return void(d[i]=vl);
        int md=(l+r)/2;
        update(l, md, 2*i, idx, vl);
        update(md+1, r, 2*i+1, idx, vl);
        d[i]=min(d[2*i], d[2*i+1]);
    }
    ll query(int l, int r, int i, ll vl)
    {
        if (l==r) return l;
        int md=(l+r)/2;
        if (d[2*i+1]<=vl) return query(md+1, r, 2*i+1, vl);
        else return query(l, md, 2*i, vl);
    }
} s;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n;
    for (int i=1; i<=n; i++) cin>>a[i], qs[i]=qs[i-1]+a[i];
    for (int i=1; i<=4*n; i++) s.d[i]=1e18;
    s.update(0, n, 1, 0, 0);
    for (int i=1; i<=n; i++)
    {
        ll l=s.query(0, n, 1, qs[i]);
        dp[i]=dp[l]+1;
        lst[i]=qs[i]-qs[l];
        //cout<<i<<' '<<l<<' '<<dp[i]<<' '<<lst[i]<<'\n';
        s.update(0, n, 1, i, lst[i]+qs[i]);
    }
    cout<<dp[n];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4952 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4568 KB Output is correct
34 Correct 1 ms 4700 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 1 ms 4708 KB Output is correct
37 Correct 1 ms 4700 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4700 KB Output is correct
41 Correct 1 ms 4700 KB Output is correct
42 Correct 1 ms 4700 KB Output is correct
43 Correct 1 ms 4952 KB Output is correct
44 Correct 1 ms 4700 KB Output is correct
45 Correct 2 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4952 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4568 KB Output is correct
34 Correct 1 ms 4700 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 1 ms 4708 KB Output is correct
37 Correct 1 ms 4700 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4700 KB Output is correct
41 Correct 1 ms 4700 KB Output is correct
42 Correct 1 ms 4700 KB Output is correct
43 Correct 1 ms 4952 KB Output is correct
44 Correct 1 ms 4700 KB Output is correct
45 Correct 2 ms 4700 KB Output is correct
46 Correct 18 ms 10328 KB Output is correct
47 Correct 19 ms 10328 KB Output is correct
48 Correct 23 ms 10332 KB Output is correct
49 Correct 22 ms 10256 KB Output is correct
50 Correct 22 ms 10228 KB Output is correct
51 Correct 22 ms 10388 KB Output is correct
52 Correct 11 ms 7512 KB Output is correct
53 Correct 9 ms 7260 KB Output is correct
54 Correct 19 ms 10328 KB Output is correct
55 Correct 23 ms 10584 KB Output is correct
56 Correct 21 ms 10332 KB Output is correct
57 Correct 25 ms 10348 KB Output is correct
58 Correct 20 ms 10260 KB Output is correct
59 Correct 20 ms 10320 KB Output is correct
60 Correct 20 ms 10332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4952 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4568 KB Output is correct
34 Correct 1 ms 4700 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 1 ms 4708 KB Output is correct
37 Correct 1 ms 4700 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4700 KB Output is correct
41 Correct 1 ms 4700 KB Output is correct
42 Correct 1 ms 4700 KB Output is correct
43 Correct 1 ms 4952 KB Output is correct
44 Correct 1 ms 4700 KB Output is correct
45 Correct 2 ms 4700 KB Output is correct
46 Correct 18 ms 10328 KB Output is correct
47 Correct 19 ms 10328 KB Output is correct
48 Correct 23 ms 10332 KB Output is correct
49 Correct 22 ms 10256 KB Output is correct
50 Correct 22 ms 10228 KB Output is correct
51 Correct 22 ms 10388 KB Output is correct
52 Correct 11 ms 7512 KB Output is correct
53 Correct 9 ms 7260 KB Output is correct
54 Correct 19 ms 10328 KB Output is correct
55 Correct 23 ms 10584 KB Output is correct
56 Correct 21 ms 10332 KB Output is correct
57 Correct 25 ms 10348 KB Output is correct
58 Correct 20 ms 10260 KB Output is correct
59 Correct 20 ms 10320 KB Output is correct
60 Correct 20 ms 10332 KB Output is correct
61 Correct 95 ms 31500 KB Output is correct
62 Correct 98 ms 31748 KB Output is correct
63 Correct 106 ms 31504 KB Output is correct
64 Correct 111 ms 31544 KB Output is correct
65 Correct 113 ms 31748 KB Output is correct
66 Correct 112 ms 31748 KB Output is correct
67 Correct 92 ms 30036 KB Output is correct
68 Correct 45 ms 21580 KB Output is correct
69 Correct 94 ms 31512 KB Output is correct
70 Correct 113 ms 31724 KB Output is correct
71 Correct 100 ms 31572 KB Output is correct
72 Correct 98 ms 31712 KB Output is correct
73 Correct 102 ms 31504 KB Output is correct
74 Correct 106 ms 31828 KB Output is correct
75 Correct 107 ms 31572 KB Output is correct