답안 #381304

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
381304 2021-03-25T02:50:24 Z ntabc05101 Happiness (Balkan15_HAPPINESS) C++14
컴파일 오류
0 ms 0 KB
#include "happiness.h"
#include<bits/stdc++.h>

struct Node {
        int64_t l, r, value;
        Node *lc, *rc;

        Node(int64_t L, int64_t R): l(L), r(R), value(0), lc(nullptr), rc(nullptr) {};

        void update(int64_t p, int64_t delta) {
                value+=delta;
                if (l!=r) {
                        int64_t mid=l+r>>1;
                        if (p>mid) {
                                if (!rc) rc=new Node(mid+1, r);
                                rc->update(p, delta);
                        }
                        else {
                                if (!lc) lc=new Node(l, mid);
                                lc->update(p, delta);
                        }
                }
        }

        int64_t get(int64_t left, int64_t right) {
                if (left>r or right<l) return 0;
                if (left<=l and right>=r) return value;

                int64_t ret=0;
                if (lc) ret+=lc->get(left, right);
                if (rc) ret+=rc->get(left, right);
                return ret;
        }
};

Node* root;

bool check() {
        int64_t current=0, sum=root->value;
        while (current<sum) {
                int64_t t=root->get(1, current);
                if (t<current) return false;
                current=t+1;
        }

        return true;
}

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

        return check();
}

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

        return check();
}

/*int main() {
        std::ios_base::sync_with_stdio(0); std::cin.tie(0);

        int n; int64_t m; std::cin>>n>>m;
        int64_t coins[n];
        for (int i=0; i<n; i++) std::cin>>coins[i];
        std::cout<<init(n, m, coins)<<"\n";

        int q; std::cin>>q;
        while (q--) {
                int e, k; std::cin>>e>>k;
                int64_t coins[k]; 
                for (int i=0; i<k; i++) std::cin>>coins[i];
                std::cout<<is_happy(e, k, coins)<<"\n";
        }

        return 0;
}*/

Compilation message

happiness.cpp: In member function 'void Node::update(int64_t, int64_t)':
happiness.cpp:13:38: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 |                         int64_t 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;
      |            ^~~~~~~~
/tmp/cccrHRZt.o: In function `main':
grader.cpp:(.text.startup+0x96): undefined reference to `init(int, long long, long long*)'
grader.cpp:(.text.startup+0x160): undefined reference to `is_happy(int, int, long long*)'
collect2: error: ld returned 1 exit status