#include <bits/stdc++.h>
#define int long long
using namespace std;
struct Type {
int sum;
int max_d;
Type() {
sum = 0;
max_d = 0;
}
void update(int id, int k) {
if(id == 1) {
max_d = k;
sum += k;
}
else {
sum -= k;
if(sum == 0) {
max_d = 0;
}
}
}
};
struct Node {
Node* left;
Node* right;
Type d;
Type merge(Type a, Type b) {
Type c;
c.sum = a.sum + b.sum;
c.max_d = max(a.max_d, b.max_d - a.sum);
return c;
}
Node() {
left = right = nullptr;
}
Node* new_node(Node* p) {
if(p == nullptr)
return new Node();
else
return p;
}
void add_child() {
left = new_node(left);
right = new_node(right);
}
void update(int i, int x, int l, int r) {
if(l == i && i == r)
d.update(x, i);
else if(l <= i && i <= r) {
int m = l + r >> 1;
add_child();
left->update(i, x, l, m);
right->update(i, x, m+1, r);
d = merge(left->d, right->d);
}
}
int query() {
return d.max_d == 1;
}
void update(int i, int x) {
update(i, x, 0, 1LL << 40);
}
} root;
bool init(int32_t n, int m, int* a) {
for(int i = 0; i < n; i++) {
root.update(a[i], 1);
}
return root.query();
}
bool is_happy(int32_t id, int32_t n, int* a) {
for(int i = 0; i < n; i++) {
root.update(a[i], id);
}
return root.query();
}
Compilation message
happiness.cpp: In member function 'void Node::update(long long int, long long int, long long int, long long int)':
happiness.cpp:52:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
52 | int m = 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 |
- |