답안 #333181

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
333181 2020-12-04T21:28:42 Z emaborevkovic Bigger segments (IZhO19_segments) C++17
100 / 100
620 ms 44524 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N = 5*1e5+11;
int n, off = 1;
ll a[N], b[N], z[N], ak[N];
ll t[4*N], lazy[4*N];

void clear (int x) {
	t[x] += lazy[x];
	if (x < off) {
		lazy[x*2] += lazy[x];
		lazy[x*2+1] += lazy[x];
	}
	lazy[x] = 0;
}

ll update(int cf, int ct, int lf, int lt, ll c, int node) {
	clear(node);
	if (cf > lt || ct < lf) return t[node];
	if (cf >= lf && ct <= lt) {
		lazy[node] += c;
		clear(node);
		return t[node];
	}
	int mid = (cf+ct)/2;
	update(cf, mid, lf, lt, c, node*2);
	update(mid+1, ct, lf, lt, c, node*2+1);
	return t[node] = max(t[node*2], t[node*2+1]);
}

int upit(int cf, int ct, int node) {
	clear(node); 
	if (cf != ct) {
		clear(node*2); 
		clear(node*2+1);
	}
	int mid = (cf+ct)/2;
	if (cf == ct) return cf;
	if (t[node*2+1] >= 0) return upit(mid+1, ct, node*2+1);
	return upit(cf, mid, node*2);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	while (off < n+1) off *= 2;
	for (int i=0;i<n;i++) {
		cin >> a[i];
		ak[i] = a[i];
		if (i > 0) ak[i] += ak[i-1];
	}
	memset(t, -1, sizeof t);
	b[0] = a[0]; z[0] = -1;
	update(0, off-1, 0, 0, a[0]+1, 1);
	for (int i=1;i<n;i++) {
		update(0, off-1, i, i, -b[i-1]+1, 1);
		update(0, off-1, 0, i, a[i], 1);
		int pos = upit(0, off-1, 1);
		z[i] = pos-1;
		b[i] = ak[i];
		if (pos > 0) b[i] -= ak[pos-1];
	}
	int br = 0;
	int x = n-1;
	while (x >= 0) {
		br++;
		x = z[x];
	}
	cout << br;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 15980 KB Output is correct
2 Correct 9 ms 15980 KB Output is correct
3 Correct 9 ms 15980 KB Output is correct
4 Correct 9 ms 15980 KB Output is correct
5 Correct 9 ms 15980 KB Output is correct
6 Correct 9 ms 15980 KB Output is correct
7 Correct 9 ms 15980 KB Output is correct
8 Correct 9 ms 15980 KB Output is correct
9 Correct 9 ms 15980 KB Output is correct
10 Correct 9 ms 15980 KB Output is correct
11 Correct 9 ms 15980 KB Output is correct
12 Correct 9 ms 15980 KB Output is correct
13 Correct 9 ms 15980 KB Output is correct
14 Correct 9 ms 15980 KB Output is correct
15 Correct 9 ms 15980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 15980 KB Output is correct
2 Correct 9 ms 15980 KB Output is correct
3 Correct 9 ms 15980 KB Output is correct
4 Correct 9 ms 15980 KB Output is correct
5 Correct 9 ms 15980 KB Output is correct
6 Correct 9 ms 15980 KB Output is correct
7 Correct 9 ms 15980 KB Output is correct
8 Correct 9 ms 15980 KB Output is correct
9 Correct 9 ms 15980 KB Output is correct
10 Correct 9 ms 15980 KB Output is correct
11 Correct 9 ms 15980 KB Output is correct
12 Correct 9 ms 15980 KB Output is correct
13 Correct 9 ms 15980 KB Output is correct
14 Correct 9 ms 15980 KB Output is correct
15 Correct 9 ms 15980 KB Output is correct
16 Correct 9 ms 16108 KB Output is correct
17 Correct 9 ms 16108 KB Output is correct
18 Correct 9 ms 16108 KB Output is correct
19 Correct 10 ms 16108 KB Output is correct
20 Correct 9 ms 16108 KB Output is correct
21 Correct 9 ms 16108 KB Output is correct
22 Correct 9 ms 16108 KB Output is correct
23 Correct 9 ms 15980 KB Output is correct
24 Correct 10 ms 16108 KB Output is correct
25 Correct 9 ms 16108 KB Output is correct
26 Correct 9 ms 16108 KB Output is correct
27 Correct 9 ms 16108 KB Output is correct
28 Correct 9 ms 16108 KB Output is correct
29 Correct 9 ms 16108 KB Output is correct
30 Correct 9 ms 16108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 15980 KB Output is correct
2 Correct 9 ms 15980 KB Output is correct
3 Correct 9 ms 15980 KB Output is correct
4 Correct 9 ms 15980 KB Output is correct
5 Correct 9 ms 15980 KB Output is correct
6 Correct 9 ms 15980 KB Output is correct
7 Correct 9 ms 15980 KB Output is correct
8 Correct 9 ms 15980 KB Output is correct
9 Correct 9 ms 15980 KB Output is correct
10 Correct 9 ms 15980 KB Output is correct
11 Correct 9 ms 15980 KB Output is correct
12 Correct 9 ms 15980 KB Output is correct
13 Correct 9 ms 15980 KB Output is correct
14 Correct 9 ms 15980 KB Output is correct
15 Correct 9 ms 15980 KB Output is correct
16 Correct 9 ms 16108 KB Output is correct
17 Correct 9 ms 16108 KB Output is correct
18 Correct 9 ms 16108 KB Output is correct
19 Correct 10 ms 16108 KB Output is correct
20 Correct 9 ms 16108 KB Output is correct
21 Correct 9 ms 16108 KB Output is correct
22 Correct 9 ms 16108 KB Output is correct
23 Correct 9 ms 15980 KB Output is correct
24 Correct 10 ms 16108 KB Output is correct
25 Correct 9 ms 16108 KB Output is correct
26 Correct 9 ms 16108 KB Output is correct
27 Correct 9 ms 16108 KB Output is correct
28 Correct 9 ms 16108 KB Output is correct
29 Correct 9 ms 16108 KB Output is correct
30 Correct 9 ms 16108 KB Output is correct
31 Correct 11 ms 16236 KB Output is correct
32 Correct 13 ms 16236 KB Output is correct
33 Correct 11 ms 16256 KB Output is correct
34 Correct 11 ms 16236 KB Output is correct
35 Correct 12 ms 16236 KB Output is correct
36 Correct 11 ms 16236 KB Output is correct
37 Correct 11 ms 16108 KB Output is correct
38 Correct 10 ms 16108 KB Output is correct
39 Correct 12 ms 16236 KB Output is correct
40 Correct 11 ms 16236 KB Output is correct
41 Correct 11 ms 16236 KB Output is correct
42 Correct 13 ms 16236 KB Output is correct
43 Correct 12 ms 16236 KB Output is correct
44 Correct 11 ms 16236 KB Output is correct
45 Correct 11 ms 16236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 15980 KB Output is correct
2 Correct 9 ms 15980 KB Output is correct
3 Correct 9 ms 15980 KB Output is correct
4 Correct 9 ms 15980 KB Output is correct
5 Correct 9 ms 15980 KB Output is correct
6 Correct 9 ms 15980 KB Output is correct
7 Correct 9 ms 15980 KB Output is correct
8 Correct 9 ms 15980 KB Output is correct
9 Correct 9 ms 15980 KB Output is correct
10 Correct 9 ms 15980 KB Output is correct
11 Correct 9 ms 15980 KB Output is correct
12 Correct 9 ms 15980 KB Output is correct
13 Correct 9 ms 15980 KB Output is correct
14 Correct 9 ms 15980 KB Output is correct
15 Correct 9 ms 15980 KB Output is correct
16 Correct 9 ms 16108 KB Output is correct
17 Correct 9 ms 16108 KB Output is correct
18 Correct 9 ms 16108 KB Output is correct
19 Correct 10 ms 16108 KB Output is correct
20 Correct 9 ms 16108 KB Output is correct
21 Correct 9 ms 16108 KB Output is correct
22 Correct 9 ms 16108 KB Output is correct
23 Correct 9 ms 15980 KB Output is correct
24 Correct 10 ms 16108 KB Output is correct
25 Correct 9 ms 16108 KB Output is correct
26 Correct 9 ms 16108 KB Output is correct
27 Correct 9 ms 16108 KB Output is correct
28 Correct 9 ms 16108 KB Output is correct
29 Correct 9 ms 16108 KB Output is correct
30 Correct 9 ms 16108 KB Output is correct
31 Correct 11 ms 16236 KB Output is correct
32 Correct 13 ms 16236 KB Output is correct
33 Correct 11 ms 16256 KB Output is correct
34 Correct 11 ms 16236 KB Output is correct
35 Correct 12 ms 16236 KB Output is correct
36 Correct 11 ms 16236 KB Output is correct
37 Correct 11 ms 16108 KB Output is correct
38 Correct 10 ms 16108 KB Output is correct
39 Correct 12 ms 16236 KB Output is correct
40 Correct 11 ms 16236 KB Output is correct
41 Correct 11 ms 16236 KB Output is correct
42 Correct 13 ms 16236 KB Output is correct
43 Correct 12 ms 16236 KB Output is correct
44 Correct 11 ms 16236 KB Output is correct
45 Correct 11 ms 16236 KB Output is correct
46 Correct 112 ms 20716 KB Output is correct
47 Correct 113 ms 20716 KB Output is correct
48 Correct 117 ms 20844 KB Output is correct
49 Correct 118 ms 20844 KB Output is correct
50 Correct 119 ms 20716 KB Output is correct
51 Correct 119 ms 20716 KB Output is correct
52 Correct 60 ms 18412 KB Output is correct
53 Correct 38 ms 17516 KB Output is correct
54 Correct 114 ms 20716 KB Output is correct
55 Correct 119 ms 20716 KB Output is correct
56 Correct 116 ms 20716 KB Output is correct
57 Correct 114 ms 20716 KB Output is correct
58 Correct 114 ms 20716 KB Output is correct
59 Correct 115 ms 20716 KB Output is correct
60 Correct 117 ms 20716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 15980 KB Output is correct
2 Correct 9 ms 15980 KB Output is correct
3 Correct 9 ms 15980 KB Output is correct
4 Correct 9 ms 15980 KB Output is correct
5 Correct 9 ms 15980 KB Output is correct
6 Correct 9 ms 15980 KB Output is correct
7 Correct 9 ms 15980 KB Output is correct
8 Correct 9 ms 15980 KB Output is correct
9 Correct 9 ms 15980 KB Output is correct
10 Correct 9 ms 15980 KB Output is correct
11 Correct 9 ms 15980 KB Output is correct
12 Correct 9 ms 15980 KB Output is correct
13 Correct 9 ms 15980 KB Output is correct
14 Correct 9 ms 15980 KB Output is correct
15 Correct 9 ms 15980 KB Output is correct
16 Correct 9 ms 16108 KB Output is correct
17 Correct 9 ms 16108 KB Output is correct
18 Correct 9 ms 16108 KB Output is correct
19 Correct 10 ms 16108 KB Output is correct
20 Correct 9 ms 16108 KB Output is correct
21 Correct 9 ms 16108 KB Output is correct
22 Correct 9 ms 16108 KB Output is correct
23 Correct 9 ms 15980 KB Output is correct
24 Correct 10 ms 16108 KB Output is correct
25 Correct 9 ms 16108 KB Output is correct
26 Correct 9 ms 16108 KB Output is correct
27 Correct 9 ms 16108 KB Output is correct
28 Correct 9 ms 16108 KB Output is correct
29 Correct 9 ms 16108 KB Output is correct
30 Correct 9 ms 16108 KB Output is correct
31 Correct 11 ms 16236 KB Output is correct
32 Correct 13 ms 16236 KB Output is correct
33 Correct 11 ms 16256 KB Output is correct
34 Correct 11 ms 16236 KB Output is correct
35 Correct 12 ms 16236 KB Output is correct
36 Correct 11 ms 16236 KB Output is correct
37 Correct 11 ms 16108 KB Output is correct
38 Correct 10 ms 16108 KB Output is correct
39 Correct 12 ms 16236 KB Output is correct
40 Correct 11 ms 16236 KB Output is correct
41 Correct 11 ms 16236 KB Output is correct
42 Correct 13 ms 16236 KB Output is correct
43 Correct 12 ms 16236 KB Output is correct
44 Correct 11 ms 16236 KB Output is correct
45 Correct 11 ms 16236 KB Output is correct
46 Correct 112 ms 20716 KB Output is correct
47 Correct 113 ms 20716 KB Output is correct
48 Correct 117 ms 20844 KB Output is correct
49 Correct 118 ms 20844 KB Output is correct
50 Correct 119 ms 20716 KB Output is correct
51 Correct 119 ms 20716 KB Output is correct
52 Correct 60 ms 18412 KB Output is correct
53 Correct 38 ms 17516 KB Output is correct
54 Correct 114 ms 20716 KB Output is correct
55 Correct 119 ms 20716 KB Output is correct
56 Correct 116 ms 20716 KB Output is correct
57 Correct 114 ms 20716 KB Output is correct
58 Correct 114 ms 20716 KB Output is correct
59 Correct 115 ms 20716 KB Output is correct
60 Correct 117 ms 20716 KB Output is correct
61 Correct 592 ms 39660 KB Output is correct
62 Correct 594 ms 39532 KB Output is correct
63 Correct 595 ms 39492 KB Output is correct
64 Correct 612 ms 39584 KB Output is correct
65 Correct 619 ms 44396 KB Output is correct
66 Correct 613 ms 44508 KB Output is correct
67 Correct 494 ms 38736 KB Output is correct
68 Correct 242 ms 27372 KB Output is correct
69 Correct 585 ms 40684 KB Output is correct
70 Correct 620 ms 44524 KB Output is correct
71 Correct 596 ms 41548 KB Output is correct
72 Correct 606 ms 41904 KB Output is correct
73 Correct 606 ms 42604 KB Output is correct
74 Correct 605 ms 42920 KB Output is correct
75 Correct 607 ms 42860 KB Output is correct