Hashiryo's Library

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub hashiryo/Library

:heavy_check_mark: 体を並列に扱う ($K_1\times K_2\times\cdots\times K_n$) (src/Misc/Pointwise.hpp)

Rolling Hash などのハッシュ計算をする時に, baseを変えたパターンのを並行して扱うのを便利にするために作った.

Verify

Verified with

Code

#pragma once
#include <tuple>
#include <array>
#include <utility>
template <class... Ks> struct Pointwise: std::tuple<Ks...> {
 static constexpr int N= sizeof...(Ks);
 using Self= Pointwise;
 using std::tuple<Ks...>::tuple;
 template <class T> Pointwise(const T &v) { fill(v, std::make_index_sequence<N>()); }
 template <class T, std::size_t... I> std::array<int, N> fill(const T &v, std::index_sequence<I...>) { return {{(void(std::get<I>(*this)= v), 0)...}}; }
#define HELPER(name, op) \
 template <std::size_t... I> std::array<int, N> name(const Self &y, std::index_sequence<I...>) { return {{(void(std::get<I>(*this) op##= std::get<I>(y)), 0)...}}; } \
 Self &operator op##=(const Self & r) { return name(r, std::make_index_sequence<N>()), *this; }
 HELPER(add_assign, +)
 HELPER(dif_assign, -)
 HELPER(mul_assign, *)
 HELPER(div_assign, /)
#undef HELPER
 Self operator+(const Self &r) const { return Self(*this)+= r; }
 Self operator-(const Self &r) const { return Self(*this)-= r; }
 Self operator*(const Self &r) const { return Self(*this)*= r; }
 Self operator/(const Self &r) const { return Self(*this)/= r; }
};
#line 2 "src/Misc/Pointwise.hpp"
#include <tuple>
#include <array>
#include <utility>
template <class... Ks> struct Pointwise: std::tuple<Ks...> {
 static constexpr int N= sizeof...(Ks);
 using Self= Pointwise;
 using std::tuple<Ks...>::tuple;
 template <class T> Pointwise(const T &v) { fill(v, std::make_index_sequence<N>()); }
 template <class T, std::size_t... I> std::array<int, N> fill(const T &v, std::index_sequence<I...>) { return {{(void(std::get<I>(*this)= v), 0)...}}; }
#define HELPER(name, op) \
 template <std::size_t... I> std::array<int, N> name(const Self &y, std::index_sequence<I...>) { return {{(void(std::get<I>(*this) op##= std::get<I>(y)), 0)...}}; } \
 Self &operator op##=(const Self & r) { return name(r, std::make_index_sequence<N>()), *this; }
 HELPER(add_assign, +)
 HELPER(dif_assign, -)
 HELPER(mul_assign, *)
 HELPER(div_assign, /)
#undef HELPER
 Self operator+(const Self &r) const { return Self(*this)+= r; }
 Self operator-(const Self &r) const { return Self(*this)-= r; }
 Self operator*(const Self &r) const { return Self(*this)*= r; }
 Self operator/(const Self &r) const { return Self(*this)/= r; }
};
Back to top page