Submission #867780

# Submission time Handle Problem Language Result Execution time Memory
867780 2023-10-29T12:56:48 Z dio_2 Hacker (BOI15_hac) C++17
100 / 100
174 ms 65384 KB
#include<bits/stdc++.h>
using namespace std;

const int MAX_N = 12 * 500'000;

int ST[MAX_N];
int N, NN;
	
int get_min(int l, int r){
	l += NN, r += NN;
	int res = int(1e9);
	while(l <= r){
		if(l % 2 == 1) res = min(res, ST[l++]);
		if(r % 2 == 0) res = min(res, ST[r--]);
		l /= 2, r /= 2;
	}
	return res;
}

void SET(int pos, int val){
	pos += NN;
	ST[pos] = val;
	for(pos /= 2;pos >= 1;pos /= 2) ST[pos] = min(ST[2 * pos], ST[2 * pos + 1]);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	for(int i = 0;i < MAX_N;i++) ST[i] = (int)1e9;
	
	cin >> N;
	
	NN = 3 * N;
	
	vector<int> A(N);
	for(int &x : A) cin >> x; // A[i] <= 2000

	for(int i = 0;i < N;i++) A.push_back(A[i]);
	for(int i = 0;i < N;i++) A.push_back(A[i]);
	
	vector<array<int, 3>> wids;
	auto add = [&](int s, int l, int r)->void{
		wids.push_back({s, l, r});
	};
	
	int K = (N + 1) / 2;
	int sum = 0;
	for(int i = 0;i < K;i++){
		sum += A[N-K+i+1];
	}
	
	add(sum, N-K+1, N);
	
	for(int i = N + 1;i < 3 * N;++i){
		sum += A[i];
		sum -= A[i - K];
		add(sum, i - K + 1, i);
	}
	
	vector<int> in(NN, -1), out(NN, -1);
	vector<int> sums;
	int id = 0;
	for(auto [s, l, r] : wids){
		sums.push_back(s);
		swap(l, r);
		if(in[l] == -1) in[l] = id;
		if(out[r] == -1 && in[r] != -1) out[r] = id;
		++id;
	}
	
	int ans = 0;
	
	for(int i = 0;i < (int)sums.size();i++){
		SET(i, sums[i]);
	}
	
	for(int i = 0;i < NN;i++){
		if(in[i] == -1 || out[i] == -1) continue;
		//~ for(int j = in[i];j <= out[i];j++) res = min(res, sums[j]);
		ans = max(ans, get_min(in[i], out[i]));
	}
	
	cout << ans << '\n';
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23896 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
3 Correct 7 ms 23900 KB Output is correct
4 Correct 5 ms 23900 KB Output is correct
5 Correct 5 ms 23712 KB Output is correct
6 Correct 5 ms 23900 KB Output is correct
7 Correct 5 ms 23944 KB Output is correct
8 Correct 5 ms 23900 KB Output is correct
9 Correct 5 ms 23900 KB Output is correct
10 Correct 5 ms 23896 KB Output is correct
11 Correct 5 ms 23896 KB Output is correct
12 Correct 5 ms 23900 KB Output is correct
13 Correct 5 ms 23900 KB Output is correct
14 Correct 5 ms 23900 KB Output is correct
15 Correct 5 ms 23900 KB Output is correct
16 Correct 5 ms 23980 KB Output is correct
17 Correct 5 ms 23900 KB Output is correct
18 Correct 6 ms 23900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23896 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
3 Correct 7 ms 23900 KB Output is correct
4 Correct 5 ms 23900 KB Output is correct
5 Correct 5 ms 23712 KB Output is correct
6 Correct 5 ms 23900 KB Output is correct
7 Correct 5 ms 23944 KB Output is correct
8 Correct 5 ms 23900 KB Output is correct
9 Correct 5 ms 23900 KB Output is correct
10 Correct 5 ms 23896 KB Output is correct
11 Correct 5 ms 23896 KB Output is correct
12 Correct 5 ms 23900 KB Output is correct
13 Correct 5 ms 23900 KB Output is correct
14 Correct 5 ms 23900 KB Output is correct
15 Correct 5 ms 23900 KB Output is correct
16 Correct 5 ms 23980 KB Output is correct
17 Correct 5 ms 23900 KB Output is correct
18 Correct 6 ms 23900 KB Output is correct
19 Correct 6 ms 23900 KB Output is correct
20 Correct 5 ms 23976 KB Output is correct
21 Correct 6 ms 23900 KB Output is correct
22 Correct 6 ms 24176 KB Output is correct
23 Correct 8 ms 24480 KB Output is correct
24 Correct 6 ms 24156 KB Output is correct
25 Correct 9 ms 24232 KB Output is correct
26 Correct 6 ms 24156 KB Output is correct
27 Correct 5 ms 23900 KB Output is correct
28 Correct 5 ms 23900 KB Output is correct
29 Correct 5 ms 23688 KB Output is correct
30 Correct 6 ms 24156 KB Output is correct
31 Correct 9 ms 24156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 23716 KB Output is correct
2 Correct 5 ms 23896 KB Output is correct
3 Correct 6 ms 24156 KB Output is correct
4 Correct 39 ms 30156 KB Output is correct
5 Correct 64 ms 40612 KB Output is correct
6 Correct 82 ms 43476 KB Output is correct
7 Correct 97 ms 51660 KB Output is correct
8 Correct 166 ms 65384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23896 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
3 Correct 7 ms 23900 KB Output is correct
4 Correct 5 ms 23900 KB Output is correct
5 Correct 5 ms 23712 KB Output is correct
6 Correct 5 ms 23900 KB Output is correct
7 Correct 5 ms 23944 KB Output is correct
8 Correct 5 ms 23900 KB Output is correct
9 Correct 5 ms 23900 KB Output is correct
10 Correct 5 ms 23896 KB Output is correct
11 Correct 5 ms 23896 KB Output is correct
12 Correct 5 ms 23900 KB Output is correct
13 Correct 5 ms 23900 KB Output is correct
14 Correct 5 ms 23900 KB Output is correct
15 Correct 5 ms 23900 KB Output is correct
16 Correct 5 ms 23980 KB Output is correct
17 Correct 5 ms 23900 KB Output is correct
18 Correct 6 ms 23900 KB Output is correct
19 Correct 6 ms 23900 KB Output is correct
20 Correct 5 ms 23976 KB Output is correct
21 Correct 6 ms 23900 KB Output is correct
22 Correct 6 ms 24176 KB Output is correct
23 Correct 8 ms 24480 KB Output is correct
24 Correct 6 ms 24156 KB Output is correct
25 Correct 9 ms 24232 KB Output is correct
26 Correct 6 ms 24156 KB Output is correct
27 Correct 5 ms 23900 KB Output is correct
28 Correct 5 ms 23900 KB Output is correct
29 Correct 5 ms 23688 KB Output is correct
30 Correct 6 ms 24156 KB Output is correct
31 Correct 9 ms 24156 KB Output is correct
32 Correct 8 ms 23716 KB Output is correct
33 Correct 5 ms 23896 KB Output is correct
34 Correct 6 ms 24156 KB Output is correct
35 Correct 39 ms 30156 KB Output is correct
36 Correct 64 ms 40612 KB Output is correct
37 Correct 82 ms 43476 KB Output is correct
38 Correct 97 ms 51660 KB Output is correct
39 Correct 166 ms 65384 KB Output is correct
40 Correct 7 ms 24664 KB Output is correct
41 Correct 12 ms 25396 KB Output is correct
42 Correct 14 ms 26348 KB Output is correct
43 Correct 70 ms 40032 KB Output is correct
44 Correct 166 ms 63808 KB Output is correct
45 Correct 37 ms 31828 KB Output is correct
46 Correct 104 ms 52772 KB Output is correct
47 Correct 174 ms 63740 KB Output is correct
48 Correct 169 ms 65208 KB Output is correct
49 Correct 154 ms 63912 KB Output is correct
50 Correct 158 ms 63552 KB Output is correct