Submission #590439

# Submission time Handle Problem Language Result Execution time Memory
590439 2022-07-05T23:56:26 Z Shreyan_Paliwal Happiness (Balkan15_HAPPINESS) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

#define lg long long

struct Node {
  lg    l, r, val = 0;
  Node* c[2] = { nullptr, nullptr };

  Node(lg L, lg R) : l(L), r(R) {
    c[0] = c[1] = nullptr;
    val         = 0;
  }

  Node* ML() {
    if (c[0]) return c[0];
    c[0]    = new Node;
    c[0]->l = l, c[0]->r = (l + r) >> 1;
    return c[0];
  }

  Node* MR() {
    if (c[1]) return c[1];
    c[1]    = new Node;
    c[1]->l = ((l + r) >> 1) + 1, c[1]->r = r;
    return c[1];
  }

  void upd(lg p, lg v) {
    val += p * v;
    if (l != r) {
      lg mid = (l + r) >> 1;
      if (p >= mid + 1)
        MR()->upd(p, v);
      else
        ML()->upd(p, v);
    }
  }

  lg qry(lg L, lg R) {
    if (r < L || R < l) return 0;
    if (r <= R && l >= L) return val;
    return (c[0] ? c[0]->qry(L, R) : 0) + (c[1] ? c[1]->qry(L, R) : 0);
  }
};

Node* seg;

bool works() {
  lg bp = 1, sum = seg->val;
  while (bp < sum) {
    lg nxt = seg->qry(1, bp);
    if (nxt < bp) return false;
    bp = nxt + 1;
  }
  return true;
}

bool init(int coinsCount, lg maxCoinSize, lg coins[]) {
  seg    = new Node;
  seg->l = 1;
  seg->r = maxCoinSize;
  for (int i = 0; i < coinsCount; i++) seg->upd(coins[i], 1);
  return works();
}

bool is_happy(int event, int coinsCount, lg coins[]) {
  for (int i = 0; i < coinsCount; i++) seg->upd(coins[i], event);
  return works();
}

Compilation message

happiness.cpp: In member function 'Node* Node::ML()':
happiness.cpp:17:19: error: no matching function for call to 'Node::Node()'
   17 |     c[0]    = new Node;
      |                   ^~~~
happiness.cpp:10:3: note: candidate: 'Node::Node(long long int, long long int)'
   10 |   Node(lg L, lg R) : l(L), r(R) {
      |   ^~~~
happiness.cpp:10:3: note:   candidate expects 2 arguments, 0 provided
happiness.cpp:6:8: note: candidate: 'constexpr Node::Node(const Node&)'
    6 | struct Node {
      |        ^~~~
happiness.cpp:6:8: note:   candidate expects 1 argument, 0 provided
happiness.cpp:6:8: note: candidate: 'constexpr Node::Node(Node&&)'
happiness.cpp:6:8: note:   candidate expects 1 argument, 0 provided
happiness.cpp: In member function 'Node* Node::MR()':
happiness.cpp:24:19: error: no matching function for call to 'Node::Node()'
   24 |     c[1]    = new Node;
      |                   ^~~~
happiness.cpp:10:3: note: candidate: 'Node::Node(long long int, long long int)'
   10 |   Node(lg L, lg R) : l(L), r(R) {
      |   ^~~~
happiness.cpp:10:3: note:   candidate expects 2 arguments, 0 provided
happiness.cpp:6:8: note: candidate: 'constexpr Node::Node(const Node&)'
    6 | struct Node {
      |        ^~~~
happiness.cpp:6:8: note:   candidate expects 1 argument, 0 provided
happiness.cpp:6:8: note: candidate: 'constexpr Node::Node(Node&&)'
happiness.cpp:6:8: note:   candidate expects 1 argument, 0 provided
happiness.cpp: In function 'bool init(int, long long int, long long int*)':
happiness.cpp:60:16: error: no matching function for call to 'Node::Node()'
   60 |   seg    = new Node;
      |                ^~~~
happiness.cpp:10:3: note: candidate: 'Node::Node(long long int, long long int)'
   10 |   Node(lg L, lg R) : l(L), r(R) {
      |   ^~~~
happiness.cpp:10:3: note:   candidate expects 2 arguments, 0 provided
happiness.cpp:6:8: note: candidate: 'constexpr Node::Node(const Node&)'
    6 | struct Node {
      |        ^~~~
happiness.cpp:6:8: note:   candidate expects 1 argument, 0 provided
happiness.cpp:6:8: note: candidate: 'constexpr Node::Node(Node&&)'
happiness.cpp:6:8: note:   candidate expects 1 argument, 0 provided
grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
   16 |  long long max_code;
      |            ^~~~~~~~