This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "happiness.h"
#include<bits/stdc++.h>
using namespace std;
struct node{
long long l, r, val;
node* lc, *rc;
node(long long l1, long long r1){
l = l1, r = r1;
val = 0;
lc = NULL;
rc = NULL;
}
void ud(long long pos, long long v){
val += v;
if (l == r) return;
long long mid = (l + r) >> 1;
if (pos > mid){
if (!rc) rc = new node(mid + 1, r);
rc -> ud(pos, v);
}
else{
if (!lc) lc = new node(l, mid);
lc -> ud(pos, v);
}
}
long long get(long long u, long long v){
if (l > v || r < u) return 0;
if (l >= u && r <= v) return val;
long long t = 0, tt = 0;
if (lc) t = lc -> get(u, v);
if (rc) tt = rc -> get(u, v);
return (t + tt);
}
};
node *root;
bool check(){
long long mx = root -> val;
long long cur = 1;
while (cur < mx){
long long t = root -> get(1, cur);
if (t < cur) return false;
cur = t + 1;
}
return true;
}
bool init(int coinsCount, long long maxCoinSize, long long coins[]){
root = new node(1, maxCoinSize);
for (int i = 0; i < coinsCount; i++){
root -> ud(coins[i], coins[i]);
}
return check();
}
bool is_happy(int event, int coinsCount, long long coins[]){
for (int i = 0; i < coinsCount; i++)
root->ud(coins[i], event * coins[i]);
return check();
}
Compilation message (stderr)
grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
16 | long long max_code;
| ^~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |