Submission #682411

# Submission time Handle Problem Language Result Execution time Memory
682411 2023-01-16T08:12:43 Z MilosMilutinovic Happiness (Balkan15_HAPPINESS) C++14
Compilation error
0 ms 0 KB
#include "happiness.h"
#include <bits/stdc++.h>

using namespace std;

const int MAX = 200005;
const long long inf = (long long) 1.01e12;

int root, ls[MAX * 60], rs[MAX * ^0], tsz;
long long sum[MAX * 60];
long long tot[MAX];
long long f[MAX];
multiset<long long> c;

void modify(int& v, long long l, long long r, long long i, int x) {
  if (!v) {
    v = ++tsz;
  }
  sum[v] += x * i;
  if (l == r) {
    return;
  }
  long long mid = l + r >> 1;
  if (i <= mid) {
    modify(ls[v], l, mid, i, x);
  } else {
    modify(rs[v], mid + 1, r, i, x);
  }
}

long long query(int v, long long l, long long r, long long ql, long long qr) {
  if (ql <= l && r <= qr) {
    return sum[v];
  }
  if (l > qr || r < ql || l > r) {
    return 0LL;
  }
  long long mid = l + r >> 1;
  return query(ls[v], l, mid, ql, qr) + query(rs[v], mid + 1, r, ql, qr);
}

long long walk(int v, long long l, long long r, long long s) {
  if (l == r) {
    return s - sum[v] == 0 ? l : l - 1;
  }
  long long mid = l + r >> 1;
  if (ls[v] && s < sum[ls[v]]) {
    return walk(ls[v], l, mid, s);
  } else {
    return walk(rs[v], mid + 1, r, s - sum[ls[v]]);
  }
}

bool Check() {
  if (query(root, 1, inf, 1, inf) == 0) {
    return true;
  }
  if (query(root, 1, inf, 1, 1) == 0) {
    return false;
  }
  long long p = 1;
  while (true) {
    if (query(root, 1, inf, p + 1, inf) == 0) {
      break;
    }
    long long s = query(root, 1, inf, 1, p);
    auto it = c.lower_bound(s + 2);
    long long nxt = (it == c.end() ? inf : *it);
    if (nxt == inf) {
      break;
    }
    if (query(root, 1, inf, 1, nxt - 1) + 1 < nxt) {
      return false;
    }
    p = nxt;
  }
  return true;
}

bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
  for (int i = 0; i < coinsCount; i++) {
    modify(root, 1, inf, coins[i], +1);
    c.insert(coins[i]);
  }
  return Check();
}

bool is_happy(int event, int coinsCount, long long coins[]) {
  if (event == -1) {
    for (int i = 0; i < coinsCount; i++) {
      assert(query(root, 1, inf, coins[i], coins[i]) > 0);
      modify(root, 1, inf, coins[i], -1);
      c.erase(c.find(coins[i]));
    }
  } else {
    for (int i = 0; i < coinsCount; i++) {
      modify(root, 1, inf, coins[i], +1);
      c.insert(coins[i]);
    }
  }
  return Check();
}

Compilation message

happiness.cpp:9:34: error: expected primary-expression before '^' token
    9 | int root, ls[MAX * 60], rs[MAX * ^0], tsz;
      |                                  ^
happiness.cpp: In function 'void modify(int&, long long int, long long int, long long int, int)':
happiness.cpp:23:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   23 |   long long mid = l + r >> 1;
      |                   ~~^~~
happiness.cpp:27:12: error: 'rs' was not declared in this scope; did you mean 'r'?
   27 |     modify(rs[v], mid + 1, r, i, x);
      |            ^~
      |            r
happiness.cpp: In function 'long long int query(int, long long int, long long int, long long int, long long int)':
happiness.cpp:38:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |   long long mid = l + r >> 1;
      |                   ~~^~~
happiness.cpp:39:47: error: 'rs' was not declared in this scope; did you mean 'r'?
   39 |   return query(ls[v], l, mid, ql, qr) + query(rs[v], mid + 1, r, ql, qr);
      |                                               ^~
      |                                               r
happiness.cpp: In function 'long long int walk(int, long long int, long long int, long long int)':
happiness.cpp:46:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |   long long mid = l + r >> 1;
      |                   ~~^~~
happiness.cpp:50:17: error: 'rs' was not declared in this scope; did you mean 'r'?
   50 |     return walk(rs[v], mid + 1, r, s - sum[ls[v]]);
      |                 ^~
      |                 r
grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
   16 |  long long max_code;
      |            ^~~~~~~~