#include <bits/stdc++.h>
using namespace std;
#define lg long long
struct Node {
lg l, r, val = 0;
Node* c[2] = { nullptr, nullptr };
Node* ML() {
if (c[0]) return c[0];
c[0] = new Node;
c[0]->l = l, c[0]->r = (l + r) >> 1;
return c[0];
}
Node* MR() {
if (c[1]) return c[1];
c[1] = new Node;
c[1]->l = ((l + r) >> 1) + 1, c[1]->r = r;
return c[1];
}
void upd(lg p, lg v) {
val += p * v;
if (l != r) {
lg mid = (l + r) >> 1;
if (p >= mid + 1)
MR()->upd(p, v);
else
ML()->upd(p, v);
}
}
lg qry(lg L, lg R) {
if (r < L || R < l) return 0;
if (r <= R && l >= L) return val;
return (c[0] ? c[0]->qry(L, R) : 0) + (c[1] ? c[1]->qry(L, R) : 0);
}
};
Node* seg;
bool works() {
lg bp = 1, sum = seg->val;
while (bp < sum) {
lg nxt = seg->qry(1, bp);
if (nxt < bp) return false;
bp = nxt + 1;
}
return true;
}
bool init(int coinsCount, lg maxCoinSize, lg coins[]) {
seg = new Node;
seg->l = 1;
seg->r = maxCoinSize;
for (int i = 0; i < coinsCount; i++) seg->upd(coins[i], 1);
return works();
}
bool is_happy(int event, int coinsCount, lg coins[]) {
for (int i = 0; i < coinsCount; i++) seg->upd(coins[i], event);
return works();
}
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 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
1728 KB |
Output is correct |
7 |
Correct |
3 ms |
1876 KB |
Output is correct |
8 |
Correct |
26 ms |
14012 KB |
Output is correct |
9 |
Correct |
27 ms |
14136 KB |
Output is correct |
10 |
Correct |
21 ms |
13648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
355 ms |
37380 KB |
Output is correct |
7 |
Correct |
389 ms |
37048 KB |
Output is correct |
8 |
Correct |
359 ms |
37516 KB |
Output is correct |
9 |
Correct |
500 ms |
48708 KB |
Output is correct |
10 |
Correct |
495 ms |
52776 KB |
Output is correct |
11 |
Correct |
134 ms |
37004 KB |
Output is correct |
12 |
Correct |
140 ms |
37124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
1728 KB |
Output is correct |
7 |
Correct |
3 ms |
1876 KB |
Output is correct |
8 |
Correct |
26 ms |
14012 KB |
Output is correct |
9 |
Correct |
27 ms |
14136 KB |
Output is correct |
10 |
Correct |
21 ms |
13648 KB |
Output is correct |
11 |
Correct |
355 ms |
37380 KB |
Output is correct |
12 |
Correct |
389 ms |
37048 KB |
Output is correct |
13 |
Correct |
359 ms |
37516 KB |
Output is correct |
14 |
Correct |
500 ms |
48708 KB |
Output is correct |
15 |
Correct |
495 ms |
52776 KB |
Output is correct |
16 |
Correct |
134 ms |
37004 KB |
Output is correct |
17 |
Correct |
140 ms |
37124 KB |
Output is correct |
18 |
Correct |
893 ms |
225164 KB |
Output is correct |
19 |
Correct |
940 ms |
233632 KB |
Output is correct |
20 |
Correct |
1248 ms |
375488 KB |
Output is correct |
21 |
Correct |
730 ms |
197496 KB |
Output is correct |
22 |
Correct |
188 ms |
36620 KB |
Output is correct |
23 |
Correct |
197 ms |
36596 KB |
Output is correct |
24 |
Correct |
884 ms |
214712 KB |
Output is correct |