Submission #369943

#TimeUsernameProblemLanguageResultExecution timeMemory
369943EIMONIMSplit the sequence (APIO14_sequence)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define pb push_back #define all(x) x.begin(),x.end() using namespace std; #define int int64_t #define ii pair<int,int> #define x first #define y second #define vi vector<int> #define vvi vector<vi> #define vii vector<ii> #define vvii vector<vii> #define vb vector<bool> #define vvb vector<vb> #define loop(i,s,e) for(int i=(s);i<(e);i++) #define loopr(i,s,e) for(int i=(e)-1;i>=(s);i--) #define chkmax(a,b) a = max(a,b) #define chkmin(a,b) a=min(a,b) const int INF = 1e18, MOD = 1e9 + 7; /*mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); auto unidist = uniform_int_distribution<int>(0, MAXN);*/ const int N = 2e5; typedef int64_t ll; typedef pair<ll, ll> pll; int n, k, a[N]; ll pre[N], dp[N], cnt[N]; struct CHT { struct Line { ll m, b, c; ll operator()(ll x) { return m * x + b; } } dq[N * 2]; int l, r; void init() { dq[0] = {0, 0, 0}; l = 0, r = 1; } bool better_ins(Line& L, Line& L1, Line& L2) { ll b1 = (L.b - L2.b) * (L2.m - L1.m), b2 = (L2.m - L.m) * (L1.b - L2.b); return b1 < b2 || (b1 == b2 && L.c <= L1.c); } bool better_qry(Line& L1, Line& L2, ll x) { ll b1 = L1(x), b2 = L2(x); return b1 > b2 || (b1 == b2 && L1.c >= L2.c); } void insert(Line L) { while(r - l >= 2 && better_ins(L, dq[r - 1], dq[r - 2])) --r; dq[r++] = L; } pll query(ll x) { while(r - l >= 2 && better_qry(dq[l], dq[l + 1], x)) ++l; return {dq[l](x), dq[l].c}; } } cht; pll calc(ll x) { dp[0] = cnt[0] = 0; cht.init(); for(int i = 1 ; i <= n ; ++i) { pll qry = cht.query(pre[i]); dp[i] = pre[i] * pre[i] + x + qry.F; cnt[i] = qry.S + 1; cht.insert({-2LL * pre[i], dp[i] + pre[i] * pre[i], cnt[i]}); } return {cnt[n], dp[n]}; } void init() { cin >> n >> k; k++; for(int i = 1 ; i <= n ; ++i) cin >> a[i], pre[i] = pre[i - 1] + a[i]; } ll solve() { ll l = 0, r = pre[n] * pre[n], ans = -1; while(l <= r) { ll mid = l + (r - l) / 2; pll res = calc(mid); if(res.F > k) l = mid + 1; else r = mid - 1, ans = res.S - k * mid; } return ans; } int32_t main(){ init(); cout << int(pre[n]*pre[n] - solve())/2 << endl; Orig::n = n, Orig::k = k-1; loop(i,0,n) Orig::a[i+1] = a[i+1]; Orig::calc(); return 0; } /* color a cls g++ seq.cpp -o a & a 7 3 4 1 3 4 0 2 3 for /l %x in (1,1,16) do a < out\big%x.in > out\big%x.out */

Compilation message (stderr)

sequence.cpp: In function 'pll calc(ll)':
sequence.cpp:66:39: error: 'pll' {aka 'struct std::pair<long int, long int>'} has no member named 'F'
   66 |     dp[i] = pre[i] * pre[i] + x + qry.F;
      |                                       ^
sequence.cpp:67:18: error: 'pll' {aka 'struct std::pair<long int, long int>'} has no member named 'S'
   67 |     cnt[i] = qry.S + 1;
      |                  ^
sequence.cpp: In function 'll solve()':
sequence.cpp:82:12: error: 'pll' {aka 'struct std::pair<long int, long int>'} has no member named 'F'
   82 |     if(res.F > k) l = mid + 1;
      |            ^
sequence.cpp:83:33: error: 'pll' {aka 'struct std::pair<long int, long int>'} has no member named 'S'
   83 |     else r = mid - 1, ans = res.S - k * mid;
      |                                 ^
sequence.cpp: In function 'int32_t main()':
sequence.cpp:90:5: error: 'Orig' has not been declared
   90 |     Orig::n = n, Orig::k = k-1;
      |     ^~~~
sequence.cpp:90:18: error: 'Orig' has not been declared
   90 |     Orig::n = n, Orig::k = k-1;
      |                  ^~~~
sequence.cpp:91:17: error: 'Orig' has not been declared
   91 |     loop(i,0,n) Orig::a[i+1] = a[i+1];
      |                 ^~~~
sequence.cpp:92:5: error: 'Orig' has not been declared
   92 |     Orig::calc();
      |     ^~~~