Submission #497622

#TimeUsernameProblemLanguageResultExecution timeMemory
497622mansurBigger segments (IZhO19_segments)C++17
13 / 100
4 ms3020 KiB
#include<bits/stdc++.h> #pragma optimize ("g",on) #pragma GCC optimize ("inline") #pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC optimize ("03") #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native") #pragma comment(linker, "/stack:200000000") //01001101 01100001 01101011 01101000 01100001 01100111 01100001 01111001 using namespace std; #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define ll long long #define pb push_back #define sz(a) a.size() #define nl '\n' #define popb pop_back() #define ld double #define ull unsigned long long #define ff first #define ss second #define fix fixed << setprecision #define pii pair<int, int> #define E exit (0) #define int long long const int inf = 1e18, N = 1e6 + 1, mod = 998244353; vector<pii> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; pii dp[N]; struct node{ node *l, *r; int ans, sum; node() { l = r = NULL; ans = 0, sum = 0; } node(node *tl, node *tr) { l = tl, r = tr; if (tl->ans > tr->ans) { ans = tl->ans, sum = tl->sum; }else if (tr->ans > tl->ans) { ans = tr->ans, sum = tr->sum; }else { ans = tl->ans, sum = min(tl->sum, tr->sum); } } }; node* update(node *u, int tl, int tr, int pos, int ans, int sum) { if (tl == tr) { if (u->ans < ans) u->ans = ans; if (u->ans == ans && u->sum < sum) u->sum = sum; return u; } int mid = (tl + tr) / 2; if (!u->l) u->l = new node(); if (!u->r) u->r = new node(); if (pos <= mid) { return new node(update(u->l, tl, mid, pos, ans, sum), u->r); }else { return new node(u->l, update(u->r, mid + 1, tr, pos, ans, sum)); } } pii get(node *u, int tl, int tr, int l, int r) { if (tl > r || tr < l) { return {0, 0}; } if (tl >= l && tr <= r) { return {u->ans, u->sum}; } int mid = (tl + tr) / 2; pii a = {0, 0}, b = {0, 0}; if (u->l) a = get(u->l, tl, mid, l, r); if (u->r) b = get(u->r, mid + 1, tr, l, r); if (a.ff > b.ff) return a; if (b.ff > a.ff) return b; return {a.ff, max(a.ss, b.ss)}; } main() { //freopen("cowrect.in", "r", stdin); //freopen("cowrect.out", "w", stdout); ios_base::sync_with_stdio(NULL); cin.tie(NULL); int n; cin >> n; int a[n + 1], pref[n + 1]; pref[0] = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; pref[i] = pref[i - 1] + a[i]; } node *root = new node(); root = update(root, 0, inf, 0, 0, 0); for (int i = 1; i <= n; i++) { dp[i] = get(root, 0, inf, 0, pref[i]); dp[i].ff++; dp[i].ss = pref[i] - pref[dp[i].ss]; root = update(root, 0, inf, dp[i].ss + pref[i], dp[i].ff, i); } cout << dp[n].ff; }

Compilation message (stderr)

segments.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    3 | #pragma optimize ("g",on)
      | 
segments.cpp:9: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    9 | #pragma comment(linker, "/stack:200000000")
      | 
segments.cpp:88:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   88 | main() {
      | ^~~~
#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...