제출 #862983

#제출 시각아이디문제언어결과실행 시간메모리
862983somethingnewBigger segments (IZhO19_segments)C++17
0 / 100
0 ms348 KiB
// ↘ ⬇ ⬇ ⬇ ⬇ ⬇ ↙ // ➡ @roadfromroi ⬅ // ↗ ⬆ ⬆ ⬆ ⬆ ⬆ ↖ #include <iostream> #include "vector" #include "algorithm" #include "numeric" #include "climits" #include "iomanip" #include "bitset" #include "cmath" #include "map" #include "deque" #include "array" #include "set" #define all(x) x.begin(), x.end() using namespace std; #define int long long void upd(pair<int, int> &a, pair<int, int> b) { if (a.first < b.first) a = b; if (a.first == b.first) a = min(a, b); } struct myset { set<pair<int, pair<int, int>>> st; void add(int x, pair<int, int> y) { while (1) { auto it = st.lower_bound({x, {-1, -1}}); if (it == st.end()) break; if (y >= ((*it).second)) st.erase(it); else break; } auto it = st.lower_bound({x+1, {-1, -1}}); if (it != st.begin()) { it--; if ((*it).second >= y) return; } st.insert({x, y}); } pair<int, int> get(int x) { auto it = st.lower_bound({x+1, {-1, -1}}); if (it != st.begin()) { it--; return it->second; } return {-1e9, 0}; } }; void solve() { int n; cin >> n; vector<int> a(n); vector<int> prf(n + 1); for (int i = 0; i < n; ++i) { cin >> a[i]; prf[i + 1] = prf[i] + a[i]; } vector<pair<int, int>> dp(n + 1, {-1e9, 0}); dp[0] = {0, 0}; myset st; st.add(0, {0, 0}); for (int i = 1; i <= n; ++i) { //cout << i << endl; int vl = prf[i]; pair<int, int> gt = st.get(vl); upd(dp[i], {gt.first + 1, vl + gt.second}); st.add(dp[i].second + prf[i], {dp[i].first, -prf[i]}); } cout << dp[n].first << '\n'; } signed main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); int t = 1; while (t--) { solve(); } }
#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...