Fu_L's Library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub Fu-L/cp-library

:heavy_check_mark: verify/unit_test/random/random_regression.test.cpp

Depends on

Code

#define PROBLEM "https://judge.yosupo.jp/problem/aplusb"
#include "../../../src/template/template.hpp"
#include "../../../src/random/permuted_congruential_generator.hpp"
int main() {
    rep(_, 0, 1000) {
        int x = rng(numeric_limits<int>::min(), numeric_limits<int>::max());
        (void)x;
        unsigned int y = rng(0u, numeric_limits<unsigned int>::max());
        (void)y;
        int z = rng(-10, 10);
        assert(-10 <= z and z <= 10);
    }
    int a, b;
    cin >> a >> b;
    cout << a + b << '\n';
}
#line 1 "verify/unit_test/random/random_regression.test.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/aplusb"
#line 2 "src/template/template.hpp"
#include <bits/stdc++.h>
#line 4 "src/template/template.hpp"
using namespace std;
using ll = long long;
using P = pair<long long, long long>;
#define rep(i, a, b) for(long long i = (a); i < (b); ++i)
#define rrep(i, a, b) for(long long i = (a); i >= (b); --i)
constexpr long long inf = 4e18;
struct SetupIO {
    SetupIO() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout << fixed << setprecision(30);
    }
} setup_io;
#line 3 "src/random/permuted_congruential_generator.hpp"
struct PermutedCongruentialGenerator {
    template <typename T>
        requires(is_integral_v<T> and sizeof(T) == 4) or (is_floating_point_v<T> and sizeof(T) == 8)
    inline T operator()(const T l, const T r) {
        assert(l <= r);
        if constexpr(is_integral_v<T>) {
            const unsigned int x = next32();
            if constexpr(is_signed_v<T>) {
                const uint64_t range = uint64_t(int64_t(r) - int64_t(l)) + 1;
                const uint64_t offset = range == (uint64_t(1) << 32) ? x : x % range;
                return T(int64_t(l) + int64_t(offset));
            } else {
                const uint64_t range = uint64_t(r) - uint64_t(l) + 1;
                const uint64_t offset = range == (uint64_t(1) << 32) ? x : x % range;
                return T(l + T(offset));
            }
        } else {
            static constexpr unsigned long long denom = 1ull << 53;
            const unsigned long long x = next64() >> 11;
            const double u = static_cast<double>(x) / denom;
            return l + (r - l) * u;
        }
    }

   private:
    static constexpr unsigned long long MULT = 6364136223846793005;
    static inline unsigned long long state = chrono::steady_clock::now().time_since_epoch().count();
    inline unsigned int next32() {
        unsigned long long x = state;
        state *= MULT;
        const unsigned int count = x >> 61;
        x ^= x >> 22;
        return static_cast<unsigned int>(x >> (22 + count));
    }
    inline unsigned long long next64() {
        return (static_cast<unsigned long long>(next32()) << 32) | next32();
    }
} rng;
#line 4 "verify/unit_test/random/random_regression.test.cpp"
int main() {
    rep(_, 0, 1000) {
        int x = rng(numeric_limits<int>::min(), numeric_limits<int>::max());
        (void)x;
        unsigned int y = rng(0u, numeric_limits<unsigned int>::max());
        (void)y;
        int z = rng(-10, 10);
        assert(-10 <= z and z <= 10);
    }
    int a, b;
    cin >> a >> b;
    cout << a + b << '\n';
}
Back to top page