제출 #1269461

#제출 시각아이디문제언어결과실행 시간메모리
1269461rayan_bd수열 (APIO14_sequence)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; const int mxN = 1e5 + 2; const int mxK = 202; #define ll long long #define ll inf = -1e18; 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; }

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp:9: warning: "ll" redefined
    9 | #define ll inf = -1e18;
      | 
sequence.cpp:7: note: this is the location of the previous definition
    7 | #define ll long long
      | 
sequence.cpp:9:12: error: 'inf' was not declared in this scope; did you mean 'ynf'?
    9 | #define ll inf = -1e18;
      |            ^~~
sequence.cpp:11:6: note: in expansion of macro 'll'
   11 | pair<ll, int> dp[mxN][mxK];
      |      ^~
sequence.cpp:9:19: error: wrong number of template arguments (1, should be 2)
    9 | #define ll inf = -1e18;
      |                   ^~~~
sequence.cpp:11:6: note: in expansion of macro 'll'
   11 | pair<ll, int> dp[mxN][mxK];
      |      ^~
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:187:12: note: provided for 'template<class _T1, class _T2> struct std::pair'
  187 |     struct pair
      |            ^~~~
sequence.cpp:11:8: error: expected unqualified-id before ',' token
   11 | pair<ll, int> dp[mxN][mxK];
      |        ^
sequence.cpp:11:10: error: expected unqualified-id before 'int'
   11 | pair<ll, int> dp[mxN][mxK];
      |          ^~~
sequence.cpp:9:12: error: 'inf' does not name a type; did you mean 'int'?
    9 | #define ll inf = -1e18;
      |            ^~~
sequence.cpp:12:1: note: in expansion of macro 'll'
   12 | ll pref[mxN];
      | ^~
sequence.cpp:12:4: error: 'pref' does not name a type
   12 | ll pref[mxN];
      |    ^~~~
sequence.cpp:9:12: error: 'inf' does not name a type; did you mean 'int'?
    9 | #define ll inf = -1e18;
      |            ^~~
sequence.cpp:15:13: note: in expansion of macro 'll'
   15 |     mutable ll k, m, p, idx;
      |             ^~
sequence.cpp:15:16: error: 'k' does not name a type
   15 |     mutable ll k, m, p, idx;
      |                ^
sequence.cpp: In member function 'bool Line::operator<(const Line&) const':
sequence.cpp:16:56: error: 'const struct Line' has no member named 'k'
   16 |     bool operator<(const Line& o) const { return k < o.k; }
      |                                                        ^
sequence.cpp:16:56: error: 'const struct Line' has no member named 'k'
sequence.cpp:16:56: error: 'const struct Line' has no member named 'k'
sequence.cpp:16:56: error: 'const struct Line' has no member named 'k'
sequence.cpp:16:56: error: 'const struct Line' has no member named 'k'
sequence.cpp:16:50: error: 'k' was not declared in this scope
   16 |     bool operator<(const Line& o) const { return k < o.k; }
      |                                                  ^
sequence.cpp:16:56: error: 'const struct Line' has no member named 'k'
   16 |     bool operator<(const Line& o) const { return k < o.k; }
      |                                                        ^
sequence.cpp: In member function 'bool Line::operator<(int) const':
sequence.cpp:17:42: error: 'p' was not declared in this scope
   17 |     bool operator<(int x) const { return p < x; }
      |                                          ^
sequence.cpp: At global scope:
sequence.cpp:9:12: error: 'inf' does not name a type; did you mean 'int'?
    9 | #define ll inf = -1e18;
      |            ^~~
sequence.cpp:21:18: note: in expansion of macro 'll'
   21 |     static const ll inf = LLONG_MAX;
      |                  ^~
sequence.cpp:21:21: error: 'inf' does not name a type; did you mean 'int'?
   21 |     static const ll inf = LLONG_MAX;
      |                     ^~~
      |                     int
sequence.cpp:9:12: error: 'inf' does not name a type; did you mean 'int'?
    9 | #define ll inf = -1e18;
      |            ^~~
sequence.cpp:22:5: note: in expansion of macro 'll'
   22 |     ll div(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
      |     ^~
sequence.cpp:9:12: error: 'inf' has not been declared
    9 | #define ll inf = -1e18;
      |            ^~~
sequence.cpp:22:12: note: in expansion of macro 'll'
   22 |     ll div(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
      |            ^~
sequence.cpp:9:23: error: expected ')' before ';' token
    9 | #define ll inf = -1e18;
      |                       ^
sequence.cpp:22:12: note: in expansion of macro 'll'
   22 |     ll div(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
      |            ^~
sequence.cpp:22:11: note: to match this '('
   22 |     ll div(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
      |           ^
sequence.cpp:22:8: error: ISO C++ forbids declaration of 'div' with no type [-fpermissive]
   22 |     ll div(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
      |        ^~~
sequence.cpp:22:15: error: 'a' does not name a type
   22 |     ll div(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
      |               ^
sequence.cpp:22:21: error: 'b' does not name a type
   22 |     ll div(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
      |                     ^
sequence.cpp:9:12: error: 'inf' has not been declared
    9 | #define ll inf = -1e18;
      |            ^~~
sequence.cpp:29:14: note: in expansion of macro 'll'
   29 |     void add(ll k, ll m, int idx) {
      |              ^~
sequence.cpp:9:23: error: expected ')' before ';' token
    9 | #define ll inf = -1e18;
      |                       ^
sequence.cpp:29:14: note: in expansion of macro 'll'
   29 |     void add(ll k, ll m, int idx) {
      |              ^~
sequence.cpp:29:13: note: to match this '('
   29 |     void add(ll k, ll m, int idx) {
      |             ^
sequence.cpp:29:17: error: 'k' does not name a type
   29 |     void add(ll k, ll m, int idx) {
      |                 ^
sequence.cpp:29:23: error: 'm' does not name a type; did you mean 'tm'?
   29 |     void add(ll k, ll m, int idx) {
      |                       ^
      |                       tm
sequence.cpp:9:12: error: 'inf' was not declared in this scope; did you mean 'ynf'?
    9 | #define ll inf = -1e18;
      |            ^~~
sequence.cpp:36:10: note: in expansion of macro 'll'
   36 |     pair<ll, int> query(ll x) {
      |          ^~
sequence.cpp:9:19: error: wrong number of template arguments (1, should be 2)
    9 | #define ll inf = -1e18;
      |                   ^~~~
sequence.cpp:36:10: note: in expansion of macro 'll'
   36 |     pair<ll, int> query(ll x) {
      |          ^~
/usr/include/c++/13/bits/stl_pair.h:187:12: note: provided for 'template<class _T1, class _T2> struct std::pair'
  187 |     struct pair
      |            ^~~~
sequence.cpp:36:12: error: expected unqualified-id before ',' token
   36 |     pair<ll, int> query(ll x) {
      |            ^
sequence.cpp:36:28: error: 'x' does not name a type
   36 |     pair<ll, int> query(ll x) {
      |                            ^
sequence.cpp:9:18: warning: overflow in conversion from 'double' to 'int' changes value from '-1.0e+18' to '-2147483648' [-Woverflow]
    9 | #define ll inf = -1e18;
      |                  ^~~~~
sequence.cpp:22:12: note: in expansion of macro 'll'
   22 |     ll div(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
      |            ^~
sequence.cpp:9:18: warning: overflow in conversion from 'double' to 'int' changes value from '-1.0e+18' to '-2147483648' [-Woverflow]
    9 | #define ll inf = -1e18;
      |                  ^~~~~
sequence.cpp:29:14: note: in expansion of macro 'll'
   29 |     void add(ll k, ll m, int idx) {
      |              ^~
sequence.cpp: In member function 'bool LineContainer::isect(std::multiset<Line, std::less<void> >::iterator, std::multiset<Line, std::less<void> >::iterator)':
sequence.cpp:24:30: error: 'const struct Line' has no member named 'p'
   24 |         if (y == end()) { x->p = inf; return false; }
      |                              ^
sequence.cpp:24:34: error: 'inf' was not declared in this scope; did you mean 'ynf'?
   24 |         if (y == end()) { x->p = inf; return false; }
      |                                  ^~~
      |                                  ynf
sequence.cpp:25:16: error: 'const struct Line' has no member named 'k'
   25 |         if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
      |                ^
sequence.cpp:25:24: error: 'const struct Line' has no member named 'k'
   25 |         if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
      |                        ^
sequence.cpp:25:30: error: 'const struct Line' has no member named 'p'
   25 |         if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
      |                              ^
sequence.cpp:25:37: error: 'const struct Line' has no member named 'm'
   25 |         if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
      |                                     ^
sequence.cpp:25:44: error: 'const struct Line' has no member named 'm'
   25 |         if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
      |                                            ^
sequence.cpp:25:48: error: 'inf' was not declared in this scope; did you mean 'ynf'?
   25 |         if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
      |                                                ^~~
      |                                                ynf
sequence.cpp:26:17: error: 'const struct Line' has no member named 'p'
   26 |         else x->p = div(y->m - x->m, x->k - y->k);
      |                 ^
sequence.cpp:26:28: error: 'const struct Line' has no member named 'm'
   26 |         else x->p = div(y->m - x->m, x->k - y->k);
      |                            ^
sequence.cpp:26:35: error: 'const struct Line' has no member named 'm'
   26 |         else x->p = div(y->m - x->m, x->k - y->k);
      |                                   ^
sequence.cpp:26:41: error: 'const struct Line' has no member named 'k'
   26 |         else x->p = div(y->m - x->m, x->k - y->k);
      |                                         ^
sequence.cpp:26:48: error: 'const struct Line' has no member named 'k'
   26 |         else x->p = div(y->m - x->m, x->k - y->k);
      |                                                ^
sequence.cpp:27:19: error: 'const struct Line' has no member named 'p'
   27 |         return x->p >= y->p;
      |                   ^
sequence.cpp:27:27: error: 'const struct Line' has no member named 'p'
   27 |         return x->p >= y->p;
      |                           ^
sequence.cpp: In function 'int main()':
sequence.cpp:52:16: error: 'pref' was not declared in this scope
   52 |         cin >> pref[i];
      |                ^~~~
sequence.cpp:58:13: error: 'dp' was not declared in this scope; did you mean 'dup'?
   58 |             dp[i][j] = {inf, 0};
      |             ^~
      |             dup
sequence.cpp:58:25: error: 'inf' was not declared in this scope; did you mean 'ynf'?
   58 |             dp[i][j] = {inf, 0};
      |                         ^~~
      |                         ynf
sequence.cpp:62:38: error: 'dp' was not declared in this scope; did you mean 'dup'?
   62 |     for (int i = 1; i <= n + 1; i++) dp[i][0] = {0,  i};
      |                                      ^~
      |                                      dup
sequence.cpp:67:21: error: 'pref' was not declared in this scope
   67 |             cht.add(pref[j], (long long) dp[j+1][k - 1].first - pref[j] * pref[j], j);
      |                     ^~~~
sequence.cpp:67:42: error: 'dp' was not declared in this scope; did you mean 'dup'?
   67 |             cht.add(pref[j], (long long) dp[j+1][k - 1].first - pref[j] * pref[j], j);
      |                                          ^~
      |                                          dup
sequence.cpp:68:35: error: 'struct LineContainer' has no member named 'query'
   68 |             auto [val, idx] = cht.query((long long) pref[n] + pref[j-1]);
      |                                   ^~~~~
sequence.cpp:73:13: error: 'dp' was not declared in this scope; did you mean 'dup'?
   73 |     cout << dp[1][K].first << "\n";
      |             ^~
      |             dup