proconlib

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

View the Project on GitHub anqooqie/proconlib

:heavy_check_mark: Find $b$ from $a$ when $b_i = \sum_{j = i}^{N - 1} a_j$ holds (tools/greater_equal_zeta.hpp)

(1)
template <typename InputIterator, typename OutputIterator>
void greater_equal_zeta(InputIterator begin, InputIterator end, OutputIterator result);

(2)
template <typename RandomAccessIterator>
void greater_equal_zeta(RandomAccessIterator begin, RandomAccessIterator end);

The following relationship holds between $a$ and $b$.

\[\begin{align*} b_i &= \sum_{i \leq j < N} a_j \end{align*}\]

Constraints

Time Complexity

License

Author

Verified with

Code

#ifndef TOOLS_GREATER_EQUAL_ZETA_HPP
#define TOOLS_GREATER_EQUAL_ZETA_HPP

#include <iterator>
#include <vector>
#include <algorithm>

namespace tools {
  template <typename RandomAccessIterator>
  void greater_equal_zeta(const RandomAccessIterator begin, const RandomAccessIterator end) {
    const int N = end - begin;
    for (int i = N - 2; i >= 0; --i) {
      begin[i] += begin[i + 1];
    }
  }

  template <typename InputIterator, typename OutputIterator>
  void greater_equal_zeta(const InputIterator begin, const InputIterator end, const OutputIterator result) {
    using T = typename ::std::iterator_traits<InputIterator>::value_type;
    ::std::vector<T> a(begin, end);
    ::tools::greater_equal_zeta(a.begin(), a.end());
    ::std::move(a.begin(), a.end(), result);
  }
}

#endif
#line 1 "tools/greater_equal_zeta.hpp"



#include <iterator>
#include <vector>
#include <algorithm>

namespace tools {
  template <typename RandomAccessIterator>
  void greater_equal_zeta(const RandomAccessIterator begin, const RandomAccessIterator end) {
    const int N = end - begin;
    for (int i = N - 2; i >= 0; --i) {
      begin[i] += begin[i + 1];
    }
  }

  template <typename InputIterator, typename OutputIterator>
  void greater_equal_zeta(const InputIterator begin, const InputIterator end, const OutputIterator result) {
    using T = typename ::std::iterator_traits<InputIterator>::value_type;
    ::std::vector<T> a(begin, end);
    ::tools::greater_equal_zeta(a.begin(), a.end());
    ::std::move(a.begin(), a.end(), result);
  }
}


Back to top page