제출 #231389

#제출 시각아이디문제언어결과실행 시간메모리
231389maskoffBigger segments (IZhO19_segments)C++14
73 / 100
623 ms250336 KiB
#include <bits/stdc++.h> #include <ext/rope> #include <random> #include <chrono> #include <ext/pb_ds/assoc_container.hpp> #define file "" #define all(x) x.begin(), x.end() #define sc second #define fr first #define pb push_back #define mp make_pair #define pss pair<line*, line*> using namespace std; using namespace __gnu_cxx; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; const ll inf = 1e16; const int MOD = 1e9 + 7; const int dx[] = {+1, -1, 0, 0}; const int dy[] = {0, 0, +1, -1}; int const N = 7e6; vector<int> L, R; vector<pii> t; int cnt = 1; void update (int u, ll l, ll r, ll pos, pll val) { if(l > r) return; if (l == r) { t[u] = val; return; } ll m = (l + r) / 2; if (pos <= m) { if (!L[u]) L[u] = ++cnt; update (L[u], l, m, pos, val); } else { if (!R[u]) R[u] = ++cnt; update (R[u], m + 1, r, pos, val); } t[u] = max(t[L[u]], t[R[u]]); } pii get (int u, ll ul, ll ur, ll l, ll r) { if (!u || l > r || ul > ur || l > ur || ul > r) return {0, 0}; if (l <= ul && ur <= r) return t[u]; ll um = (ul + ur) / 2; return max(get(L[u], ul, um, l, r), get(R[u], um + 1, ur, l, r)); } int main() { ios_base :: sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n + 1); L.resize(N); R = L; t.resize(N); for (int i = 1; i <= n; i++) cin >> a[i]; vector<ll> dp(n + 1), sum(n + 1), pref(n + 1); for (int i = 1; i <= n; i++) pref[i] = pref[i - 1] + a[i]; for (int i = 1; i <= n; i++) { pii k = get(1, 1, inf, 1, pref[i]); dp[i] = k.fr + 1; sum[i] = pref[i] - pref[k.sc]; update (1, 1, inf, sum[i] + pref[i], {dp[i], i}); } cout << dp[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...