#include <bits/stdc++.h>
#include "happiness.h"
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
#define f first
#define s second
#define LOGN 21
const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 100;
#define int long long
struct Node {
int l, r;
int sum;
Node *ln, *rn;
Node() : l(-1), r(-1), sum(0), ln(NULL), rn(NULL) { }
Node(int _l, int _r) : l(_l), r(_r), sum(0), ln(NULL), rn(NULL) { }
int query(int a, int b) {
if (r < a || l > b)
return 0;
if (l <= a && b <= r)
return sum;
int res = 0;
if (ln)
res += ln->sum;
if (rn)
res += rn->sum;
return res;
}
void update(int plc, int val) {
sum += val;
if (l != r) {
int mid = (l + r) / 2;
if (plc > mid) {
if (!rn)
rn = new Node(mid + 1, r);
rn->update(plc, val);
} else {
if (!ln)
ln = new Node(l, mid);
ln->update(plc, val);
}
}
}
};
Node *root;
bool solve() {
int now = 1;
while (now < root->sum) {
int t = root->query(1, now);
if (t < now)
return false;
now = t + 1;
}
return true;
}
bool init(int coinsCount, int maxCoinSize, int coins[]) {
root = new Node(1, maxCoinSize);
root->update(1, 1);
for (int i = 0; i < coinsCount; i++)
root->update(coins[i], coins[i]);
return solve();
}
bool is_happy(int event, int coinsCount, int coins[]) {
for (int i = 0; i < coinsCount; i++)
root->update(coins[i], event * coins[i]);
return solve();
}
Compilation message
grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
16 | long long max_code;
| ^~~~~~~~
/usr/bin/ld: /tmp/ccBqnsHh.o: in function `main':
grader.cpp:(.text.startup+0x96): undefined reference to `init(int, long long, long long*)'
/usr/bin/ld: grader.cpp:(.text.startup+0x160): undefined reference to `is_happy(int, int, long long*)'
collect2: error: ld returned 1 exit status