Submission #343680

#TimeUsernameProblemLanguageResultExecution timeMemory
343680spike1236Bigger segments (IZhO19_segments)C++14
100 / 100
950 ms259564 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define f first #define s second #define ll long long #define ld long double #define all(_v) _v.begin(), _v.end() #define sz(_v) (int)_v.size() #define pii pair <int, int> #define pll pair <ll, ll> #define veci vector <int> #define vecll vector <ll> const int dx[4] = {1, -1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; const double PI = 3.1415926535897932384626433832795; const double eps = 1e-9; const int MOD1 = 1e9 + 7; const int MOD2 = 998244353; const int MAXN = 5e5 + 10; ll pref[MAXN]; ll a[MAXN]; pll dp[MAXN]; int n; pii t[MAXN * 40]; int ls[MAXN * 40]; int rs[MAXN * 40]; int sz = 1; void upd(ll pos, pll val, int v = 1, ll tl = 1, ll tr = 1e15) { if(tl == tr) { t[v] = val; return; } ll tm = tl + tr >> 1; if(pos <= tm) { if(!ls[v]) ls[v] = ++sz; upd(pos, val, ls[v], tl, tm); } else { if(!rs[v]) rs[v] = ++sz; upd(pos, val, rs[v], tm + 1, tr); } t[v] = max(t[ls[v]], t[rs[v]]); } pll get(ll l, ll r, int v = 1, ll tl = 1, ll tr = 1e15) { if(l <= tl && tr <= r) return t[v]; if(l > tr || r < tl) return mp(0, 0); ll tm = tl + tr >> 1; return max(get(l, r, ls[v], tl, tm), get(l, r, rs[v], tm + 1, tr)); } void solve() { cin >> n; for(int i = 1; i <= n; ++i) cin >> a[i], pref[i] = pref[i - 1] + a[i]; for(int i = 1; i <= n; ++i) { upd(pref[i - 1] * 2 - pref[dp[i - 1].s], mp(dp[i - 1].f, i - 1)); dp[i] = get(0, pref[i]); dp[i].f++; } cout << dp[n].f; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; ///cin >> T; while(T--) solve(), cout << '\n'; return 0; }

Compilation message (stderr)

segments.cpp: In function 'void upd(long long int, std::pair<long long int, long long int>, int, long long int, long long int)':
segments.cpp:40:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |     ll tm = tl + tr >> 1;
      |             ~~~^~~~
segments.cpp: In function 'std::pair<long long int, long long int> get(long long int, long long int, int, long long int, long long int)':
segments.cpp:54:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   54 |     ll tm = tl + tr >> 1;
      |             ~~~^~~~
#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...