제출 #270391

#제출 시각아이디문제언어결과실행 시간메모리
270391anubhavdhar수열 (APIO14_sequence)C++14
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define pll pair<ll, ll> #define ff first #define ss second #define vi vector<int> #define vl vector<ll> #define vii vector<pii> #define vll vector<pll> #define FOR(i,N) for(i=0;i<(N);++i) #define FORe(i,N) for(i=1;i<=(N);++i) #define FORr(i,a,b) for(i=(a);i<(b);++i) #define FORrev(i,N) for(i=(N);i>=0;--i) #define F0R(i,N) for(int i=0;i<(N);++i) #define F0Re(i,N) for(int i=1;i<=(N);++i) #define F0Rr(i,a,b) for(ll i=(a);i<(b);++i) #define F0Rrev(i,N) for(int i=(N);i>=0;--i) #define all(v) (v).begin(),(v).end() #define dbgLine cerr<<" LINE : "<<__LINE__<<"\n" #define ldd long double using namespace std; const int Alp = 26; const int __PRECISION = 9; const int inf = 1e9 + 8; const ldd PI = acos(-1); const ldd EPS = 1e-7; const ll MOD = 1e9 + 7; const ll MAXN = 1e5 + 5; const ll ROOTN = 320; const ll LOGN = 18; const ll INF = 1e18 + 1022; ll dp[MAXN][201], pre[MAXN], par[MAXN][201]; int N, K; struct line //mx + c { mutable ll m, c, p, ind; bool operator < (const line& o) const {return m < o.m;} bool operator < (ll x) const {return p < x;} }; struct CHT_black_box : set<line, less<>> { int mode; CHT_black_box(){mode = 1;} void set_mode(string S) {mode = (S[1] == 'i' || S[1] == 'I') ? -1 : 1;} 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->m == y->m) x->p = (x->c > y->c) ? INF : -INF; else x->p = div((y->c - x->c),(x->m - y->m)); return (x->p >= y->p); } void add(ll slope, ll intercept, ll id) { auto z = insert({mode * slope, mode * intercept, 0, id}), 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)); } pll query(ll x) { assert(!empty()); auto l = *lower_bound(x); return mp (mode * (l.m * x + l.c), l.ind); } }box[201]; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll p, q = INF; assert(N < MAXN); cin>>N>>K; pre[0] = 0; F0Re(i, N) cin>>p, pre[i] = p + pre[i-1]; p = 0; // F0Re(i, N) // cout<<pre[i]<<' '; // cout<<endl; F0R(i, N+1) F0R(j, K+1) dp[i][j] = par[i][j] = 0; // F0Rr(k, j-1, i) dp[i][j] = max(dp[k][j-1] + pre[N]*pre[i] - pre[i]*pre[i] - pre[N]*pre[k] + pre[i]*pre[k]), dp[i][j]); F0Re(i, N) { F0Re(j, min(i, K)) { if(j == 1) dp[i][j] = pre[i]*(pre[N] - pre[i]); else {pll v = box[j-1].query(pre[i]); dp[i][j] = pre[N]*pre[i] - pre[i]*pre[i] + v.ff; par[i][j] = v.ss;} // p = max(p, dp[i][j]); } if(i >= K) p = max(p, dp[i][K]); F0Re(j,min(i, K)) box[j].add(pre[i], dp[i][j] - pre[i] * pre[N], i); } cout<<p<<'\n'; F0Re(i, N) if(dp[i][K] == p) { q = i; break; } while(q and K) { cout<<q<<' '; q = par[q][K--]; } return 0; }

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

sequence.cpp: In member function 'void CHT_black_box::add(long long int, long long int, long long int)':
sequence.cpp:66:66: error: no 'operator++(int)' declared for postfix '++' [-fpermissive]
   66 |   auto z = insert({mode * slope, mode * intercept, 0, id}), y = z++, x = y;
      |                                                                 ~^~
sequence.cpp:66:3: error: inconsistent deduction for 'auto': 'std::pair<std::_Rb_tree_const_iterator<line>, bool>' and then '<type error>'
   66 |   auto z = insert({mode * slope, mode * intercept, 0, id}), y = z++, x = y;
      |   ^~~~
sequence.cpp:67:33: error: no matching function for call to 'CHT_black_box::erase(std::pair<std::_Rb_tree_const_iterator<line>, bool>&)'
   67 |   while(isect(y, z)) z = erase(z);
      |                                 ^
In file included from /usr/include/c++/9/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:87,
                 from sequence.cpp:1:
/usr/include/c++/9/bits/stl_set.h:654:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::erase(std::set<_Key, _Compare, _Alloc>::const_iterator) [with _Key = line; _Compare = std::less<void>; _Alloc = std::allocator<line>; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<line>; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<line>]'
  654 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/9/bits/stl_set.h:654:28: note:   no known conversion for argument 1 from 'std::pair<std::_Rb_tree_const_iterator<line>, bool>' to 'std::set<line, std::less<void> >::const_iterator' {aka 'std::_Rb_tree_const_iterator<line>'}
  654 |       erase(const_iterator __position)
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/9/bits/stl_set.h:684:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::erase(const key_type&) [with _Key = line; _Compare = std::less<void>; _Alloc = std::allocator<line>; std::set<_Key, _Compare, _Alloc>::size_type = long unsigned int; std::set<_Key, _Compare, _Alloc>::key_type = line]'
  684 |       erase(const key_type& __x)
      |       ^~~~~
/usr/include/c++/9/bits/stl_set.h:684:29: note:   no known conversion for argument 1 from 'std::pair<std::_Rb_tree_const_iterator<line>, bool>' to 'const key_type&' {aka 'const line&'}
  684 |       erase(const key_type& __x)
      |             ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_set.h:706:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::erase(std::set<_Key, _Compare, _Alloc>::const_iterator, std::set<_Key, _Compare, _Alloc>::const_iterator) [with _Key = line; _Compare = std::less<void>; _Alloc = std::allocator<line>; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<line>; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<line>]'
  706 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/9/bits/stl_set.h:706:7: note:   candidate expects 2 arguments, 1 provided
sequence.cpp:68:6: error: 'x' was not declared in this scope
   68 |   if(x != begin() && isect(--x, y)) isect(x, y = erase(y));
      |      ^
sequence.cpp:69:12: error: 'x' was not declared in this scope
   69 |   while((y=x) != begin() && (--x)->p >= y->p) isect(x, erase(y));
      |            ^