답안 #391512

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
391512 2021-04-19T05:54:25 Z _eve Bigger segments (IZhO19_segments) C++17
100 / 100
180 ms 21232 KB
#include <bits/stdc++.h>

#define ll long long

using namespace std;

const int N = 500500;
const int mod = 1e9 + 7;
const ll inf = 1e17 + 10;

int n, a[N], sol, dp[N];
ll pref[N];
ll t[N * 4];

void build(int u,int l,int r) {
    t[u] = inf;
    if(l == r) return;
    int m = l + r >> 1;
    build(u << 1,l,m);
    build(u << 1 | 1,m + 1,r);
}

void get(int u,int l,int r,ll val) {
    if(l == r) {
        if(t[u] <= val) {
            sol = l;
        }
        return;
    }
    int m = l + r >> 1;
    if(t[u << 1 | 1] <= val) get(u << 1 | 1,m + 1,r,val);
    else get(u << 1,l,m,val);
}

void upd(int p,ll val,int u,int l,int r) {
    if(l == r) {
        t[u] = val;
        return;
    }
    int m = l + r >> 1;
    if(p <= m) {
        upd(p,val,u << 1,l,m); 
    } else upd(p,val,u << 1 | 1,m + 1,r);
    t[u] = min(t[u << 1],t[u << 1 | 1]);
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        pref[i] = pref[i - 1] + a[i];
    }
    build(1,1,n);
    for(int i = 1; i <= n; i++) {
        sol = 0;
        get(1,1,n,pref[i]);
        dp[i] = dp[sol] + 1;
        upd(i,2 * pref[i] - pref[sol],1,1,n);
    }
    cout << dp[n];
}

Compilation message

segments.cpp: In function 'void build(int, int, int)':
segments.cpp:18:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   18 |     int m = l + r >> 1;
      |             ~~^~~
segments.cpp: In function 'void get(int, int, int, long long int)':
segments.cpp:30:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |     int m = l + r >> 1;
      |             ~~^~~
segments.cpp: In function 'void upd(int, long long int, int, int, int)':
segments.cpp:40:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |     int m = l + r >> 1;
      |             ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 2 ms 460 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 396 KB Output is correct
36 Correct 2 ms 460 KB Output is correct
37 Correct 1 ms 460 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 2 ms 472 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 2 ms 464 KB Output is correct
43 Correct 1 ms 456 KB Output is correct
44 Correct 2 ms 460 KB Output is correct
45 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 2 ms 460 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 396 KB Output is correct
36 Correct 2 ms 460 KB Output is correct
37 Correct 1 ms 460 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 2 ms 472 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 2 ms 464 KB Output is correct
43 Correct 1 ms 456 KB Output is correct
44 Correct 2 ms 460 KB Output is correct
45 Correct 1 ms 460 KB Output is correct
46 Correct 27 ms 4300 KB Output is correct
47 Correct 29 ms 4296 KB Output is correct
48 Correct 32 ms 4656 KB Output is correct
49 Correct 33 ms 4820 KB Output is correct
50 Correct 34 ms 4804 KB Output is correct
51 Correct 36 ms 4804 KB Output is correct
52 Correct 17 ms 2624 KB Output is correct
53 Correct 10 ms 1516 KB Output is correct
54 Correct 29 ms 4064 KB Output is correct
55 Correct 34 ms 4844 KB Output is correct
56 Correct 36 ms 4408 KB Output is correct
57 Correct 29 ms 4316 KB Output is correct
58 Correct 32 ms 4312 KB Output is correct
59 Correct 34 ms 4532 KB Output is correct
60 Correct 36 ms 4484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 2 ms 460 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 396 KB Output is correct
36 Correct 2 ms 460 KB Output is correct
37 Correct 1 ms 460 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 2 ms 472 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 2 ms 464 KB Output is correct
43 Correct 1 ms 456 KB Output is correct
44 Correct 2 ms 460 KB Output is correct
45 Correct 1 ms 460 KB Output is correct
46 Correct 27 ms 4300 KB Output is correct
47 Correct 29 ms 4296 KB Output is correct
48 Correct 32 ms 4656 KB Output is correct
49 Correct 33 ms 4820 KB Output is correct
50 Correct 34 ms 4804 KB Output is correct
51 Correct 36 ms 4804 KB Output is correct
52 Correct 17 ms 2624 KB Output is correct
53 Correct 10 ms 1516 KB Output is correct
54 Correct 29 ms 4064 KB Output is correct
55 Correct 34 ms 4844 KB Output is correct
56 Correct 36 ms 4408 KB Output is correct
57 Correct 29 ms 4316 KB Output is correct
58 Correct 32 ms 4312 KB Output is correct
59 Correct 34 ms 4532 KB Output is correct
60 Correct 36 ms 4484 KB Output is correct
61 Correct 148 ms 18204 KB Output is correct
62 Correct 148 ms 18216 KB Output is correct
63 Correct 156 ms 18648 KB Output is correct
64 Correct 175 ms 20844 KB Output is correct
65 Correct 176 ms 21232 KB Output is correct
66 Correct 176 ms 21196 KB Output is correct
67 Correct 140 ms 18624 KB Output is correct
68 Correct 70 ms 9448 KB Output is correct
69 Correct 153 ms 17348 KB Output is correct
70 Correct 176 ms 21172 KB Output is correct
71 Correct 158 ms 18260 KB Output is correct
72 Correct 180 ms 18628 KB Output is correct
73 Correct 167 ms 19284 KB Output is correct
74 Correct 167 ms 19660 KB Output is correct
75 Correct 164 ms 19576 KB Output is correct