Skip to the content.

:heavy_check_mark: library/datastructure/SWAG.hpp

Depends on

Verified with

Code

#include "library/algebra/monoid/Concepts.hpp"

#pragma once
template <monoid M> class SWAG {
    using X = typename M::value_type;

    std::stack<X> back_stack,
        front_stack; // back は後ろの各要素 front は前の累積和
    X back_value;

    inline X front_value() const {
        return front_stack.size() ? front_stack.top() : M::unit();
    }

  public:
    SWAG() : back_value(M::unit()) {}
    void push_back(X x) {
        back_stack.push(x);
        M::Rchop(back_value, x);
    }
    void push_front(X x) { front_stack.push(M::op(x, front_value())); }
    void pop_front() {
        if (front_stack.empty()) {
            if (back_stack.empty())
                return;
            while (back_stack.size()) {
                push_front(back_stack.top());
                back_stack.pop();
            }
            back_value = M::unit();
        }
        front_stack.pop();
    }
    X prod() { return M::op(front_value(), back_value); }
    int size() { return back_stack.size() + front_stack.size(); }
};
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/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.14.0/x64/lib/python3.14/site-packages/onlinejudge_verify/languages/cplusplus.py", line 187, in bundle
    bundler.update(path)
    ~~~~~~~~~~~~~~^^^^^^
  File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/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: library/datastructure/SWAG.hpp: line 3: #pragma once found in a non-first line
Back to top page