Submission #1269460

#TimeUsernameProblemLanguageResultExecution timeMemory
1269460rayan_bdSplit the sequence (APIO14_sequence)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; const int mxN = 1e5 + 2; const int mxK = 202; #define ll long long pair<ll, int> dp[mxN][mxK]; ll pref[mxN]; struct Line { mutable ll k, m, p, idx; bool operator<(const Line& o) const { return k < o.k; } bool operator<(int x) const { return p < x; } }; struct LineContainer : multiset<Line, less<>> { static const ll inf = LLONG_MAX; ll div(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); } bool isect(iterator x, iterator y) { if (y == end()) { x->p = inf; return false; } if (x->k == y->k) x->p = x->m > y->m ? inf : -inf; else x->p = div(y->m - x->m, x->k - y->k); return x->p >= y->p; } void add(ll k, ll m, int idx) { auto z = insert({k, m, 0, idx}), y = z++, x = y; while (isect(y, z)) z = erase(z); if (x != begin() && isect(--x, y)) isect(x, y = erase(y)); while ((y = x) != begin() && (--x)->p >= y->p) isect(x, erase(y)); } pair<ll, int> query(ll x) { assert(!empty()); auto l = *lower_bound(x); return {l.k * x + l.m, l.idx}; } } cht; signed main(){ ios_base::sync_with_stdio(0); cin.tie(nullptr); int n, K; cin >> n >> K; for(int i = 1; i <= n; ++i){ cin >> pref[i]; pref[i] += pref[i - 1]; } for(int i = 0; i <= n + 1; ++i){ for(int j = 0; j <= K; ++j){ dp[i][j] = {inf, 0}; } } for (int i = 1; i <= n + 1; i++) dp[i][0] = {0, i}; for (int k = 1; k <= K; k++) { cht.clear(); for (int j = n; j >= 1; j--) { cht.add(pref[j], (long long) dp[j+1][k - 1].first - pref[j] * pref[j], j); auto [val, idx] = cht.query((long long) pref[n] + pref[j-1]); dp[j][k] = {(long long) -pref[j-1] * pref[n] + val, idx}; } } cout << dp[1][K].first << "\n"; int i = 1; while (K > 0 && i <= n) { int j = dp[i][K].second; if (j == -1) break; cout << j << " "; i = j + 1; K--; } cout << "\n"; return 0; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:56:25: error: 'inf' was not declared in this scope; did you mean 'ynf'?
   56 |             dp[i][j] = {inf, 0};
      |                         ^~~
      |                         ynf
sequence.cpp:56:31: error: no match for 'operator=' (operand types are 'std::pair<long long int, int>' and '<brace-enclosed initializer list>')
   56 |             dp[i][j] = {inf, 0};
      |                               ^
In file included from /usr/include/c++/13/bits/stl_algobase.h:64,
                 from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from sequence.cpp:1:
/usr/include/c++/13/bits/stl_pair.h:439:9: note: candidate: 'template<class _U1, class _U2> constexpr std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) requires  _S_assignable<const _U1&, const _U2&>() [with _U2 = _U1; _T1 = long long int; _T2 = int]'
  439 |         operator=(const pair<_U1, _U2>& __p)
      |         ^~~~~~~~
/usr/include/c++/13/bits/stl_pair.h:439:9: note:   template argument deduction/substitution failed:
sequence.cpp:56:31: note:   couldn't deduce template parameter '_U1'
   56 |             dp[i][j] = {inf, 0};
      |                               ^
/usr/include/c++/13/bits/stl_pair.h:451:9: note: candidate: 'template<class _U1, class _U2> constexpr std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) requires  _S_assignable<_U1, _U2>() [with _U2 = _U1; _T1 = long long int; _T2 = int]'
  451 |         operator=(pair<_U1, _U2>&& __p)
      |         ^~~~~~~~
/usr/include/c++/13/bits/stl_pair.h:451:9: note:   template argument deduction/substitution failed:
sequence.cpp:56:31: note:   couldn't deduce template parameter '_U1'
   56 |             dp[i][j] = {inf, 0};
      |                               ^
/usr/include/c++/13/bits/stl_pair.h:416:7: note: candidate: 'constexpr std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(const std::pair<_T1, _T2>&) requires  _S_assignable<const _T1&, const _T2&>() [with _T1 = long long int; _T2 = int]'
  416 |       operator=(const pair& __p)
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_pair.h:416:29: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::pair<long long int, int>&'
  416 |       operator=(const pair& __p)
      |                 ~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_pair.h:427:7: note: candidate: 'constexpr std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::pair<_T1, _T2>&&) requires  _S_assignable<_T1, _T2>() [with _T1 = long long int; _T2 = int]'
  427 |       operator=(pair&& __p)
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_pair.h:427:24: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::pair<long long int, int>&&'
  427 |       operator=(pair&& __p)
      |                 ~~~~~~~^~~