#include "happiness.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e9+1)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}#include "happiness.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e9+1)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
struct node{
ll lf,rg,sum;
node *l,*r;
node(ll _lf,ll _rg){
l = nullptr;
r = nullptr;
sum = 0;
lf = _lf;
rg = _rg;
}
void upd(ll val,ll c){
sum+=val*c;
if(lf==rg)return;
int tm = (lf+rg)/2;
if(val<=tm){
if(l == nullptr)l = new node(lf,tm);
l->upd(val,c);
}else{
if(r == nullptr)r = new node(tm+1,rg);
r->upd(val,c);
}
}
ll query(int L,int R){
if(lf == L && R == rg)return sum;
int tm = (lf+rg)/2;
if(R<=tm){
if(l==nullptr)l = new node(lf,tm);
return l->query(L,R);
}
else if(L>tm){
if(r==nullptr)r = new node(tm+1,rg);
return r->query(L,R);
}else{
if(l==nullptr)l = new node(lf,tm);
if(r==nullptr)r = new node(tm+1,rg);
return l->query(L,tm) + r->query(tm+1,R);
}
}
};
ll m = 0;
node *root;
bool check(){
ll cur = 1,mx = min(root->sum;
while(cur<mx){
ll t = root->query(1,cur);
if(cur>t)return false;
cur = t+1;
}
return true;
}
bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
root = new node(1,1e12);
for(int i=0;i<coinsCount;i++)root->upd(coins[i],1);
return check();
}
bool is_happy(int event, int coinsCount, long long coins[]) {
for(int i=0;i<coinsCount;i++)root->upd(coins[i],event);
return check();
}
struct node{
ll lf,rg,sum;
node *l,*r;
node(ll _lf,ll _rg){
l = nullptr;
r = nullptr;
sum = 0;
lf = _lf;
rg = _rg;
}
void upd(ll val,ll c){
sum+=val*c;
if(lf==rg)return;
int tm = (lf+rg)/2;
if(val<=tm){
if(l == nullptr)l = new node(lf,tm);
l->upd(val,c);
}else{
if(r == nullptr)r = new node(tm+1,rg);
r->upd(val,c);
}
}
ll query(int L,int R){
if(lf == L && R == rg)return sum;
int tm = (lf+rg)/2;
if(R<=tm){
if(l==nullptr)l = new node(lf,tm);
return l->query(L,R);
}
else if(L>tm){
if(r==nullptr)r = new node(tm+1,rg);
return r->query(L,R);
}else{
if(l==nullptr)l = new node(lf,tm);
if(r==nullptr)r = new node(tm+1,rg);
return l->query(L,tm) + r->query(tm+1,R);
}
}
};
node *root;
bool check(){
ll cur = 1,mx = root->sum;
while(cur<mx){
ll t = root->query(1,cur);
if(cur>t)return false;
cur = t+1;
}
return true;
}
bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
root = new node(1,maxCoinSize);
for(int i=0;i<coinsCount;i++)root->upd(coins[i],1);
return check();
}
bool is_happy(int event, int coinsCount, long long coins[]) {
for(int i=0;i<coinsCount;i++)root->upd(coins[i],event);
return check();
}
Compilation message
happiness.cpp:23:58: error: stray '#' in program
23 | ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}#include "happiness.h"
| ^
happiness.cpp:23:59: error: 'include' does not name a type
23 | ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}#include "happiness.h"
| ^~~~~~~
happiness.cpp:45:4: error: redefinition of 'll gcd(ll, ll)'
45 | ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
| ^~~
happiness.cpp:23:4: note: 'll gcd(ll, ll)' previously defined here
23 | ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}#include "happiness.h"
| ^~~
happiness.cpp: In function 'bool check()':
happiness.cpp:89:31: error: expected ')' before ';' token
89 | ll cur = 1,mx = min(root->sum;
| ~ ^
| )
happiness.cpp: At global scope:
happiness.cpp:107:8: error: redefinition of 'struct node'
107 | struct node{
| ^~~~
happiness.cpp:46:8: note: previous definition of 'struct node'
46 | struct node{
| ^~~~
happiness.cpp:147:7: error: redefinition of 'node* root'
147 | node *root;
| ^~~~
happiness.cpp:87:7: note: 'node* root' previously declared here
87 | node *root;
| ^~~~
happiness.cpp:148:6: error: redefinition of 'bool check()'
148 | bool check(){
| ^~~~~
happiness.cpp:88:6: note: 'bool check()' previously defined here
88 | bool check(){
| ^~~~~
happiness.cpp:157:6: error: redefinition of 'bool init(int, long long int, long long int*)'
157 | bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
| ^~~~
happiness.cpp:97:6: note: 'bool init(int, long long int, long long int*)' previously defined here
97 | bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
| ^~~~
happiness.cpp:162:6: error: redefinition of 'bool is_happy(int, int, long long int*)'
162 | bool is_happy(int event, int coinsCount, long long coins[]) {
| ^~~~~~~~
happiness.cpp:102:6: note: 'bool is_happy(int, int, long long int*)' previously defined here
102 | bool is_happy(int event, int coinsCount, long long coins[]) {
| ^~~~~~~~
grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
16 | long long max_code;
| ^~~~~~~~