# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
723553 |
2023-04-14T04:56:42 Z |
drdilyor |
Hacker (BOI15_hac) |
C++17 |
|
1 ms |
212 KB |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int nextPower2(int n) {
n--;
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
return 1+n;
}
struct segtree {
int n;
vector<ll> t;
segtree(int m) : n(nextPower2(m)), t(n*2, 1e18) {}
void upd(int l, int r, ll x, int v, int tl, int tr) {
if (l <= tl && tr <= r) {
t[v] = min(t[v], x);
return;
}
if (tr < l || r < tl) return;
int mid = (tl+tr) / 2;
upd(l, r, x, v*2, tl, mid);
upd(l, r, x, v*2+1, mid+1, tr);
}
void upd(int l, int r, ll x) {
upd(l, r, x, 1, 0, n-1);
}
ll query(int i) {
ll res = t[i+=n];
for (i /= 2; i >= 1; i /= 2)
res = min(res, t[i]);
return res;
}
};
int main() {
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
vector<int> arr(n*2);
for (int i = 0; i < n; i++) {
cin >> arr[i];
arr[i+n] = arr[i];
}
segtree s(n*2);
ll sum = accumulate(arr.begin(), arr.begin() + (n+1) / 2, 0ll);
for (int l = 0, r = (n+1) / 2 - 1; l < n; l++, r++) {
s.upd(l, r, sum);
sum -= arr[l];
if (r < n-1)sum += arr[r+1];
}
ll res = 0;
for (int i = 0; i < n; i++)
res = max(res, min(s.query(i), s.query(i+n)));
cout << res << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |