Submission #1086886

# Submission time Handle Problem Language Result Execution time Memory
1086886 2024-09-11T16:30:23 Z serifefedartar Happiness (Balkan15_HAPPINESS) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
#define f first
#define s second
#define LOGN 21
const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 100;

#define int long long
struct Node {
    int l, r;
    int sum;
    Node *ln, *rn;
    Node() : l(-1), r(-1), sum(0), ln(NULL), rn(NULL) { }
    Node(int _l, int _r) : l(_l), r(_r), sum(0), ln(NULL), rn(NULL) { }

    int query(int a, int b) {
        if (r < a || l > b)
            return 0;
        if (l <= a && b <= r)
            return sum;
        int res = 0;
        if (ln)
            res += ln->sum;
        if (rn)
            res += rn->sum;
        return res;
    }

    void update(int plc, int val) {
        sum += val;
        if (l != r) {
            int mid = (l + r) / 2;
            if (plc > mid) {
                if (!rn)
                    rn = new Node(mid + 1, r);
                rn->update(plc, val);
            } else {
                if (!ln)
                    ln = new Node(l, mid);
                ln->update(plc, val);
            }
        }
    }
};

Node *root;
bool solve() {
    int now = 1;
    while (now < root->val) {
        int t = root->query(1, now);
        if (t < now)
            return false;
        now = t + 1;
    }
    return true;
}

bool init(int coinsCount, int maxCoinSize, int coins[]) {
    root = new Node(1, maxCoinSize);
    root->update(1, 1);
    for (int i = 0; i < coinsCount; i++)
        root->update(coins[i], coins[i]);
    return solve();
}

bool is_happy(int event, int coinsCount, int coins[]) {
    for (int i = 0; i < coinsCount; i++)
        root->update(coins[i], event * coins[i]); 
    return solve();
}

Compilation message

happiness.cpp: In function 'bool solve()':
happiness.cpp:53:24: error: 'struct Node' has no member named 'val'
   53 |     while (now < root->val) {
      |                        ^~~
grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
   16 |  long long max_code;
      |            ^~~~~~~~