This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//
#ifndef __SIZEOF_INT128__
#define __SIZEOF_INT128__
#endif
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
template <typename T> using oset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define rep(i, p, k) for(int i(p); i < (k); ++i)
#define per(i, p, k) for(int i(p); i > (k); --i)
#define sz(x) (int)(x).size()
#define sc static_cast
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef __int128_t lll;
//#define int ll
template <typename T = int> using par = std::pair <T, T>;
#define fi first
#define se second
#define test int _number_of_tests(in()); while(_number_of_tests--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb emplace_back
struct Timer {
string name{""};
time_point<high_resolution_clock> end, start{high_resolution_clock::now()};
duration<float, std::milli> dur;
Timer() = default;
Timer(string nm): name(nm) {}
~Timer() {
end = high_resolution_clock::now(); dur= end - start;
cout << "@" << name << "> " << dur.count() << " ms" << '\n';
}
};
template <typename T = int> inline T in()
{
static T x;
std::cin >> x;
return x;
}
std::string yn(bool b)
{
if(b) return "YES\n";
else return "NO\n";
}
template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par);
template <typename T> std::ostream& operator<< (std::ostream& out, const std::vector <T>& wek)
{
for(const auto& i : wek)out << i << ' ';
return out;
}
template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par)
{
out << '{'<<par.first<<", "<<par.second<<"}";
return out;
}
#define show(x) cerr << #x << " = " << x << '\n';
vector <int> l, r;
vector <ll> t;
int ne(){
l.pb(-1); r.pb(-1); t.pb(-1);
return sz(t)-1;
}
void add(int w, ll a, int z, ll d)
{
if(a == 0){
l[w] = r[w] = 0;
}
if(0 < a && a < d/2){
l[w] = ne();
r[w] = 0;
add(l[w], a, l[z], d/2);
}
if(a == d/2){
l[w] = l[z];
r[w] = 0;
}
if(d/2 < a && a < d){
l[w] = l[z];
r[w] = ne();
add(r[w], a-d/2, r[z], d/2);
}
if(a == d){
l[w] = l[z];
r[w] = r[z];
}
t[w] = t[l[w]] + t[r[w]];
}
ll count_tastiness(ll x, vector<ll> a)
{
l = {-1, -1};
r = {-1, -1};
t = {0, 1};
vector <ll> moz{0};
ll s(0);
int k(1);
rep(p, 0, 61){
l.pb(k); r.pb(0); t.pb(t[k]);
k = sz(l)-1;
if(p < sz(a))s += (a[p]<<p);
if(s < (lll(x)<<p))continue;
ll b(min((1ll<<p)-1, (s-(x<<p))/x)+1);
if(b == 1ll<<p){
r[k] = l[k];
t[k] *= 2;
continue;
}
r[k] = ne();
add(r[k], b, l[k], (1ll<<p));
t[k] = t[l[k]] + t[r[k]];
// cerr << "--------------------\n";
// cerr << l << '\n' << r << '\n' << t << '\n';
}
return t[k];
}
# | 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... |