#include "happiness.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200005;
const long long inf = (long long) 1.01e12;
int root, ls[MAX * 20], rs[MAX * 20], tsz;
long long sum[MAX * 20];
void modify(int& v, long long l, long long r, long long i, int x) {
if (!v) {
v = ++tsz;
}
sum[v] += x * i;
if (l == r) {
return;
}
long long mid = l + r >> 1;
if (i <= mid) {
modify(ls[v], l, mid, i, x);
} else {
modify(rs[v], mid + 1, r, i, x);
}
}
long long query(int v, long long l, long long r, long long ql, long long qr) {
if (ql <= l && r <= qr) {
return sum[v];
}
if (l > qr || r < ql || l > r) {
return 0LL;
}
long long mid = l + r >> 1;
return query(ls[v], l, mid, ql, qr) + query(rs[v], mid + 1, r, ql, qr);
}
long long walk(long long s) {
long long l = s, r = inf, pos = inf;
long long target = query(root, 1, inf, s, inf);
while (l <= r) {
long long mid = l + r >> 1;
if (query(root, 1, inf, mid, inf) == target) {
pos = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
return pos;
}
bool Check() {
if (query(root, 1, inf, 1, 1) == 0) {
return false;
}
for (int i = 2; i <= 200; i++) {
if (query(root, 1, inf, i, i) > 0 && query(root, 1, inf, 1, i - 1) + 1 < i) {
return false;
}
}
return true;
/*long long p = 1;
while (true) {
if (query(root, 1, inf, p + 1, inf) == 0) {
break;
}
long long s = query(root, 1, inf, 1, p);
long long nxt = walk(s + 2);
if (nxt == inf) {
break;
}
if (query(root, 1, inf, 1, nxt - 1) + 1 < nxt) {
return false;
}
p = nxt;
}
return true;*/
}
bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
for (int i = 0; i < coinsCount; i++) {
modify(root, 1, inf, coins[i], +1);
}
return Check();
}
bool is_happy(int event, int coinsCount, long long coins[]) {
if (event == -1) {
for (int i = 0; i < coinsCount; i++) {
assert(query(root, 1, inf, coins[i], coins[i]) > 0);
modify(root, 1, inf, coins[i], -1);
}
} else {
for (int i = 0; i < coinsCount; i++) {
modify(root, 1, inf, coins[i], +1);
}
}
return Check();
}
Compilation message
happiness.cpp: In function 'void modify(int&, long long int, long long int, long long int, int)':
happiness.cpp:20:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
20 | long long mid = l + r >> 1;
| ~~^~~
happiness.cpp: In function 'long long int query(int, long long int, long long int, long long int, long long int)':
happiness.cpp:35:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
35 | long long mid = l + r >> 1;
| ~~^~~
happiness.cpp: In function 'long long int walk(long long int)':
happiness.cpp:43:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
43 | long long mid = l + r >> 1;
| ~~^~~
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 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |