Submission #73236

# Submission time Handle Problem Language Result Execution time Memory
73236 2018-08-28T05:41:10 Z 강태규(#2268) Happiness (Balkan15_HAPPINESS) C++11
0 / 100
795 ms 525312 KB
#include "happiness.h"

typedef long long llong;

llong mx;
struct node {
    node *l, *r;
    llong sum;
    node() : l(0), r(0), sum(0) {}
} ns[42 * 1000000];

node * _alloc() {
    static int tp = 0;
    return ns + tp++;
}

void update(node * &i, llong s, llong e, llong x, llong v) {
    if (i == 0) i = _alloc();
    i->sum += v;
    if (s == e) return;
    llong m = (s + e) / 2;
    if (x <= m) update(i->l, s, m, x, v);
    else update(i->r, m + 1, e, x, v);
}

llong query(node * &i, llong s, llong e, llong x) {
    if (i == 0) return 0;
    if (x < s) return 0;
    if (e <= x) return i->sum;
    llong m = (s + e) / 2;
    return query(i->l, s, m, x) + query(i->r, m + 1, e, x);
}

node * rt;
bool check() {
    llong sum = 0, pr = -1;
    while (pr != sum) sum = query(rt, 1, mx, (pr = sum) + 1);
    return sum == rt->sum;
}

bool init(int coinsCount, llong maxCoinSize, llong coins[]) {
    rt = _alloc();
    mx = maxCoinSize;
    for (int i = 0; i < coinsCount; ++i)
        update(rt, 1, mx, coins[i], coins[i]);
    return check();
}
bool is_happy(int event, int coinsCount, llong coins[]) {
    for (int i = 0; i < coinsCount; ++i)
        update(rt, 1, mx, coins[i], event * coins[i]);
    return check();
}

Compilation message

grader.cpp: In function 'int main()':
grader.cpp:14:9: warning: unused variable 'd' [-Wunused-variable]
  int i, d;
         ^
grader.cpp:15:12: warning: unused variable 'max_code' [-Wunused-variable]
  long long max_code;
            ^~~~~~~~
grader.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%lld", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~~~
grader.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &coins[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~
grader.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &Q);
  ~~~~~^~~~~~~~~~
grader.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &ck, &c);
   ~~~~~^~~~~~~~~~~~~~~~~
grader.cpp:28:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld", &A[j]);
    ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 698 ms 525312 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 795 ms 525312 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 691 ms 525312 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 663 ms 525312 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -