답안 #789056

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
789056 2023-07-20T23:38:56 Z lamduybao03 Happiness (Balkan15_HAPPINESS) C++14
컴파일 오류
0 ms 0 KB
#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(int n, int m, int* a) {
    for(int i = 0; i < n; i++) {
        root.update(a[i], 1);
    }
    return root.query();
}
bool is_happy(int id, int 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;
      |            ^~~~~~~~
/usr/bin/ld: /tmp/ccmGQdp6.o: in function `main':
grader.cpp:(.text.startup+0x96): undefined reference to `init(int, long long, long long*)'
/usr/bin/ld: grader.cpp:(.text.startup+0x160): undefined reference to `is_happy(int, int, long long*)'
collect2: error: ld returned 1 exit status