답안 #526530

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
526530 2022-02-15T06:19:29 Z Bill_00 Bigger segments (IZhO19_segments) C++14
100 / 100
192 ms 25224 KB
#include <bits/stdc++.h>
#define MOD 1000000007
#define ff first
#define ss second
#define N 500005
typedef long long ll;
const ll mx = 1e9 + 100005;
using namespace std;
ll a[N], M[N], H[N], sum[N], mn[4 * N];

ll solve(ll id, ll l, ll r, ll val){
	ll m = l + r >> 1;
	if(l == r) return l;
	if(mn[id * 2 + 1] <= val) return solve(id * 2 + 1, m + 1, r, val);
	else return solve(id * 2, l, m, val);
}

void update(ll id, ll l, ll r, ll pos, ll val){
	if(l == r){
		mn[id] = val;
		return;
	}
	ll m = l + r >> 1;
	if(m >= pos) update(id * 2, l, m, pos, val);
	else update(id * 2 + 1, m + 1, r, pos, val);
	mn[id] = min(mn[id * 2], mn[id * 2 + 1]);
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	for(ll i = 0; i <= n; i++){
		update(1, 0, n, i, 1e18);
	}
	for(ll i = 1; i <= n; i++){
		cin >> a[i];
		sum[i] = sum[i - 1] + a[i];
		ll id = solve(1, 0, n, sum[i]);
		H[i] = H[id] + 1;
		update(1, 0, n, i, sum[i] - sum[id] + sum[i]);

	}
	cout << H[n];
}

Compilation message

segments.cpp: In function 'll solve(ll, ll, ll, ll)':
segments.cpp:12:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   12 |  ll m = l + r >> 1;
      |         ~~^~~
segments.cpp: In function 'void update(ll, ll, ll, ll, ll)':
segments.cpp:23:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   23 |  ll m = l + r >> 1;
      |         ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 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 0 ms 332 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 328 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 316 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 0 ms 336 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 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 0 ms 332 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 328 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 316 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 1 ms 468 KB Output is correct
32 Correct 1 ms 476 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 2 ms 460 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
36 Correct 2 ms 464 KB Output is correct
37 Correct 1 ms 452 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 2 ms 460 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 1 ms 460 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 1 ms 464 KB Output is correct
45 Correct 2 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 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 0 ms 332 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 328 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 316 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 1 ms 468 KB Output is correct
32 Correct 1 ms 476 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 2 ms 460 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
36 Correct 2 ms 464 KB Output is correct
37 Correct 1 ms 452 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 2 ms 460 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 1 ms 460 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 1 ms 464 KB Output is correct
45 Correct 2 ms 464 KB Output is correct
46 Correct 30 ms 5092 KB Output is correct
47 Correct 32 ms 5168 KB Output is correct
48 Correct 37 ms 5512 KB Output is correct
49 Correct 37 ms 5568 KB Output is correct
50 Correct 38 ms 5664 KB Output is correct
51 Correct 38 ms 5664 KB Output is correct
52 Correct 19 ms 3012 KB Output is correct
53 Correct 10 ms 1836 KB Output is correct
54 Correct 38 ms 4892 KB Output is correct
55 Correct 37 ms 5700 KB Output is correct
56 Correct 33 ms 5184 KB Output is correct
57 Correct 33 ms 5040 KB Output is correct
58 Correct 31 ms 5064 KB Output is correct
59 Correct 34 ms 5228 KB Output is correct
60 Correct 34 ms 5320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 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 0 ms 332 KB Output is correct
18 Correct 1 ms 316 KB Output is correct
19 Correct 1 ms 328 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 316 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 1 ms 468 KB Output is correct
32 Correct 1 ms 476 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 2 ms 460 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
36 Correct 2 ms 464 KB Output is correct
37 Correct 1 ms 452 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 2 ms 460 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 1 ms 460 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 1 ms 464 KB Output is correct
45 Correct 2 ms 464 KB Output is correct
46 Correct 30 ms 5092 KB Output is correct
47 Correct 32 ms 5168 KB Output is correct
48 Correct 37 ms 5512 KB Output is correct
49 Correct 37 ms 5568 KB Output is correct
50 Correct 38 ms 5664 KB Output is correct
51 Correct 38 ms 5664 KB Output is correct
52 Correct 19 ms 3012 KB Output is correct
53 Correct 10 ms 1836 KB Output is correct
54 Correct 38 ms 4892 KB Output is correct
55 Correct 37 ms 5700 KB Output is correct
56 Correct 33 ms 5184 KB Output is correct
57 Correct 33 ms 5040 KB Output is correct
58 Correct 31 ms 5064 KB Output is correct
59 Correct 34 ms 5228 KB Output is correct
60 Correct 34 ms 5320 KB Output is correct
61 Correct 152 ms 22148 KB Output is correct
62 Correct 161 ms 22212 KB Output is correct
63 Correct 160 ms 22592 KB Output is correct
64 Correct 175 ms 24772 KB Output is correct
65 Correct 182 ms 25224 KB Output is correct
66 Correct 180 ms 25028 KB Output is correct
67 Correct 144 ms 21720 KB Output is correct
68 Correct 72 ms 11092 KB Output is correct
69 Correct 156 ms 21204 KB Output is correct
70 Correct 192 ms 25156 KB Output is correct
71 Correct 164 ms 22300 KB Output is correct
72 Correct 160 ms 22524 KB Output is correct
73 Correct 167 ms 23260 KB Output is correct
74 Correct 169 ms 23496 KB Output is correct
75 Correct 170 ms 23552 KB Output is correct