답안 #641601

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
641601 2022-09-17T09:00:25 Z andreast12 Bigger segments (IZhO19_segments) C++17
100 / 100
149 ms 19264 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
const int mod=998244353, maxn=5e5+5;
int n, a, dp[maxn], prv;
ll pf[maxn], tree[4*maxn], inf=1e18;

void build(int now, int tl, int tr) {
	if(tl==tr) {
		tree[now]=(tl)?inf:0;
		return;
	}
	int mid=(tl+tr)/2;
	build(now*2, tl, mid);
	build(now*2+1, mid+1, tr);
	tree[now]=min(tree[now*2], tree[now*2+1]);
}

int query(int now, int tl, int tr, ll val) {
	if(tl==tr) return tl;
	int mid=(tl+tr)/2;
	if(tree[now*2+1]<=val) return query(now*2+1, mid+1, tr, val);
	return query(now*2, tl, mid, val);
}

void update(int now, int tl, int tr, int pos, ll val) {
	if(tl==tr) {
		tree[now]=val;
		return;
	}
	int mid=(tl+tr)/2;
	if(pos<=mid) update(now*2, tl, mid, pos, val);
	else update(now*2+1, mid+1, tr, pos, val);
	tree[now]=min(tree[now*2], tree[now*2+1]);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	build(1, 0, n);
	for(int i=1; i<=n; i++) {
		cin >> a;
		pf[i]=pf[i-1]+a;
		prv=query(1, 0, n, pf[i]);
		dp[i]=dp[prv]+1;
		// cout << i << ": " << prv << ' ' << dp[i] << '\n';
		update(1, 0, n, i, pf[i]*2-pf[prv]);
	}
	cout << dp[n] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 328 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 328 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 328 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 328 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 328 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 328 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 21 ms 3908 KB Output is correct
47 Correct 25 ms 3928 KB Output is correct
48 Correct 25 ms 4292 KB Output is correct
49 Correct 26 ms 4444 KB Output is correct
50 Correct 28 ms 4480 KB Output is correct
51 Correct 28 ms 4428 KB Output is correct
52 Correct 17 ms 2404 KB Output is correct
53 Correct 11 ms 1492 KB Output is correct
54 Correct 23 ms 3776 KB Output is correct
55 Correct 28 ms 4452 KB Output is correct
56 Correct 25 ms 3944 KB Output is correct
57 Correct 24 ms 3916 KB Output is correct
58 Correct 23 ms 3932 KB Output is correct
59 Correct 25 ms 4132 KB Output is correct
60 Correct 25 ms 4108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 328 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 328 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 2 ms 468 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 21 ms 3908 KB Output is correct
47 Correct 25 ms 3928 KB Output is correct
48 Correct 25 ms 4292 KB Output is correct
49 Correct 26 ms 4444 KB Output is correct
50 Correct 28 ms 4480 KB Output is correct
51 Correct 28 ms 4428 KB Output is correct
52 Correct 17 ms 2404 KB Output is correct
53 Correct 11 ms 1492 KB Output is correct
54 Correct 23 ms 3776 KB Output is correct
55 Correct 28 ms 4452 KB Output is correct
56 Correct 25 ms 3944 KB Output is correct
57 Correct 24 ms 3916 KB Output is correct
58 Correct 23 ms 3932 KB Output is correct
59 Correct 25 ms 4132 KB Output is correct
60 Correct 25 ms 4108 KB Output is correct
61 Correct 112 ms 16252 KB Output is correct
62 Correct 116 ms 16296 KB Output is correct
63 Correct 121 ms 16720 KB Output is correct
64 Correct 144 ms 18936 KB Output is correct
65 Correct 146 ms 19264 KB Output is correct
66 Correct 149 ms 19176 KB Output is correct
67 Correct 116 ms 16972 KB Output is correct
68 Correct 54 ms 8692 KB Output is correct
69 Correct 120 ms 15396 KB Output is correct
70 Correct 141 ms 19200 KB Output is correct
71 Correct 131 ms 16340 KB Output is correct
72 Correct 122 ms 16692 KB Output is correct
73 Correct 126 ms 17308 KB Output is correct
74 Correct 131 ms 17664 KB Output is correct
75 Correct 131 ms 17608 KB Output is correct