답안 #276487

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
276487 2020-08-20T13:10:29 Z aZvezda Bigger segments (IZhO19_segments) C++14
100 / 100
366 ms 21368 KB
#include <bits/stdc++.h>
using namespace std;
#define endl "\n" // BRAT NASKO KUF E TOQ TRASH KOD
template<class T, class T2> bool chkmax(T &a, const T2 &b) {return (a < b) ? a = b, 1 : 0;}
typedef long long ll;

const ll MAX_N = 5e5 + 10;
ll arr[MAX_N];

ll tree[4 * MAX_N];

void upd(ll curr, ll l, ll r, ll ind, ll val) {
	if(l == r && l == ind) {
		chkmax(tree[curr], val);
		return;
	} else if(r < ind || l > ind) {return;}
	ll m = (l + r) / 2ll;
	upd(curr * 2, l, m, ind, val);
	upd(curr * 2 + 1, m + 1, r, ind, val);
	tree[curr] = max(tree[curr * 2], tree[curr * 2 + 1]);
}

ll ans(ll curr, ll l, ll r, ll ql, ll qr) {
	if(ql <= l && r <= qr) {
		return tree[curr];
	} else if(l > qr || r < ql) {
		return 0;
	}
	ll m = (l + r) / 2ll;
	return max(ans(curr * 2, l, m, ql, qr), ans(curr * 2 + 1, m + 1, r, ql, qr));
}

ll dp[MAX_N];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll n;
	cin >> n;
	for(ll i = 1; i <= n; i ++) {
		cin >> arr[i];
		arr[i] += arr[i - 1];
	}
	for(ll i = 1; i <= n; i ++) {
		ll curr = ans(1, 0, n, 0, i);
		dp[i] = dp[curr] + 1;
		ll nowWeight = arr[i] * 2 - arr[curr];
		ll ind = lower_bound(arr + 1, arr + n + 1, nowWeight) - arr;
		upd(1, 0, n, ind, i);
	}
	cout << dp[n] << endl;
}
/*NASKO E GOLQM GEI*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 2 ms 512 KB Output is correct
44 Correct 2 ms 512 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 2 ms 512 KB Output is correct
44 Correct 2 ms 512 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 29 ms 1916 KB Output is correct
47 Correct 56 ms 3704 KB Output is correct
48 Correct 58 ms 3960 KB Output is correct
49 Correct 58 ms 3832 KB Output is correct
50 Correct 63 ms 3960 KB Output is correct
51 Correct 61 ms 3960 KB Output is correct
52 Correct 29 ms 2168 KB Output is correct
53 Correct 17 ms 1280 KB Output is correct
54 Correct 57 ms 3960 KB Output is correct
55 Correct 60 ms 3924 KB Output is correct
56 Correct 58 ms 3960 KB Output is correct
57 Correct 54 ms 3192 KB Output is correct
58 Correct 58 ms 3576 KB Output is correct
59 Correct 65 ms 3960 KB Output is correct
60 Correct 65 ms 3960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 2 ms 512 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 2 ms 512 KB Output is correct
43 Correct 2 ms 512 KB Output is correct
44 Correct 2 ms 512 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 29 ms 1916 KB Output is correct
47 Correct 56 ms 3704 KB Output is correct
48 Correct 58 ms 3960 KB Output is correct
49 Correct 58 ms 3832 KB Output is correct
50 Correct 63 ms 3960 KB Output is correct
51 Correct 61 ms 3960 KB Output is correct
52 Correct 29 ms 2168 KB Output is correct
53 Correct 17 ms 1280 KB Output is correct
54 Correct 57 ms 3960 KB Output is correct
55 Correct 60 ms 3924 KB Output is correct
56 Correct 58 ms 3960 KB Output is correct
57 Correct 54 ms 3192 KB Output is correct
58 Correct 58 ms 3576 KB Output is correct
59 Correct 65 ms 3960 KB Output is correct
60 Correct 65 ms 3960 KB Output is correct
61 Correct 162 ms 9464 KB Output is correct
62 Correct 239 ms 14328 KB Output is correct
63 Correct 331 ms 16616 KB Output is correct
64 Correct 366 ms 20956 KB Output is correct
65 Correct 338 ms 21368 KB Output is correct
66 Correct 334 ms 21208 KB Output is correct
67 Correct 269 ms 18696 KB Output is correct
68 Correct 143 ms 9592 KB Output is correct
69 Correct 310 ms 17388 KB Output is correct
70 Correct 340 ms 21284 KB Output is correct
71 Correct 336 ms 18296 KB Output is correct
72 Correct 311 ms 15472 KB Output is correct
73 Correct 324 ms 18168 KB Output is correct
74 Correct 326 ms 19808 KB Output is correct
75 Correct 325 ms 19704 KB Output is correct