제출 #651049

#제출 시각아이디문제언어결과실행 시간메모리
651049KiriLL1caBigger segments (IZhO19_segments)C++14
0 / 100
1 ms316 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define fr first #define sc second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pw(x) (1ll << x) #define sz(x) (int)((x).size()) #define pb push_back #define endl '\n' #define mp make_pair using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef pair <int, int> pii; typedef pair <ll, ll> pll; typedef unsigned long long ull; template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> using oset = tree<T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; inline void solve () { int n; cin >> n; vector <int> a (n); for (auto &i : a) cin >> i; vector <int> opt (n), dp (n); vector <vector <int>> vec (n + 1); vector <ll> pref (n); pref[0] = a[0]; for (int i = 1; i < n; ++i) pref[i] = pref[i - 1] + a[i]; auto get = [&] (int l, int r) { return pref[r] - (l ? pref[l - 1] : 0); }; for (int i = 0; i < n; ++i) { dp[i] = 1, opt[i] = 0; vec[dp[i]].pb(i); } for (int i = 1; i < n; ++i) { int dpj = 0; for (int p = 19; ~p; --p) { dpj += pw(p); if (dpj > n || !sz(vec[dpj])) dpj -= pw(p); else { int j = vec[dpj][0]; if (get(j + 1, i) < get(opt[j], j)) dpj -= pw(p); } } umax(dp[i], dpj + 1); int optj = 0; for (int p = 19; ~p; --p) { optj += pw(p); if (optj >= sz(vec[dpj])) optj -= pw(p); else { int j = vec[dpj][optj]; if (get(j + 1, i) < get(opt[j], j)) optj -= pw(p); } } opt[i] = optj + 1; vec[dp[i]].pb(i); } cout << dp[n - 1]; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // LOCAL int t = 1; // cin >> t; while (t--) solve(); 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...