Submission #343956

# Submission time Handle Problem Language Result Execution time Memory
343956 2021-01-04T22:17:56 Z ogibogi2004 Happiness (Balkan15_HAPPINESS) C++14
Compilation error
0 ms 0 KB
#include "happiness.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAXM=1e7;
const ll INF=2e17;
const ll MAXN=2e12;
struct node
{
	ll val;
	ll pl,pr;
	node()
	{
		val=0;pl=-1;pr=-1;
	}
};
node tree[MAXM];
ll sz=1;
void update(ll idx,ll l,ll r,ll q,ll val)
{
	if(l>q||r<q)return;
	if(l==r)
	{
		tree[idx].val+=val;
		return;
	}
	ll mid=(l+r)/2;
	if(mid<q)
	{
		if(tree[idx].pr==-1)
		{
			tree[idx].pr=++sz;
		}
		update(tree[idx].pr,mid+1,r,q,val);
	}
	else
	{
		if(tree[idx].pl==-1)
		{
			tree[idx].pl=++sz;
		}
		update(tree[idx].pl,l,mid,q,val);
	}
	tree[idx].val=0;
	if(tree[idx].pl!=-1)tree[idx].val+=tree[tree[idx].pl].val;
	if(tree[idx].pr!=-1)tree[idx].val+=tree[tree[idx].pr].val;
}
ll query(ll idx,ll l,ll r,ll ql,ll qr)
{
	if(l>qr||r<ql)return 0;
	if(l>=ql&&r<=qr)
	{
		return tree[idx].val;
	}
	ll mid=(l+r)/2;
	ll ret=0;
	if(tree[idx].pl!=-1)
	{
		ret+=query(tree[idx].pl,l,mid,ql,qr);
	}
	if(tree[idx].pr!=-1)
	{
		ret+=query(tree[idx].pr,mid+1,r,ql,qr);
	}
	return ret;
}
bool check()
{
	ll csum=1;
	while(csum<tree[1].val)
	{
		ll t=query(1,1,MAXN,1,csum);
		if(t<csum)return 0;
		csum=t+1;
	}
	return 1;
}
bool init(ll coinsCount, long long maxCoinSize, long long coins[]) {
	for(ll i=0;i<coinsCount;i++)
	{
		update(1,1,MAXN,coins[i],coins[i]);
	}
	return check();
}
bool is_happy(ll event, ll coinsCount, long long coins[]) {
	
	if(event==1)
	{
		for(ll i=0;i<coinsCount;i++)
		{
			update(1,1,MAXN,coins[i],coins[i]);
		}
	}
	else
	{
		for(ll i=0;i<coinsCount;i++)
		{
			update(1,1,MAXN,coins[i],-coins[i]);
		}
	}
	return check();
}

Compilation message

grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
   16 |  long long max_code;
      |            ^~~~~~~~
/tmp/cc8BVxeQ.o: In function `main':
grader.cpp:(.text.startup+0x96): undefined reference to `init(int, long long, long long*)'
grader.cpp:(.text.startup+0x160): undefined reference to `is_happy(int, int, long long*)'
collect2: error: ld returned 1 exit status