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;
#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;
struct Node {
ll v;
int l, r;
Node() {
v = 0;
l = r = 0;
}
};
ll n, m, sz, mx;
Node tree[20202020];
void update(int node, ll s, ll e, ll i, ll x) {
if(s == e) {
tree[node].v += x;
return;
}
ll m = (s + e)/2;
if(i <= m) {
if(!tree[node].l) tree[node].l = ++sz;
update(tree[node].l, s, m, i, x);
}
else {
if(!tree[node].r) tree[node].r = ++sz;
update(tree[node].r, m+1, e, i, x);
}
tree[node].v = tree[tree[node].l].v + tree[tree[node].r].v;
}
ll cal(int node, ll s, ll e, ll l, ll r) {
if(r < s || e < l || !node) return 0;
if(l <= s && e <= r) return tree[node].v;
return cal(tree[node].l, s, (s+e)/2, l, r) + cal(tree[node].r, (s+e)/2+1, e, l, r);
}
bool chk() {
ll sum = 0;
while(sum < min(m, mx)) {
ll x = cal(1, 0, m, 0, sum+1);
if(x == sum) return false;
sum = x;
}
return true;
}
bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
n = coinsCount;
m = maxCoinSize + 1;
sz = 1;
for(int i=0; i<n; i++) {
update(1, 0, m, coins[i], coins[i]);
mx += coins[i];
}
return chk();
}
bool is_happy(int event, int coinsCount, long long coins[]) {
n = coinsCount;
for(int i=0; i<n; i++) {
update(1, 0, m, coins[i], event * coins[i]);
mx += event * coins[i];
}
return chk();
}
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... |