Submission #101131

# Submission time Handle Problem Language Result Execution time Memory
101131 2019-03-16T19:17:59 Z luciocf Hacker (BOI15_hac) C++14
100 / 100
485 ms 20216 KB
// BOI 2015 - Hacker
// Lúcio Cardoso

#include <bits/stdc++.h>
 
using namespace std;
 
const int maxn = 5e5+10;
const int inf = 1e9+10;
 
int n;
int v[2*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 pos)
{
	flush(node, l, r);
	if (l == r) return tree[node];
 
	int mid = (l+r)>>1;
 
	if (pos <= mid) return query(2*node, l, mid, pos);
	return query(2*node+1, mid+1, r, pos);
}
 
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));
 
	cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 16000 KB Output is correct
2 Correct 18 ms 16000 KB Output is correct
3 Correct 17 ms 16128 KB Output is correct
4 Correct 16 ms 16000 KB Output is correct
5 Correct 18 ms 16000 KB Output is correct
6 Correct 16 ms 16000 KB Output is correct
7 Correct 15 ms 16000 KB Output is correct
8 Correct 17 ms 16000 KB Output is correct
9 Correct 16 ms 16000 KB Output is correct
10 Correct 16 ms 16000 KB Output is correct
11 Correct 18 ms 15972 KB Output is correct
12 Correct 17 ms 16000 KB Output is correct
13 Correct 20 ms 16000 KB Output is correct
14 Correct 16 ms 16000 KB Output is correct
15 Correct 16 ms 16000 KB Output is correct
16 Correct 20 ms 16000 KB Output is correct
17 Correct 19 ms 16000 KB Output is correct
18 Correct 15 ms 16000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 16000 KB Output is correct
2 Correct 18 ms 16000 KB Output is correct
3 Correct 17 ms 16128 KB Output is correct
4 Correct 16 ms 16000 KB Output is correct
5 Correct 18 ms 16000 KB Output is correct
6 Correct 16 ms 16000 KB Output is correct
7 Correct 15 ms 16000 KB Output is correct
8 Correct 17 ms 16000 KB Output is correct
9 Correct 16 ms 16000 KB Output is correct
10 Correct 16 ms 16000 KB Output is correct
11 Correct 18 ms 15972 KB Output is correct
12 Correct 17 ms 16000 KB Output is correct
13 Correct 20 ms 16000 KB Output is correct
14 Correct 16 ms 16000 KB Output is correct
15 Correct 16 ms 16000 KB Output is correct
16 Correct 20 ms 16000 KB Output is correct
17 Correct 19 ms 16000 KB Output is correct
18 Correct 15 ms 16000 KB Output is correct
19 Correct 18 ms 16000 KB Output is correct
20 Correct 16 ms 16000 KB Output is correct
21 Correct 16 ms 16000 KB Output is correct
22 Correct 18 ms 16000 KB Output is correct
23 Correct 19 ms 16000 KB Output is correct
24 Correct 16 ms 16000 KB Output is correct
25 Correct 19 ms 15996 KB Output is correct
26 Correct 21 ms 16000 KB Output is correct
27 Correct 15 ms 16000 KB Output is correct
28 Correct 16 ms 16000 KB Output is correct
29 Correct 18 ms 16000 KB Output is correct
30 Correct 21 ms 16032 KB Output is correct
31 Correct 18 ms 16000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 16128 KB Output is correct
2 Correct 17 ms 16000 KB Output is correct
3 Correct 18 ms 16000 KB Output is correct
4 Correct 136 ms 16760 KB Output is correct
5 Correct 185 ms 17528 KB Output is correct
6 Correct 213 ms 17912 KB Output is correct
7 Correct 261 ms 18368 KB Output is correct
8 Correct 419 ms 20088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 16000 KB Output is correct
2 Correct 18 ms 16000 KB Output is correct
3 Correct 17 ms 16128 KB Output is correct
4 Correct 16 ms 16000 KB Output is correct
5 Correct 18 ms 16000 KB Output is correct
6 Correct 16 ms 16000 KB Output is correct
7 Correct 15 ms 16000 KB Output is correct
8 Correct 17 ms 16000 KB Output is correct
9 Correct 16 ms 16000 KB Output is correct
10 Correct 16 ms 16000 KB Output is correct
11 Correct 18 ms 15972 KB Output is correct
12 Correct 17 ms 16000 KB Output is correct
13 Correct 20 ms 16000 KB Output is correct
14 Correct 16 ms 16000 KB Output is correct
15 Correct 16 ms 16000 KB Output is correct
16 Correct 20 ms 16000 KB Output is correct
17 Correct 19 ms 16000 KB Output is correct
18 Correct 15 ms 16000 KB Output is correct
19 Correct 18 ms 16000 KB Output is correct
20 Correct 16 ms 16000 KB Output is correct
21 Correct 16 ms 16000 KB Output is correct
22 Correct 18 ms 16000 KB Output is correct
23 Correct 19 ms 16000 KB Output is correct
24 Correct 16 ms 16000 KB Output is correct
25 Correct 19 ms 15996 KB Output is correct
26 Correct 21 ms 16000 KB Output is correct
27 Correct 15 ms 16000 KB Output is correct
28 Correct 16 ms 16000 KB Output is correct
29 Correct 18 ms 16000 KB Output is correct
30 Correct 21 ms 16032 KB Output is correct
31 Correct 18 ms 16000 KB Output is correct
32 Correct 16 ms 16128 KB Output is correct
33 Correct 17 ms 16000 KB Output is correct
34 Correct 18 ms 16000 KB Output is correct
35 Correct 136 ms 16760 KB Output is correct
36 Correct 185 ms 17528 KB Output is correct
37 Correct 213 ms 17912 KB Output is correct
38 Correct 261 ms 18368 KB Output is correct
39 Correct 419 ms 20088 KB Output is correct
40 Correct 30 ms 16000 KB Output is correct
41 Correct 30 ms 16256 KB Output is correct
42 Correct 52 ms 16376 KB Output is correct
43 Correct 174 ms 17656 KB Output is correct
44 Correct 446 ms 20088 KB Output is correct
45 Correct 88 ms 16888 KB Output is correct
46 Correct 261 ms 18424 KB Output is correct
47 Correct 413 ms 20216 KB Output is correct
48 Correct 485 ms 20192 KB Output is correct
49 Correct 454 ms 20120 KB Output is correct
50 Correct 482 ms 20088 KB Output is correct