Submission #270133

#TimeUsernameProblemLanguageResultExecution timeMemory
270133anubhavdharSplit the sequence (APIO14_sequence)C++11
Compilation error
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  
{
	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
{
	multiset<line, less<>> CHT_box;
	ll div(ll a,ll b) { return a/b - ((a^b) < 0 && a%b);}
	bool isect(multiset<line, less<>> :: iterator x, multiset<line, less<>> :: iterator y)
	{
		if(y == CHT_box.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 sl, ll in, ll i)
	{
		auto z = CHT_box.insert({sl, in, 0, i}), y = z++, x = y;
		while(isect(y, z))	z = CHT_box.erase(z);
		if(x != CHT_box.begin() && isect(--x,y))	isect(x, y = CHT_box.erase(y));
		while((y=x) != CHT_box.begin() && (--x)->p >= y->p)	isect(x,CHT_box.erase(y)); 
	}
	pll query(ll x)
	{
		if(CHT_box.empty()) while(true) cout<<1;
		auto l = *CHT_box.lower_bound(x);
		return mp(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;
}

Compilation message (stderr)

sequence.cpp:53:21: error: wrong number of template arguments (0, should be 1)
   53 |  multiset<line, less<>> CHT_box;
      |                     ^
In file included from /usr/include/c++/9/string:48,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from sequence.cpp:1:
/usr/include/c++/9/bits/stl_function.h:381:12: note: provided for 'template<class _Tp> struct std::less'
  381 |     struct less : public binary_function<_Tp, _Tp, bool>
      |            ^~~~
sequence.cpp:53:22: error: template argument 2 is invalid
   53 |  multiset<line, less<>> CHT_box;
      |                      ^~
sequence.cpp:55:32: error: wrong number of template arguments (0, should be 1)
   55 |  bool isect(multiset<line, less<>> :: iterator x, multiset<line, less<>> :: iterator y)
      |                                ^
In file included from /usr/include/c++/9/string:48,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from sequence.cpp:1:
/usr/include/c++/9/bits/stl_function.h:381:12: note: provided for 'template<class _Tp> struct std::less'
  381 |     struct less : public binary_function<_Tp, _Tp, bool>
      |            ^~~~
sequence.cpp:55:33: error: template argument 2 is invalid
   55 |  bool isect(multiset<line, less<>> :: iterator x, multiset<line, less<>> :: iterator y)
      |                                 ^~
sequence.cpp:55:48: error: expected ',' or '...' before 'x'
   55 |  bool isect(multiset<line, less<>> :: iterator x, multiset<line, less<>> :: iterator y)
      |                                                ^
sequence.cpp: In member function 'bool CHT::isect(int)':
sequence.cpp:57:6: error: 'y' was not declared in this scope
   57 |   if(y == CHT_box.end()) {x->p = INF; return false;}
      |      ^
sequence.cpp:57:19: error: request for member 'end' in '((CHT*)this)->CHT::CHT_box', which is of non-class type 'int'
   57 |   if(y == CHT_box.end()) {x->p = INF; return false;}
      |                   ^~~
sequence.cpp:57:27: error: 'x' was not declared in this scope
   57 |   if(y == CHT_box.end()) {x->p = INF; return false;}
      |                           ^
sequence.cpp:58:6: error: 'x' was not declared in this scope
   58 |   if(x->m == y-> m) x->p = (x->c > y->c ) ? INF: -INF;
      |      ^
sequence.cpp:58:14: error: 'y' was not declared in this scope
   58 |   if(x->m == y-> m) x->p = (x->c > y->c ) ? INF: -INF;
      |              ^
sequence.cpp:60:11: error: 'x' was not declared in this scope
   60 |   return (x->p >= y->p);
      |           ^
sequence.cpp:60:19: error: 'y' was not declared in this scope
   60 |   return (x->p >= y->p);
      |                   ^
sequence.cpp: In member function 'void CHT::add(long long int, long long int, long long int)':
sequence.cpp:64:20: error: request for member 'insert' in '((CHT*)this)->CHT::CHT_box', which is of non-class type 'int'
   64 |   auto z = CHT_box.insert({sl, in, 0, i}), y = z++, x = y;
      |                    ^~~~~~
sequence.cpp:65:15: error: 'y' was not declared in this scope
   65 |   while(isect(y, z)) z = CHT_box.erase(z);
      |               ^
sequence.cpp:65:34: error: request for member 'erase' in '((CHT*)this)->CHT::CHT_box', which is of non-class type 'int'
   65 |   while(isect(y, z)) z = CHT_box.erase(z);
      |                                  ^~~~~
sequence.cpp:66:6: error: 'x' was not declared in this scope
   66 |   if(x != CHT_box.begin() && isect(--x,y)) isect(x, y = CHT_box.erase(y));
      |      ^
sequence.cpp:66:19: error: request for member 'begin' in '((CHT*)this)->CHT::CHT_box', which is of non-class type 'int'
   66 |   if(x != CHT_box.begin() && isect(--x,y)) isect(x, y = CHT_box.erase(y));
      |                   ^~~~~
sequence.cpp:66:40: error: 'y' was not declared in this scope
   66 |   if(x != CHT_box.begin() && isect(--x,y)) isect(x, y = CHT_box.erase(y));
      |                                        ^
sequence.cpp:66:65: error: request for member 'erase' in '((CHT*)this)->CHT::CHT_box', which is of non-class type 'int'
   66 |   if(x != CHT_box.begin() && isect(--x,y)) isect(x, y = CHT_box.erase(y));
      |                                                                 ^~~~~
sequence.cpp:67:10: error: 'y' was not declared in this scope
   67 |   while((y=x) != CHT_box.begin() && (--x)->p >= y->p) isect(x,CHT_box.erase(y));
      |          ^
sequence.cpp:67:12: error: 'x' was not declared in this scope
   67 |   while((y=x) != CHT_box.begin() && (--x)->p >= y->p) isect(x,CHT_box.erase(y));
      |            ^
sequence.cpp:67:26: error: request for member 'begin' in '((CHT*)this)->CHT::CHT_box', which is of non-class type 'int'
   67 |   while((y=x) != CHT_box.begin() && (--x)->p >= y->p) isect(x,CHT_box.erase(y));
      |                          ^~~~~
sequence.cpp:67:71: error: request for member 'erase' in '((CHT*)this)->CHT::CHT_box', which is of non-class type 'int'
   67 |   while((y=x) != CHT_box.begin() && (--x)->p >= y->p) isect(x,CHT_box.erase(y));
      |                                                                       ^~~~~
sequence.cpp: In member function 'std::pair<long long int, long long int> CHT::query(long long int)':
sequence.cpp:71:14: error: request for member 'empty' in '((CHT*)this)->CHT::CHT_box', which is of non-class type 'int'
   71 |   if(CHT_box.empty()) while(true) cout<<1;
      |              ^~~~~
sequence.cpp:72:21: error: request for member 'lower_bound' in '((CHT*)this)->CHT::CHT_box', which is of non-class type 'int'
   72 |   auto l = *CHT_box.lower_bound(x);
      |                     ^~~~~~~~~~~