Submission #1007709

#TimeUsernameProblemLanguageResultExecution timeMemory
1007709VMaksimoski008Hacker (BOI15_hac)C++17
100 / 100
397 ms45992 KiB
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() //#define int long long using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; struct SegTree { int n; vector<ll> tree, lazy; SegTree(int _n) : n(_n), tree(4*_n+5, 1e18), lazy(4*_n+5, 1e18) {} void push(int u, int tl, int tr) { if(lazy[u] == 1e18) return ; tree[u] = min(tree[u], lazy[u]); if(tl != tr) { lazy[2*u] = min(lazy[u], lazy[2*u+1]); lazy[2*u+1] = min(lazy[u], lazy[2*u+1]); } lazy[u] = 1e18; } void update(int u, int tl, int tr, int l, int r, ll v) { push(u, tl, tr); if(tl > tr || l > tr || tl > r) return ; if(l <= tl && tr <= r) { lazy[u] = min(lazy[u], v); push(u, tl, tr); return ; } int tm = (tl + tr) / 2; update(2*u, tl, tm, l, r, v); update(2*u+1, tm+1, tr, l, r, v); tree[u] = min(tree[2*u], tree[2*u+1]); } ll query(int u, int tl, int tr, int l, int r) { if(tl > tr || l > tr || tl > r) return 1e18; push(u, tl, tr); if(l <= tl && tr <= r) return tree[u]; int tm = (tl + tr) / 2; return min(query(2*u, tl, tm, l, r), query(2*u+1, tm+1, tr, l, r)); } void update(int l, int r, ll v) { update(1, 0, n-1, l, r, v); } ll query(int l, int r) { return query(1, 0, n-1, l, r); } }; signed main() { int n; cin >> n; vector<int> v(n+1); for(int i=1; i<=n; i++) cin >> v[i]; for(int i=1; i<=n; i++) v.push_back(v[i]); vector<ll> pref(2*n+1); for(int i=1; i<=2*n; i++) pref[i] = pref[i-1] + v[i]; SegTree tree(n+1); int len = (n + 1) / 2; for(int i=1; i<=n; i++) { ll val = pref[i+len-1] - pref[i-1]; if(i+len-1 <= n) tree.update(i, i+len-1, val); else { tree.update(i, n, val); tree.update(1, i+len-1-n, val); } } ll ans = 0; for(int i=1; i<=n; i++) ans = max(ans, tree.query(i, i)); cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...