Submission #685447

# Submission time Handle Problem Language Result Execution time Memory
685447 2023-01-24T11:31:55 Z OrazB Bigger segments (IZhO19_segments) C++14
100 / 100
93 ms 38588 KB
#include <bits/stdc++.h>
#define N 500005
#define wr cout << "Continue debugging\n";
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second
using namespace std;

ll a[N], mx, n, ind[N];
vector<int> vec;
ll pref[N], dp[N][5];

int calc(int x){
	int l = 0, r = vec.size()-1, pos = 0;
	while(l <= r){
		int md = (l+r)/2;
		if (vec[md] > x) r = md - 1;
		else{
			pos = vec[md];
			l = md + 1;
		}
	}
	return pos;
}

int binary(int i, ll x){
	int l = i+1, r = n, idx=i;
	while(l <= r){
		int md = (l+r)/2;
		if (pref[md]-pref[i] >= x) r = md - 1;
		else{
			idx = md;
			l = md + 1;
		}
	}
	return idx+1;
}

int main ()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
		pref[i] = pref[i-1]+a[i];
	}
	dp[1][1] = 1;
	dp[1][2] = a[1];
	int pos = binary(1, a[1]);
	if (pos <= n){
		ind[pos] = 1;
		vec.pb(pos);
	}
	for (int i = 2; i <= n; i++){
		int pos = ind[calc(i)];
		if (!pos){
			dp[i][1] = 1;
			dp[i][2] = pref[i];
		}else{
			dp[i][1] = dp[pos][1]+1;
			dp[i][2] = pref[i]-pref[pos];
		}
		pos = binary(i, dp[i][2]);
		if (pos > n) continue;
		ind[pos] = i;
		while(vec.size() and vec.back() >= pos){
			vec.pop_back();
		}
		vec.pb(pos);
	}
	cout << dp[n][1];
}	
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 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 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 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 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 472 KB Output is correct
32 Correct 1 ms 472 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 476 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 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 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 472 KB Output is correct
32 Correct 1 ms 472 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 476 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 10 ms 5716 KB Output is correct
47 Correct 16 ms 6696 KB Output is correct
48 Correct 19 ms 6612 KB Output is correct
49 Correct 16 ms 6764 KB Output is correct
50 Correct 15 ms 7124 KB Output is correct
51 Correct 19 ms 6880 KB Output is correct
52 Correct 9 ms 3624 KB Output is correct
53 Correct 6 ms 2388 KB Output is correct
54 Correct 13 ms 6932 KB Output is correct
55 Correct 16 ms 6996 KB Output is correct
56 Correct 12 ms 7124 KB Output is correct
57 Correct 14 ms 6588 KB Output is correct
58 Correct 15 ms 6868 KB Output is correct
59 Correct 13 ms 7124 KB Output is correct
60 Correct 14 ms 7108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 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 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 472 KB Output is correct
32 Correct 1 ms 472 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 476 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 10 ms 5716 KB Output is correct
47 Correct 16 ms 6696 KB Output is correct
48 Correct 19 ms 6612 KB Output is correct
49 Correct 16 ms 6764 KB Output is correct
50 Correct 15 ms 7124 KB Output is correct
51 Correct 19 ms 6880 KB Output is correct
52 Correct 9 ms 3624 KB Output is correct
53 Correct 6 ms 2388 KB Output is correct
54 Correct 13 ms 6932 KB Output is correct
55 Correct 16 ms 6996 KB Output is correct
56 Correct 12 ms 7124 KB Output is correct
57 Correct 14 ms 6588 KB Output is correct
58 Correct 15 ms 6868 KB Output is correct
59 Correct 13 ms 7124 KB Output is correct
60 Correct 14 ms 7108 KB Output is correct
61 Correct 50 ms 28936 KB Output is correct
62 Correct 77 ms 32068 KB Output is correct
63 Correct 81 ms 33672 KB Output is correct
64 Correct 83 ms 36564 KB Output is correct
65 Correct 81 ms 38588 KB Output is correct
66 Correct 93 ms 37636 KB Output is correct
67 Correct 82 ms 30240 KB Output is correct
68 Correct 37 ms 15264 KB Output is correct
69 Correct 71 ms 33640 KB Output is correct
70 Correct 83 ms 38204 KB Output is correct
71 Correct 66 ms 35556 KB Output is correct
72 Correct 69 ms 33692 KB Output is correct
73 Correct 69 ms 35668 KB Output is correct
74 Correct 69 ms 36924 KB Output is correct
75 Correct 71 ms 36968 KB Output is correct