Submission #101130

# Submission time Handle Problem Language Result Execution time Memory
101130 2019-03-16T19:13:13 Z luciocf Hacker (BOI15_hac) C++14
100 / 100
706 ms 22508 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 5e5+10;
const int inf = 1e9+10;

int n;
int v[2*maxn], soma[maxn];
int tree[4*maxn], lazy[4*maxn];

void init(void)
{
	for (int i = 0; i < 4*maxn; i++)
		tree[i] = lazy[i] = inf;
}

void flush(int node, int l, int r)
{
	if (lazy[node] == inf) return;

	tree[node] = min(tree[node], lazy[node]);

	if (l != r)
	{
		lazy[2*node] = min(lazy[2*node], lazy[node]);
		lazy[2*node+1] = min(lazy[2*node+1], lazy[node]);
	}

	lazy[node] = inf;
}

void upd(int node, int l, int r, int a, int b, int v)
{
	flush(node, l, r);
	if (l > b || r < a) return;

	if (l >= a && r <= b)
	{
		lazy[node] = v;
		flush(node, l, r);
		return;
	}

	int mid = (l+r)>>1;

	upd(2*node, l, mid, a, b, v); upd(2*node+1, mid+1, r, a, b, v);

	tree[node] = min(tree[2*node], tree[2*node+1]);
}

int query(int node, int l, int r, int a, int b)
{
	flush(node, l, r);
	if (l > b || r < a) return inf;

	if (l >= a && r <= b) return tree[node];

	int mid = (l+r)>>1;

	return min(query(2*node, l, mid, a, b), query(2*node+1, mid+1, r, a, b));
}

int main(void)
{
	init();

	cin >> n;

	int m = (n+1)/2;

	for (int i = 1; i <= n; i++)
	{
		cin >> v[i];
		v[n+i] = v[i];
	}

	int soma = 0;
	for (int i = 1; i <= m; i++)
		soma += v[i];

	upd(1, 1, n, 1, m, soma);

	int ans = 0;
	for (int i = m + 1; i-m+1 <= n; i++)
	{
		soma -= v[i-m];
		soma += v[i];

		if (i <= n) upd(1, 1, n, i-m+1, i, soma);
		else
		{
			upd(1, 1, n, i-m+1, n, soma); upd(1, 1, n, 1, i-n, soma);
		}
	}

	for (int i = 1; i <= n; i++) 
		ans = max(ans, query(1, 1, n, i, i));

	cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 16000 KB Output is correct
2 Correct 16 ms 16000 KB Output is correct
3 Correct 14 ms 16000 KB Output is correct
4 Correct 14 ms 16000 KB Output is correct
5 Correct 16 ms 16000 KB Output is correct
6 Correct 17 ms 16000 KB Output is correct
7 Correct 16 ms 16000 KB Output is correct
8 Correct 17 ms 16000 KB Output is correct
9 Correct 14 ms 15972 KB Output is correct
10 Correct 15 ms 16000 KB Output is correct
11 Correct 16 ms 16000 KB Output is correct
12 Correct 16 ms 16000 KB Output is correct
13 Correct 15 ms 16000 KB Output is correct
14 Correct 16 ms 16000 KB Output is correct
15 Correct 14 ms 15992 KB Output is correct
16 Correct 16 ms 16000 KB Output is correct
17 Correct 16 ms 16000 KB Output is correct
18 Correct 17 ms 16000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 16000 KB Output is correct
2 Correct 16 ms 16000 KB Output is correct
3 Correct 14 ms 16000 KB Output is correct
4 Correct 14 ms 16000 KB Output is correct
5 Correct 16 ms 16000 KB Output is correct
6 Correct 17 ms 16000 KB Output is correct
7 Correct 16 ms 16000 KB Output is correct
8 Correct 17 ms 16000 KB Output is correct
9 Correct 14 ms 15972 KB Output is correct
10 Correct 15 ms 16000 KB Output is correct
11 Correct 16 ms 16000 KB Output is correct
12 Correct 16 ms 16000 KB Output is correct
13 Correct 15 ms 16000 KB Output is correct
14 Correct 16 ms 16000 KB Output is correct
15 Correct 14 ms 15992 KB Output is correct
16 Correct 16 ms 16000 KB Output is correct
17 Correct 16 ms 16000 KB Output is correct
18 Correct 17 ms 16000 KB Output is correct
19 Correct 16 ms 16000 KB Output is correct
20 Correct 15 ms 16000 KB Output is correct
21 Correct 17 ms 16000 KB Output is correct
22 Correct 16 ms 16000 KB Output is correct
23 Correct 18 ms 16000 KB Output is correct
24 Correct 16 ms 16000 KB Output is correct
25 Correct 24 ms 16000 KB Output is correct
26 Correct 18 ms 16000 KB Output is correct
27 Correct 16 ms 15964 KB Output is correct
28 Correct 15 ms 16000 KB Output is correct
29 Correct 15 ms 16000 KB Output is correct
30 Correct 21 ms 16000 KB Output is correct
31 Correct 18 ms 16000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 15992 KB Output is correct
2 Correct 15 ms 15932 KB Output is correct
3 Correct 21 ms 16000 KB Output is correct
4 Correct 90 ms 16632 KB Output is correct
5 Correct 239 ms 17728 KB Output is correct
6 Correct 287 ms 18012 KB Output is correct
7 Correct 325 ms 18508 KB Output is correct
8 Correct 518 ms 19960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 16000 KB Output is correct
2 Correct 16 ms 16000 KB Output is correct
3 Correct 14 ms 16000 KB Output is correct
4 Correct 14 ms 16000 KB Output is correct
5 Correct 16 ms 16000 KB Output is correct
6 Correct 17 ms 16000 KB Output is correct
7 Correct 16 ms 16000 KB Output is correct
8 Correct 17 ms 16000 KB Output is correct
9 Correct 14 ms 15972 KB Output is correct
10 Correct 15 ms 16000 KB Output is correct
11 Correct 16 ms 16000 KB Output is correct
12 Correct 16 ms 16000 KB Output is correct
13 Correct 15 ms 16000 KB Output is correct
14 Correct 16 ms 16000 KB Output is correct
15 Correct 14 ms 15992 KB Output is correct
16 Correct 16 ms 16000 KB Output is correct
17 Correct 16 ms 16000 KB Output is correct
18 Correct 17 ms 16000 KB Output is correct
19 Correct 16 ms 16000 KB Output is correct
20 Correct 15 ms 16000 KB Output is correct
21 Correct 17 ms 16000 KB Output is correct
22 Correct 16 ms 16000 KB Output is correct
23 Correct 18 ms 16000 KB Output is correct
24 Correct 16 ms 16000 KB Output is correct
25 Correct 24 ms 16000 KB Output is correct
26 Correct 18 ms 16000 KB Output is correct
27 Correct 16 ms 15964 KB Output is correct
28 Correct 15 ms 16000 KB Output is correct
29 Correct 15 ms 16000 KB Output is correct
30 Correct 21 ms 16000 KB Output is correct
31 Correct 18 ms 16000 KB Output is correct
32 Correct 14 ms 15992 KB Output is correct
33 Correct 15 ms 15932 KB Output is correct
34 Correct 21 ms 16000 KB Output is correct
35 Correct 90 ms 16632 KB Output is correct
36 Correct 239 ms 17728 KB Output is correct
37 Correct 287 ms 18012 KB Output is correct
38 Correct 325 ms 18508 KB Output is correct
39 Correct 518 ms 19960 KB Output is correct
40 Correct 25 ms 16052 KB Output is correct
41 Correct 36 ms 16260 KB Output is correct
42 Correct 47 ms 16376 KB Output is correct
43 Correct 268 ms 18480 KB Output is correct
44 Correct 566 ms 22180 KB Output is correct
45 Correct 115 ms 17144 KB Output is correct
46 Correct 342 ms 19704 KB Output is correct
47 Correct 706 ms 22008 KB Output is correct
48 Correct 602 ms 22508 KB Output is correct
49 Correct 551 ms 21628 KB Output is correct
50 Correct 573 ms 21596 KB Output is correct