#include "happiness.h"
struct Node {
long long l, r, sm, mn;
Node *lc, *rc;
Node(long long L, long long R): l(L), r(R), sm(0), mn(-R), lc(nullptr), rc(nullptr) {}
void update(long long p, long long v) {
sm += v;
if (l != r) {
long long mid = (l + r) / 2;
if (p > mid) {
if (!rc) rc = new Node(mid + 1, r);
rc->update(p, v);
} else {
if (!lc) lc = new Node(l, mid);
lc->update(p, v);
}
long long lmn = (lc ? lc->mn : -mid), rmn = (rc ? rc->mn : -r);
long long lsm = (lc ? lc->sm : 0);
mn = (lmn < lsm + rmn ? lmn : lsm + rmn);
}
}
} *root;
bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
root = new Node(1, maxCoinSize);
for (int i = 0; i < coinsCount; i++) root->update(coins[i], coins[i]);
return root->mn < -1;
}
bool is_happy(int event, int coinsCount, long long coins[]) {
for (int i = 0; i < coinsCount; i++) root->update(coins[i], event * coins[i]);
return root->mn < -1;
}
Compilation message
grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
16 | long long max_code;
| ^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |