#include <bits/stdc++.h>
using namespace std;
#include "happiness.h"
struct tnode
{
int64_t t;
tnode *l, *r;
uint64_t x, y;
void *new_node(bool left)
{
if (left)
{
if (!l)
{
l = (tnode *)calloc(1, sizeof(tnode));
l->x = x;
l->y = (x + y) / 2;
}
}
else
{
if (!r)
{
r = (tnode *)calloc(1, sizeof(tnode));
r->x = (x + y) / 2 + 1;
r->y = y;
}
}
}
void update(uint64_t i, int64_t v)
{
if (x == i && y == i)
t += v;
else
{
if (i <= (x + y) / 2)
{
new_node(1);
l->update(i, v);
}
else
{
new_node(0);
r->update(i, v);
}
t = (l ? l->t : 0) + (r ? r->t : 0);
}
}
int64_t range_sum(uint64_t i, uint64_t j)
{
if (y < i || x > j)
return 0;
if (i <= x && y <= j)
return t;
else
return (l ? l->range_sum(i, j) : 0) + (r ? r->range_sum(i, j) : 0);
}
void destroy()
{
if (l)
{
l->destroy();
free(l);
}
if (r)
{
r->destroy();
free(r);
}
}
};
tnode *root;
bool check()
{
int64_t curr = 1, sum = root->t;
while (curr < sum)
{
int64_t v = root->range_sum(1, curr);
if (v < curr)
return 0;
curr = v + 1;
}
return 1;
}
bool init(int coinsCount, long long maxCoinSize, long long coins[])
{
root = (tnode *)calloc(1, sizeof(tnode));
root->y = maxCoinSize + 1;
for (int i = 0; i < coinsCount; i++)
root->update(coins[i], coins[i]);
return check();
}
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 check();
}
Compilation message
happiness.cpp: In member function 'void* tnode::new_node(bool)':
happiness.cpp:32:5: warning: no return statement in function returning non-void [-Wreturn-type]
32 | }
| ^
grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
16 | long long max_code;
| ^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |