Submission #1270601

#TimeUsernameProblemLanguageResultExecution timeMemory
1270601cowwycowHacker (BOI15_hac)C++20
100 / 100
63 ms90440 KiB
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define name "aaaaaa"
#define fi first
#define se second
#define endl "\n"
using ll = long long;
using db = double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdb = pair<db, db>;
using ppii = pair<int, pii>;
using ull = unsigned long long;
using vvi = vector<vector<ll>>;

void file(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	if(fopen(name".inp", "r")) {
		freopen(name".inp", "r", stdin);
		freopen(name".out", "w", stdout);
	}
}

const int N = 2e6 + 5;
const int L = 25;

int a[N], pre[N], sum[N];

int st[L][N];

int query(int l, int r){
	int k = __lg(r - l + 1);
	return min(st[k][l], st[k][r - (1 << k) + 1]);
}

void solve(){
	int n; cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		a[n * 2 + i] = a[n + i] = a[i];
	}
	for(int i = 1; i <= n * 3; i++){
		pre[i] = pre[i - 1] + a[i];
	}

	int half = (n + 1) / 2;
	for(int i = 1; i <= n * 2; i++){
		sum[i] = pre[i + half - 1] - pre[i - 1];
	}

	for(int i = 1; i <= n * 2; i++){
		st[0][i] = sum[i];
	}
	for(int i = 1; i < L; i++){
		for(int j = 1; j + (1 << i) - 1 <= n * 2; j++){
			st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
		}
	}

	int ans = 0;
	for(int i = n + 1; i <= n * 2; i++){
		ans = max(ans, query(i - half + 1, i));
	}

	cout << ans;
}

int main(){
	file();
	int test = 1;
	//cin >> test;
	while(test--){
		solve();
	}
}

Compilation message (stderr)

hac.cpp: In function 'void file()':
hac.cpp:20:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |                 freopen(name".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
hac.cpp:21:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |                 freopen(name".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...