ttamx's library

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

View on GitHub

:heavy_check_mark: verify/yosupo/template/aplusb.test.cpp

Depends on

Code

#define PROBLEM "https://judge.yosupo.jp/problem/aplusb"
#include "template.hpp"

void test_macros(){
    vector<int> a{3,1,4,1,5};
    assert(SZ(a)==5);
    assert(FIND(a,4)==2&&FIND(a,9)==SZ(a));
    assert(COUNT(a,1)==2&&COUNT(a,7)==0);
    assert(MIN(a)==1&&MAX(a)==5);
    SORT(a);
    assert(a==vector<int>({1,1,3,4,5}));
    UNI(a);
    assert(a==vector<int>({1,3,4,5}));
    assert(LB(a,3)==1&&UB(a,3)==2&&LB(a,6)==4);
    RSORT(a);
    assert(a==vector<int>({5,4,3,1}));
    REV(a);
    assert(a==vector<int>({1,3,4,5}));
}

void test_chmin_chmax(){
    ll x=5;
    assert(chmin(x,3)&&x==3);
    assert(!chmin(x,4)&&x==3);
    assert(chmax(x,7)&&x==7);
    assert(!chmax(x,7)&&x==7);
}

void test_floor_ceil(){
    for(ll a=-50;a<=50;a++){
        for(ll b=-7;b<=7;b++){
            if(b==0)continue;
            assert(floor(a,b)==(ll)std::floor((db)a/b));
            assert(ceil(a,b)==(ll)std::ceil((db)a/b));
        }
    }
}

void test_bits(){
    assert(popcnt(0)==0&&popcnt(13)==3&&popcnt((1LL<<62)|1)==2);
    assert(topbit(0)==-1&&topbit(1)==0&&topbit(13)==3&&topbit(1LL<<62)==62);
    assert(lowbit(0)==-1&&lowbit(1)==0&&lowbit(12)==2&&lowbit(1LL<<62)==62);
}

void test_sum_argsort(){
    vector<int> a(3,2000000000);
    assert(SUM<ll>(a)==6000000000LL);
    vector<int> b{30,10,20,10};
    assert(argsort(b)==vector<int>({1,3,2,0}));
}

void test_vec(){
    auto a=VEC<pair<int,int>>[2][3][4]();
    static_assert(is_same_v<decltype(a),vector<vector<vector<pair<int,int>>>>>);
    assert(SZ(a)==2&&SZ(a[0])==3&&SZ(a[0][0])==4&&a[1][2][3]==pair(0,0));
    auto b=VEC<ll>[2][3](LINF);
    assert(b[1][2]==LINF);
}

int main(){
    test_macros();
    test_chmin_chmax();
    test_floor_ceil();
    test_bits();
    test_sum_argsort();
    test_vec();
    ll a,b;
    cin >> a >> b;
    cout << a+b << "\n";
}
#line 1 "verify/yosupo/template/aplusb.test.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/aplusb"
#line 2 "template.hpp"
#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using db = long double;
using i128 = __int128_t;
using u32 = uint32_t;
using u64 = uint64_t;
template<class T>
using PQ = priority_queue<T,vector<T>,greater<T>>;

const int INF=INT_MAX/2;
const ll LINF=LLONG_MAX/4;
const db DINF=numeric_limits<db>::infinity();
const db EPS=1e-9;
const db PI=acos(db(-1));

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SZ(a) (int)(a.size())
#define SORT(a) sort(ALL(a))
#define RSORT(a) sort(RALL(a))
#define REV(a) reverse(ALL(a))
#define UNI(a) a.erase(unique(ALL(a)),a.end())
#define LB(a,x) (int)(lower_bound(ALL(a),x)-a.begin())
#define UB(a,x) (int)(upper_bound(ALL(a),x)-a.begin())
#define FIND(a,x) (int)(find(ALL(a),x)-a.begin())
#define COUNT(a,x) (int)count(ALL(a),x)
#define MIN(a) *min_element(ALL(a))
#define MAX(a) *max_element(ALL(a))

template<class T,class U>
bool chmin(T &a,U b){return b<a?a=b,1:0;}
template<class T,class U>
bool chmax(T &a,U b){return a<b?a=b,1:0;}

template<class T>
T floor(T a,T b){return a/b-((a^b)<0&&a%b);}
template<class T>
T ceil(T a,T b){return a/b+((a^b)>=0&&a%b);}

int popcnt(ll x){return __builtin_popcountll(x);}
int topbit(ll x){return x==0?-1:63-__builtin_clzll(x);}
int lowbit(ll x){return x==0?-1:__builtin_ctzll(x);}

template<class T,class U>
T SUM(const U &a){return accumulate(ALL(a),T{});}
template<class T>
vector<int> argsort(const vector<T> &a){
    vector<int> p(SZ(a));
    iota(ALL(p),0);
    stable_sort(ALL(p),[&](int i,int j){return a[i]<a[j];});
    return p;
}

template<class T,size_t D=0>
struct VecBuilder{
    array<size_t,D> d;
    VecBuilder<T,D+1> operator[](size_t n)const{
        VecBuilder<T,D+1> res{};
        for(size_t i=0;i<D;i++)res.d[i]=d[i];
        res.d[D]=n;
        return res;
    }
    template<size_t I=0>
    auto build(const T &x)const{
        if constexpr(I+1==D)return vector<T>(d[I],x);
        else return vector<decltype(build<I+1>(x))>(d[I],build<I+1>(x));
    }
    auto operator()(const T &x=T())const{
        static_assert(D>0);
        return build(x);
    }
};
template<class T>
inline constexpr VecBuilder<T> VEC{};

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
#line 3 "verify/yosupo/template/aplusb.test.cpp"

void test_macros(){
    vector<int> a{3,1,4,1,5};
    assert(SZ(a)==5);
    assert(FIND(a,4)==2&&FIND(a,9)==SZ(a));
    assert(COUNT(a,1)==2&&COUNT(a,7)==0);
    assert(MIN(a)==1&&MAX(a)==5);
    SORT(a);
    assert(a==vector<int>({1,1,3,4,5}));
    UNI(a);
    assert(a==vector<int>({1,3,4,5}));
    assert(LB(a,3)==1&&UB(a,3)==2&&LB(a,6)==4);
    RSORT(a);
    assert(a==vector<int>({5,4,3,1}));
    REV(a);
    assert(a==vector<int>({1,3,4,5}));
}

void test_chmin_chmax(){
    ll x=5;
    assert(chmin(x,3)&&x==3);
    assert(!chmin(x,4)&&x==3);
    assert(chmax(x,7)&&x==7);
    assert(!chmax(x,7)&&x==7);
}

void test_floor_ceil(){
    for(ll a=-50;a<=50;a++){
        for(ll b=-7;b<=7;b++){
            if(b==0)continue;
            assert(floor(a,b)==(ll)std::floor((db)a/b));
            assert(ceil(a,b)==(ll)std::ceil((db)a/b));
        }
    }
}

void test_bits(){
    assert(popcnt(0)==0&&popcnt(13)==3&&popcnt((1LL<<62)|1)==2);
    assert(topbit(0)==-1&&topbit(1)==0&&topbit(13)==3&&topbit(1LL<<62)==62);
    assert(lowbit(0)==-1&&lowbit(1)==0&&lowbit(12)==2&&lowbit(1LL<<62)==62);
}

void test_sum_argsort(){
    vector<int> a(3,2000000000);
    assert(SUM<ll>(a)==6000000000LL);
    vector<int> b{30,10,20,10};
    assert(argsort(b)==vector<int>({1,3,2,0}));
}

void test_vec(){
    auto a=VEC<pair<int,int>>[2][3][4]();
    static_assert(is_same_v<decltype(a),vector<vector<vector<pair<int,int>>>>>);
    assert(SZ(a)==2&&SZ(a[0])==3&&SZ(a[0][0])==4&&a[1][2][3]==pair(0,0));
    auto b=VEC<ll>[2][3](LINF);
    assert(b[1][2]==LINF);
}

int main(){
    test_macros();
    test_chmin_chmax();
    test_floor_ceil();
    test_bits();
    test_sum_argsort();
    test_vec();
    ll a,b;
    cin >> a >> b;
    cout << a+b << "\n";
}
Back to top page