library

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

View the Project on GitHub kk2a/library

:heavy_check_mark: fps/fps_sparsity_detector.hpp

Depends on

Required by

Verified with

Code

#ifndef KK2_FPS_FPS_SPARSITY_DETECTOR_HPP
#define KK2_FPS_FPS_SPARSITY_DETECTOR_HPP 1

#include "../bit/bitcount.hpp"

namespace kk2 {

enum class FPSOperation { CONVOLUTION };

template <class FPS, class mint = typename FPS::value_type>
bool is_sparse_operation(FPSOperation op, bool is_ntt_friendly, const FPS &a, const FPS &b) {
    int n = a.size(), m = b.size();
    long long not_zero_a = 0, not_zero_b = 0;
    for (int i = 0; i < n; i++) not_zero_a += a[i] != mint(0);
    for (int i = 0; i < m; i++) not_zero_b += b[i] != mint(0);

    if (op == FPSOperation::CONVOLUTION) {
        // NTT-friendly -> 3 * FFT
        // Arbitrary    -> 9 * FFT
        // Sparse       -> not_zero(a) * not_zero(b)
        int lg = msb(n + m) / 2 + 1;
        return (n + m) * lg * (is_ntt_friendly ? 3 : 7) > not_zero_a * not_zero_b;
    }
    return false;
}

} // namespace kk2

#endif // KK2_FPS_FPS_SPARSITY_DETECTOR_HPP
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/onlinejudge_verify/documentation/build.py", line 71, in _render_source_code_stat
    bundled_code = language.bundle(stat.path, basedir=basedir, options={'include_paths': [basedir]}).decode()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus.py", line 187, in bundle
    bundler.update(path)
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus_bundle.py", line 401, in update
    self.update(self._resolve(pathlib.Path(included), included_from=path))
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus_bundle.py", line 401, in update
    self.update(self._resolve(pathlib.Path(included), included_from=path))
  File "/opt/hostedtoolcache/Python/3.12.0/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/cplusplus_bundle.py", line 312, in update
    raise BundleErrorAt(path, i + 1, "#pragma once found in a non-first line")
onlinejudge_verify.languages.cplusplus_bundle.BundleErrorAt: type_traits/integral.hpp: line 4: #pragma once found in a non-first line
Back to top page