zawatins-library

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

View the Project on GitHub zawa-tin/zawatins-library

:heavy_check_mark: accum1d (累積和)
(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>()

zawa::accum1d<T>(const std::vector<T>& A)

zawa::accum1d<T>(InputIterator begin, InputIterator end)

それぞれ計算量は: $O(\mid A\mid)$

メンバ関数

T sum(std::size_t l, std::size_t r)

std::vector<T>を継承しているので、std::vectorの機能がそのまま使えます。

メモ

TODO

Verified with

Code

#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
Back to top page