제출 #1127763

#제출 시각아이디문제언어결과실행 시간메모리
1127763VMaksimoski008Bigger segments (IZhO19_segments)C++17
100 / 100
216 ms14116 KiB
#include <bits/stdc++.h> #define ar array //#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 fenwick { int n; vector<pii> tree; fenwick(int _n) : n(_n+10), tree(_n+50) {} void update(int p, int v, int p2) { for(p++; p<n; p+=p&-p) tree[p] = max(tree[p], { v, p2 }); } pii query(int p) { pii ans = { 0, 0 }; for(p++; p; p-=p&-p) ans = max(ans, tree[p]); return ans; } }; signed main() { int n; cin >> n; vector<int> a(n+1); vector<ll> pref(n+1); for(int i=1; i<=n; i++) cin >> a[i]; for(int i=1; i<=n; i++) pref[i] = pref[i-1] + a[i]; pref.push_back(1e18); vector<int> dp(n+1), last(n+1); dp[0] = 0; fenwick fwt(n); for(int i=1; i<=n; i++) { auto [v, p] = fwt.query(i); dp[i] = v + 1; last[i] = p; ll V = 2 * pref[i] - pref[p]; int l=0, r=n+1, pos=0; while(l <= r) { int mid = (l + r) / 2; if(V <= pref[mid]) pos = mid, r = mid - 1; else l = mid + 1; } fwt.update(pos, dp[i], i); } cout << dp[n] << '\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...
#Verdict Execution timeMemoryGrader output
Fetching results...