This documentation is automatically generated by online-judge-tools/verification-helper
#include "src/template/accum1d.hpp"
1次元列の累積和をとります。
詳しくいうと、与えられた列 $A$ に対して、 $\displaystyle S_0\ =\ 0\land S_i\ =\ \sum_{j = 0}^{i - 1} A_j (i > 0)$ を満たす列 $S$ を構築します。
コンストラクタ
zawa::accum1d<T>()
T()
1要素のみの列を構築します。zawa::accum1d<T>(const std::vector<T>& A)
A
から $S$ を構築します。std::partial_sum
を内部で利用しています。zawa::accum1d<T>(InputIterator begin, InputIterator end)
begin
からend
までの要素からS
を構築します。それぞれ計算量は: $O(\mid A\mid)$
メンバ関数
T sum(std::size_t l, std::size_t r)
std::vector<T>
を継承しているので、std::vector
の機能がそのまま使えます。
sum
を呼び出そう。ex) sum(l, l + p)
int
型の列からlong long
型のaccum1d
を構築できるようにする#pragma once
#include <vector>
#include <numeric>
namespace zawa {
template <class T>
struct accum1d : std::vector<T> {
using vector = std::vector<T>;
accum1d() {
(*this).push_back(T());
}
accum1d(const std::vector<T>& A) {
(*this).push_back(T());
std::partial_sum(A.begin(), A.end(), std::back_inserter(*this));
}
template <class InputIterator>
accum1d(InputIterator begin, InputIterator end) {
(*this).push_back(T());
std::partial_sum(begin, end, std::back_inserter(*this));
}
T sum(std::size_t l, std::size_t r) {
return (*this)[r] - (*this)[l];
}
};
} // namespace zawa
#line 2 "src/template/accum1d.hpp"
#include <vector>
#include <numeric>
namespace zawa {
template <class T>
struct accum1d : std::vector<T> {
using vector = std::vector<T>;
accum1d() {
(*this).push_back(T());
}
accum1d(const std::vector<T>& A) {
(*this).push_back(T());
std::partial_sum(A.begin(), A.end(), std::back_inserter(*this));
}
template <class InputIterator>
accum1d(InputIterator begin, InputIterator end) {
(*this).push_back(T());
std::partial_sum(begin, end, std::back_inserter(*this));
}
T sum(std::size_t l, std::size_t r) {
return (*this)[r] - (*this)[l];
}
};
} // namespace zawa