Submission #287958

#TimeUsernameProblemLanguageResultExecution timeMemory
287958dvdg6566Bigger segments (IZhO19_segments)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define f first
#define s second
#define SZ(x) (ll)x.size()
#define ALL(x) x.begin(),x.end()
#define lb lower_bound
#define ub upper_bound
const ll MAXN=500001;
const ll MOD=1e9+7;
const ll INF = 3e9;

ll A[MAXN];
ll N;
ll dp[MAXN];
ll S[MAXN];

struct node{
	node *l,*r;
	pi v;
	node(ll _s,ll _e){
		v=mp(0,0);
		l=r=nullptr;
	}
	pi ask(ll s,ll e,ll x,ll y){
		ll m=(s+e)/2;
		assert(s<=x&&y<=e);
		if(s==x&&e==y)return v;
		pi t=mp(0,0);
		if(l&&x<=m)t=max(t, l->ask(s,m,x,min(y,m)));
		if(r&&y>m)t=max(t,r->ask(m+1,e,max(m+1,x),y));
		return t;
	}
	void up(ll s,ll e,ll x,pi va){
		assert(s<=x&&x<=e);
		if(s==e){v=max(v,va);return;}
		if(x<=m){
			if(!l)l=new node();
			l->up(s,m,x,va);
		}else{
			if(!r)r=new node();
			r->up(m+1,e,x,va);
		}
		v=mp(0,0);
		if(l)v=max(v,l->v);
		if(r)v=max(v,r->v);
	}
}*root;

int main(){
	cin>>N;
	for(int i=1;i<=N;++i){
		cin>>A[i];
		A[i]+=A[i-1];
	}
	root=new node(0,2*A[N]);
	root->up(0,mp(0,0));
	for(int i=1;i<=N;++i){
		pi x=root->ask(0,2*A[N],0,A[i]);
		ll p=x.s;
		dp[i]=x.f+1;
		root->up(0,2*A[N],2*A[i]-A[p], mp(dp[i],i));
	}
	cout<<dp[N];
}

Compilation message (stderr)

segments.cpp: In member function 'void node::up(ll, ll, ll, pi)':
segments.cpp:44:9: error: 'm' was not declared in this scope
   44 |   if(x<=m){
      |         ^
segments.cpp:45:21: error: no matching function for call to 'node::node()'
   45 |    if(!l)l=new node();
      |                     ^
segments.cpp:28:2: note: candidate: 'node::node(ll, ll)'
   28 |  node(ll _s,ll _e){
      |  ^~~~
segments.cpp:28:2: note:   candidate expects 2 arguments, 0 provided
segments.cpp:25:8: note: candidate: 'constexpr node::node(const node&)'
   25 | struct node{
      |        ^~~~
segments.cpp:25:8: note:   candidate expects 1 argument, 0 provided
segments.cpp:25:8: note: candidate: 'constexpr node::node(node&&)'
segments.cpp:25:8: note:   candidate expects 1 argument, 0 provided
segments.cpp:48:21: error: no matching function for call to 'node::node()'
   48 |    if(!r)r=new node();
      |                     ^
segments.cpp:28:2: note: candidate: 'node::node(ll, ll)'
   28 |  node(ll _s,ll _e){
      |  ^~~~
segments.cpp:28:2: note:   candidate expects 2 arguments, 0 provided
segments.cpp:25:8: note: candidate: 'constexpr node::node(const node&)'
   25 | struct node{
      |        ^~~~
segments.cpp:25:8: note:   candidate expects 1 argument, 0 provided
segments.cpp:25:8: note: candidate: 'constexpr node::node(node&&)'
segments.cpp:25:8: note:   candidate expects 1 argument, 0 provided
segments.cpp: In function 'int main()':
segments.cpp:64:20: error: no matching function for call to 'node::up(int, std::pair<int, int>)'
   64 |  root->up(0,mp(0,0));
      |                    ^
segments.cpp:41:7: note: candidate: 'void node::up(ll, ll, ll, pi)'
   41 |  void up(ll s,ll e,ll x,pi va){
      |       ^~
segments.cpp:41:7: note:   candidate expects 4 arguments, 2 provided