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 <bits/stdc++.h>
using namespace std;
#include "biscuits.h"
using ll = long long;
using lll = __int128;
struct node {
lll mn, mx, ad, sz;
node *l, *r;
};
using seq = node*;
seq con(lll n, lll v) {
return n == 0 ? nullptr : new node{v, v, 0, n, nullptr, nullptr};
}
seq inc(seq s, lll a) {
return a == 0 ? s : new node{s->mn, s->mx, s->ad + a, s->sz, s->l, s->r};
}
seq conc(seq l, seq r, lll ad = 0) {
if (l == nullptr) return inc(r, ad);
if (r == nullptr) return inc(l, ad);
assert(l->mx + l->ad <= r->mn + r->ad);
return new node{l->mn + l->ad, r->mx + r->ad, ad, l->sz + r->sz, l, r};
}
seq drop(seq s, lll u = 0) {
u -= s->ad;
return s->mx < u ? nullptr : u <= s->mn ? s : conc(drop(s->l, u), drop(s->r, u), s->ad);
}
lll size(seq s) {
return s->sz;
}
ll count_tastiness(ll x, vector<ll> a) {
a.resize(62);
auto s = con(1, 0);
for (int i = 0; i < a.size(); i++) s = drop(conc(inc(s, lll(-x) << i), s, lll(a[i]) << i));
return size(s);
}
Compilation message (stderr)
biscuits.cpp: In function 'll count_tastiness(ll, std::vector<long long int>)':
biscuits.cpp:35:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int i = 0; i < a.size(); i++) s = drop(conc(inc(s, lll(-x) << i), s, lll(a[i]) << i));
| ~~^~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |