This documentation is automatically generated by online-judge-tools/verification-helper
#define PROBLEM "https://judge.yosupo.jp/problem/aplusb"
#include <iostream>
#include "../../algebra/acted_monoid/acted_monoid_product_sum_add2.hpp"
#include "../../segment_tree/lazy_segment_tree.hpp"
#include "../../math/static_modint.hpp"
using mint = mint998;
std::vector<int> solve(std::vector<int>& a,
std::vector<int>& b,
std::vector<std::tuple<int, int, int, int>>& query) {
const int n = (int)(a.size());
std::vector<ProductSum<mint>> segi(n);
for (int i = 0; i < n; i++) {
segi[i] = {mint(a[i]) * mint(b[i]), mint(a[i]), mint(b[i])};
}
LazySegmentTree<ActedMonoidProductSumAdd2<mint>> seg(segi);
std::vector<int> ans;
for (auto&& [type, l, r, x] : query) {
l--;
if (type == 1) {
seg.apply(l, r, {x, 0});
} else if (type == 2) {
seg.apply(l, r, {0, x});
} else {
ans.push_back(seg.prod(l, r).ab.val());
}
}
return ans;
}
void test1_sample1() {
std::vector<int> a = {1, 3, 5, 6, 8};
std::vector<int> b = {3, 1, 2, 1, 2};
std::vector<std::tuple<int, int, int, int>> query = {
{3, 1, 3, -1}, {1, 2, 5, 3}, {3, 1, 3, -1},
{1, 1, 3, 1}, {2, 5, 5, 2}, {3, 1, 5, -1}};
std::vector<int> sol = {16, 25, 84};
assert(solve(a, b, query) == sol);
}
void test2_sample2() {
std::vector<int> a = {1000000000, 1000000000};
std::vector<int> b = {1000000000, 1000000000};
std::vector<std::tuple<int, int, int, int>> query = {
{3, 1, 1, -1}, {1, 2, 2, 1000000000}, {3, 1, 2, -1}};
std::vector<int> sol = {716070898, 151723988};
assert(solve(a, b, query) == sol);
}
int main() {
// https://atcoder.jp/contests/abc357/tasks/abc357_f
test1_sample1();
test2_sample2();
int a, b;
std::cin >> a >> b;
std::cout << a + b << '\n';
return 0;
}#line 1 "segment_tree/test/lazy_segment_tree_product_sum_add2.test.cpp"
#define PROBLEM "https://judge.yosupo.jp/problem/aplusb"
#include <iostream>
#line 2 "algebra/acted_monoid/acted_monoid_product_sum_add2.hpp"
// https://atcoder.jp/contests/abc357/tasks/abc357_f
template <class T> struct ProductSum {
T ab, a, b;
};
template <class T> struct MonoidProductSum {
using value_type = ProductSum<T>;
static constexpr value_type operation(const value_type& a,
const value_type& b) {
return {a.ab + b.ab, a.a + b.a, a.b + b.b};
}
static constexpr value_type identity() { return {T(0), T(0), T(0)}; }
};
template <class T> struct Add2 {
T a, b;
};
template <class T> struct MonoidAdd2 {
using value_type = Add2<T>;
static constexpr value_type operation(const value_type& f,
const value_type& g) {
return {f.a + g.a, f.b + g.b};
}
static constexpr value_type identity() { return {T(0), T(0)}; }
};
template <class T> struct ActedMonoidProductSumAdd2 {
using MS = MonoidProductSum<T>;
using MF = MonoidAdd2<T>;
using S = typename MS::value_type;
using F = typename MF::value_type;
static constexpr S mapping(const F f, const S x, const int size) {
return {x.ab + f.a * x.b + f.b * x.a + f.a * f.b * T(size),
x.a + f.a * T(size), x.b + f.b * T(size)};
}
};
#line 2 "segment_tree/lazy_segment_tree.hpp"
#line 2 "misc/bit_ceil.hpp"
#include <cassert>
#if __cplusplus >= 202002L
#include <bit>
#endif
// bit_ceil
// (0, 1, 2, 3, 4) -> (1, 1, 2, 4, 4)
#if __cplusplus >= 202002L
using std::bit_ceil;
#else
unsigned int bit_ceil(unsigned int x) {
unsigned int p = 1;
while (p < x) p *= 2;
return p;
}
unsigned long long int bit_ceil(unsigned long long int x) {
unsigned long long int p = 1;
while (p < x) p *= 2;
return p;
}
#endif
int bit_ceil(int x) {
assert(x >= 0);
return bit_ceil((unsigned int)(x));
}
long long int bit_ceil(long long int x) {
assert(x >= 0);
return bit_ceil((unsigned long long int)(x));
}
#line 2 "misc/countr_zero.hpp"
#if __cplusplus >= 202002L
#include <bit>
#endif
// countr_zero
// (000, 001, 010, 011, 100) -> (32, 0, 1, 0, 2)
#if __cplusplus >= 202002L
using std::countr_zero;
#else
int countr_zero(unsigned int x) {
return x == 0 ? 32 : __builtin_ctz(x);
}
int countr_zero(unsigned long long int x) {
return x == 0 ? 64 : __builtin_ctzll(x);
}
#endif
int countr_zero(int x) { return countr_zero((unsigned int)(x)); }
int countr_zero(long long int x) {
return countr_zero((unsigned long long int)(x));
}
#line 2 "misc/topbit.hpp"
#line 2 "misc/countl_zero.hpp"
#if __cplusplus >= 202002L
#include <bit>
#endif
// countl_zero
// (000, 001, 010, 011, 100) -> (32, 31, 30, 30, 29)
#if __cplusplus >= 202002L
using std::countl_zero;
#else
int countl_zero(unsigned int x) {
return x == 0 ? 32 : __builtin_clz(x);
}
int countl_zero(unsigned long long int x) {
return x == 0 ? 64 : __builtin_clzll(x);
}
#endif
int countl_zero(int x) { return countl_zero((unsigned int)(x)); }
int countl_zero(long long int x) {
return countl_zero((unsigned long long int)(x));
}
#line 4 "misc/topbit.hpp"
// topbit
// (000, 001, 010, 011, 100) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return 31 - countl_zero(x); }
int topbit(unsigned int x) { return 31 - countl_zero(x); }
int topbit(long long int x) { return 63 - countl_zero(x); }
int topbit(unsigned long long int x) { return 63 - countl_zero(x); }
#line 6 "segment_tree/lazy_segment_tree.hpp"
#line 8 "segment_tree/lazy_segment_tree.hpp"
#include <vector>
// Lazy Segment Tree
template <class AM> struct LazySegmentTree {
public:
using MS = typename AM::MS;
using MF = typename AM::MF;
using S = typename MS::value_type;
using F = typename MF::value_type;
LazySegmentTree() = default;
explicit LazySegmentTree(int n)
: LazySegmentTree(std::vector<S>(n, MS::identity())) {}
explicit LazySegmentTree(const std::vector<S>& v) : n((int)(v.size())) {
size = bit_ceil(n);
log = countr_zero(size);
d = std::vector<S>(size << 1, MS::identity());
lz = std::vector<F>(size, MF::identity());
for (int i = 0; i < n; i++) d[i + size] = v[i];
for (int i = size - 1; i >= 1; i--) {
update(i);
}
}
void set(int p, const S& x) {
assert(0 <= p and p < n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
d[p] = x;
for (int i = 1; i <= log; i++) update(p >> i);
}
void add(int p, const S& x) {
assert(0 <= p and p < n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
d[p] = MS::operation(d[p], x);
for (int i = 1; i <= log; i++) update(p >> i);
}
S operator[](int p) {
assert(0 <= p and p < n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
return d[p];
}
S get(int p) {
assert(0 <= p and p < n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
return d[p];
}
S prod(int l, int r) {
assert(0 <= l and l <= r and r <= n);
if (l == r) return MS::identity();
l += size;
r += size;
for (int i = log; i >= 1; i--) {
if (((l >> i) << i) != l) push(l >> i);
if (((r >> i) << i) != r) push((r - 1) >> i);
}
S sml = MS::identity(), smr = MS::identity();
while (l < r) {
if (l & 1) sml = MS::operation(sml, d[l++]);
if (r & 1) smr = MS::operation(d[--r], smr);
l >>= 1;
r >>= 1;
}
return MS::operation(sml, smr);
}
S all_prod() { return d[1]; }
void apply(int p, const F& f) {
assert(0 <= p and p < n);
p += size;
for (int i = log; i >= 1; i--) push(p >> i);
d[p] = AM::mapping(f, d[p], 1);
for (int i = 1; i <= log; i++) update(p >> i);
}
void apply(int l, int r, const F& f) {
assert(0 <= l and l <= r and r <= n);
if (l == r) return;
l += size;
r += size;
for (int i = log; i >= 1; i--) {
if (((l >> i) << i) != l) push(l >> i);
if (((r >> i) << i) != r) push((r - 1) >> i);
}
{
int l2 = l, r2 = r;
while (l < r) {
if (l & 1) all_apply(l++, f);
if (r & 1) all_apply(--r, f);
l >>= 1;
r >>= 1;
}
l = l2;
r = r2;
}
for (int i = 1; i <= log; i++) {
if (((l >> i) << i) != l) update(l >> i);
if (((r >> i) << i) != r) update((r - 1) >> i);
}
}
template <class G> int max_right(int l, G& g) {
assert(0 <= l and l <= n);
assert(g(MS::identity()));
if (l == n) return n;
l += size;
for (int i = log; i >= 1; i--) push(l >> i);
S sm = MS::identity();
do {
while ((l & 1) == 0) l >>= 1;
if (!g(MS::operation(sm, d[l]))) {
while (l < size) {
push(l);
l <<= 1;
if (g(MS::operation(sm, d[l]))) {
sm = MS::operation(sm, d[l]);
l++;
}
}
return l - size;
}
sm = MS::operation(sm, d[l]);
l++;
} while ((l & -l) != l);
return n;
}
template <class G> int min_left(int r, G& g) {
assert(0 <= r and r <= n);
assert(g(MS::identity()));
if (r == 0) return 0;
r += size;
for (int i = log; i >= 1; i--) push((r - 1) >> i);
S sm = MS::identity();
do {
r--;
while (r > 1 and (r & 1)) r >>= 1;
if (!g(MS::operation(d[r], sm))) {
while (r < size) {
push(r);
r = (r << 1) | 1;
if (g(MS::operation(d[r], sm))) {
sm = MS::operation(d[r], sm);
r--;
}
}
return r + 1 - size;
}
sm = MS::operation(d[r], sm);
} while ((r & -r) != r);
return 0;
}
std::vector<S> make_vector() {
std::vector<S> vec(n);
for (int i = 0; i < n; i++) vec[i] = get(i);
return vec;
}
private:
int n, log, size;
std::vector<S> d;
std::vector<F> lz;
inline void update(int k) {
d[k] = MS::operation(d[k << 1], d[(k << 1) | 1]);
}
void all_apply(int k, const F& f) {
d[k] = AM::mapping(f, d[k], 1 << (log - topbit(k)));
// MF::operation(f, g), g(f(x))
if (k < size) lz[k] = MF::operation(lz[k], f);
}
void push(int k) {
all_apply(k << 1, lz[k]);
all_apply((k << 1) | 1, lz[k]);
lz[k] = MF::identity();
}
};
#line 2 "math/static_modint.hpp"
#include <utility>
#line 5 "math/static_modint.hpp"
// constexpr ... for constexpr bool prime()
template <int m> struct StaticModint {
using mint = StaticModint;
unsigned int _v;
static constexpr int mod() { return m; }
static constexpr unsigned int umod() { return m; }
constexpr StaticModint() : _v(0) {}
template <class T> constexpr StaticModint(T v) {
long long x = (long long)(v % (long long)(umod()));
if (x < 0) x += umod();
_v = (unsigned int)(x);
}
constexpr unsigned int val() const { return _v; }
constexpr mint &operator++() {
_v++;
if (_v == umod()) _v = 0;
return *this;
}
constexpr mint &operator--() {
if (_v == 0) _v = umod();
_v--;
return *this;
}
constexpr mint operator++(int) {
mint result = *this;
++*this;
return result;
}
constexpr mint operator--(int) {
mint result = *this;
--*this;
return result;
}
constexpr mint &operator+=(const mint &rhs) {
_v += rhs._v;
if (_v >= umod()) _v -= umod();
return *this;
}
constexpr mint &operator-=(const mint &rhs) {
_v -= rhs._v;
if (_v >= umod()) _v += umod();
return *this;
}
constexpr mint &operator*=(const mint &rhs) {
unsigned long long z = _v;
z *= rhs._v;
_v = (unsigned int)(z % umod());
return *this;
}
constexpr mint &operator/=(const mint &rhs) { return (*this *= rhs.inv()); }
constexpr mint operator+() const { return *this; }
constexpr mint operator-() const { return mint() - *this; }
constexpr mint pow(long long n) const {
assert(n >= 0);
mint x = *this, r = 1;
while (n) {
if (n & 1) r *= x;
x *= x;
n >>= 1;
}
return r;
}
constexpr mint inv() const {
if (prime) {
assert(_v);
return pow(umod() - 2);
} else {
auto eg = inv_gcd(_v, m);
assert(eg.first == 1);
return eg.second;
}
}
friend constexpr mint operator+(const mint &lhs, const mint &rhs) { return mint(lhs) += rhs; }
friend constexpr mint operator-(const mint &lhs, const mint &rhs) { return mint(lhs) -= rhs; }
friend constexpr mint operator*(const mint &lhs, const mint &rhs) { return mint(lhs) *= rhs; }
friend constexpr mint operator/(const mint &lhs, const mint &rhs) { return mint(lhs) /= rhs; }
friend constexpr bool operator==(const mint &lhs, const mint &rhs) { return lhs._v == rhs._v; }
friend constexpr bool operator!=(const mint &lhs, const mint &rhs) { return lhs._v != rhs._v; }
friend std::ostream &operator<<(std::ostream &os, const mint &v) { return os << v.val(); }
static constexpr bool prime = []() -> bool {
if (m == 1) return false;
if (m == 2 || m == 7 || m == 61) return true;
if (m % 2 == 0) return false;
unsigned int d = m - 1;
while (d % 2 == 0) d /= 2;
for (unsigned int a : {2, 7, 61}) {
unsigned int t = d;
mint y = mint(a).pow(t);
while (t != m - 1 and y != 1 and y != m - 1) {
y *= y;
t <<= 1;
}
if (y != m - 1 and t % 2 == 0) {
return false;
}
}
return true;
}();
static constexpr std::pair<int, int> inv_gcd(int a, int b) {
if (a == 0) return {b, 0};
int s = b, t = a, m0 = 0, m1 = 1;
while (t) {
const int u = s / t;
s -= t * u;
m0 -= m1 * u;
std::swap(s, t);
std::swap(m0, m1);
}
if (m0 < 0) m0 += b / s;
return {s, m0};
}
};
using mint107 = StaticModint<1000000007>;
using mint998 = StaticModint<998244353>;
#line 8 "segment_tree/test/lazy_segment_tree_product_sum_add2.test.cpp"
using mint = mint998;
std::vector<int> solve(std::vector<int>& a,
std::vector<int>& b,
std::vector<std::tuple<int, int, int, int>>& query) {
const int n = (int)(a.size());
std::vector<ProductSum<mint>> segi(n);
for (int i = 0; i < n; i++) {
segi[i] = {mint(a[i]) * mint(b[i]), mint(a[i]), mint(b[i])};
}
LazySegmentTree<ActedMonoidProductSumAdd2<mint>> seg(segi);
std::vector<int> ans;
for (auto&& [type, l, r, x] : query) {
l--;
if (type == 1) {
seg.apply(l, r, {x, 0});
} else if (type == 2) {
seg.apply(l, r, {0, x});
} else {
ans.push_back(seg.prod(l, r).ab.val());
}
}
return ans;
}
void test1_sample1() {
std::vector<int> a = {1, 3, 5, 6, 8};
std::vector<int> b = {3, 1, 2, 1, 2};
std::vector<std::tuple<int, int, int, int>> query = {
{3, 1, 3, -1}, {1, 2, 5, 3}, {3, 1, 3, -1},
{1, 1, 3, 1}, {2, 5, 5, 2}, {3, 1, 5, -1}};
std::vector<int> sol = {16, 25, 84};
assert(solve(a, b, query) == sol);
}
void test2_sample2() {
std::vector<int> a = {1000000000, 1000000000};
std::vector<int> b = {1000000000, 1000000000};
std::vector<std::tuple<int, int, int, int>> query = {
{3, 1, 1, -1}, {1, 2, 2, 1000000000}, {3, 1, 2, -1}};
std::vector<int> sol = {716070898, 151723988};
assert(solve(a, b, query) == sol);
}
int main() {
// https://atcoder.jp/contests/abc357/tasks/abc357_f
test1_sample1();
test2_sample2();
int a, b;
std::cin >> a >> b;
std::cout << a + b << '\n';
return 0;
}