#define AUTO_GENERATED
// competitive-verifier: PROBLEM https://judge.yosupo.jp/problem/vertex_set_path_composite/
#include "../../../src/graph/ds/alist/lib.hpp"
#include "../../../src/tree/hld/lib.hpp"
#include "../../../src/tree/lca_hld/lib.hpp"
using namespace tifa_libs;
CEXP u32 MOD = 998244353;
#include "../../../src/math/ds/mint/bd/lib.hpp"
using namespace tifa_libs;
using mint = mint_bd<__LINE__>;
using Ty = mint;
using T = std::pair<Ty, Ty>;
using F = T;
using tree_t = tree<alist<>>;
CEXP auto op_ab(T a, T b) { // a(b(x))
return T{a.first * b.first, a.first * b.second + a.second};
}
CEXP auto op_ba(T a, T b) { // b(a(x))
return op_ab(b, a);
}
CEXP auto e() { return T{1, 0}; }
CEXP auto id() { return F{1, 0}; }
CEXP void mapping(T& x, F a) { x = a; }
CEXP void composition(F& x, F) { x = F{1, 0}; }
int main() {
mint::set_mod(MOD);
std::cin.tie(nullptr)->std::ios::sync_with_stdio(false);
u32 n, q;
std::cin >> n >> q;
vec<T> a(n);
for (auto& x : a) std::cin >> x.first >> x.second;
tree_t tr(n);
for (u32 i = 1, u, v; i < n; ++i) std::cin >> u >> v, tr.add_arc(u, v), tr.add_arc(v, u);
tifa_libs::lca_hld lca(tr);
tifa_libs::hld<tree_t, T, op_ba, F, mapping, composition> hld(e(), id(), tr, lca.info, a);
tifa_libs::hld<tree_t, T, op_ab, F, mapping, composition> hld1(e(), id(), tr, lca.info, a);
for (u32 i = 0, opt; i < q; ++i) {
std::cin >> opt;
if (opt == 0) {
u32 x;
Ty y, z;
std::cin >> x >> y >> z;
hld.node_update(x, F(y, z)), hld1.node_update(x, F(y, z));
} else {
u32 x, y;
Ty z;
std::cin >> x >> y >> z;
auto [retu, retv] = lca.getchain(x, y);
T ret1 = e(), ret2 = e();
for (auto x : retu) ret1 = op_ba(ret1, hld1.chain_query(x.first, x.second));
for (auto x : retv) ret2 = op_ba(ret2, hld.chain_query(x.first, x.second));
ret1 = op_ba(ret1, ret2);
std::cout << ret1.first * z + ret1.second << '\n';
}
}
return 0;
}
#line 1 "test/cpv/library-checker-tree/vertex_set_path_composite.mintd-bd.cpp"
#define AUTO_GENERATED
// competitive-verifier: PROBLEM https://judge.yosupo.jp/problem/vertex_set_path_composite/
#line 2 "src/graph/ds/alist/lib.hpp"
#line 2 "src/graph/ds/graph_c/lib.hpp"
#line 2 "src/util/traits/others/lib.hpp"
// clang-format off
#line 2 "src/util/alias/others/lib.hpp"
#line 2 "src/util/consts/lib.hpp"
#line 2 "src/util/alias/num/lib.hpp"
#line 2 "src/util/util/lib.hpp"
// https://github.com/Tiphereth-A/CP-lib
#include <bits/extc++.h>
// clang-format off
namespace tifa_libs {
#define CEXP constexpr
#define CEXPE constexpr explicit
#define CR const&
#define CP const*
#define PC *const
#define CPC const*const
#define TPN typename
#define NE noexcept
#define CNE const noexcept
#define ND [[nodiscard]]
#define cT_(...) std::conditional_t<sizeof(__VA_ARGS__) <= sizeof(size_t) * 2, __VA_ARGS__, __VA_ARGS__ CR>
// NOLINTNEXTLINE(misc-const-correctness)
#define flt_(T, i, l, r, ...) for (T i = (l), i##e = (r)__VA_OPT__(, ) __VA_ARGS__; i < i##e; ++i)
#define retif_(cond, if_true, ...) if cond return if_true __VA_OPT__(; else return __VA_ARGS__)
#ifdef ONLINE_JUDGE
#undef assert
#define assert(x) 42
#endif
using namespace std::ranges;
using namespace std::literals;
template <class T>
CEXP T abs(T x) NE { retif_((x < 0), -x, x); }
} // namespace tifa_libs
// clang-format on
#line 4 "src/util/alias/num/lib.hpp"
// clang-format off
namespace tifa_libs {
#define mk0_(w, t) using w = t; using c##w = const t
#define mk_(w, t) mk0_(w, t); CEXP w operator""_##w(unsigned long long x) NE { return (w)x; }
mk_(i8, int8_t) mk_(u8, uint8_t) mk_(i16, int16_t) mk_(u16, uint16_t) mk_(i32, int32_t) mk_(u32, uint32_t) mk_(i64, int64_t) mk_(u64, uint64_t) mk_(isz, ssize_t) mk_(usz, size_t) mk_(chr, char) mk_(schr, signed char) mk_(uchr, unsigned char) mk_(sint, signed) mk_(uint, unsigned);
mk0_(i128, __int128_t); mk0_(u128, __uint128_t); mk0_(f32, float); mk0_(f64, double); mk0_(f128, long double);
#undef mk0_
#undef mk_
} // namespace tifa_libs
// clang-format on
#line 4 "src/util/consts/lib.hpp"
// clang-format off
namespace tifa_libs {
using std::numbers::pi_v;
template <std::floating_point FP>
inline FP eps_v = std::sqrt(std::numeric_limits<FP>::epsilon());
template <std::floating_point FP>
CEXP void set_eps(FP v) NE { eps_v<FP> = v; }
CEXP u32 TIME = ((__TIME__[0] & 15) << 20) | ((__TIME__[1] & 15) << 16) | ((__TIME__[3] & 15) << 12) | ((__TIME__[4] & 15) << 8) | ((__TIME__[6] & 15) << 4) | (__TIME__[7] & 15);
CEXP auto STR2U16 = [] { std::array<u32, 65536> table{}; table.fill(-1_u32); flt_ (u32, i, 48, 58) flt_ (u32, j, 48, 58) table[i << 8 | j] = (j & 15) * 10 + (i & 15); return table; }();
inline const auto fn_0 = [](auto&&...) NE {};
inline const auto fn_is0 = [](auto x) NE { return x == 0; };
} // namespace tifa_libs
// clang-format on
#line 4 "src/util/alias/others/lib.hpp"
namespace tifa_libs {
template <class T>
struct chash {
CEXP static u64 C = u64(pi_v<f128> * 2e18) | 71;
CEXP u64 operator()(T x) CNE { return __builtin_bswap64(((u64)x ^ TIME) * C); }
};
// clang-format off
#define mk_(w, t) using w = t; using c##w = const t;
mk_(strn, std::string) mk_(strnv, std::string_view)
#undef mk_
template <class T> struct edge_t { T w; u32 u, v; CEXP auto operator<=>(edge_t CR) const = default; }; template <class T> using cedge_t = const edge_t<T>;
template <class T> struct pt3 { T _0, _1, _2; CEXP auto operator<=>(pt3 CR) const = default; }; template <class T> using cpt3 = const pt3<T>;
template <class T> struct pt4 { T _0, _1, _2, _3; CEXP auto operator<=>(pt4 CR) const = default; }; template <class T> using cpt4 = const pt4<T>;
#define mkT_(w, t, ...) template <class T> using w = t __VA_OPT__(, ) __VA_ARGS__; template <class T> using c##w = const t __VA_OPT__(, ) __VA_ARGS__;
mkT_(ptt, std::pair<T, T>) mkT_(alc, std::pmr::polymorphic_allocator<T>) mkT_(vec, std::vector<T>) mkT_(vvec, vec<vec<T>>) mkT_(v3ec, vvec<vec<T>>) mkT_(vecpt, vec<ptt<T>>) mkT_(vvecpt, vvec<ptt<T>>) mkT_(ptvec, ptt<vec<T>>) mkT_(ptvvec, ptt<vvec<T>>)
#undef mkT_
template <class T> using itl = std ::initializer_list<T>;
template <class T, usz ext = std::dynamic_extent> using spn = std::span<T const, ext>;
template <class T, usz N> using arr = std::array<T, N>; template <class T, usz N> using carr = std::array<const T, N>;
template <class U, class T> using vecp = vec<std::pair<U, T>>; template <class U, class T> using vvecp = vvec<std::pair<U, T>>;
template <class U, class T> using vvecp = vvec<std::pair<U, T>>; template <class U, class T> using vvvecp = vvec<vvec<std::pair<U, T>>>;
#ifdef PB_DS_ASSOC_CNTNR_HPP
template <class T, class C = std::less<T>> using set = __gnu_pbds::tree<T, __gnu_pbds::null_type, C>;
template <class K, class V, class C = std::less<K>> using map = __gnu_pbds::tree<K, V, C>;
// hset<u64> s({}, {}, {}, {}, {1<<16});
template <class T, class HF = chash<T>> using hset = __gnu_pbds::gp_hash_table<T, __gnu_pbds::null_type, HF>;
// hmap<u64, int> s({}, {}, {}, {}, {1<<16});
template <class K, class V, class HF = chash<K>> using hmap = __gnu_pbds::gp_hash_table<K, V, HF>;
#else
using std::set, std::map;
template <class T, class HF = chash<T>> using hset = std::unordered_set<T, HF>;
template <class K, class V, class HF = chash<K>> using hmap = std::unordered_map<K, V, HF>;
#endif
#ifdef PB_DS_PRIORITY_QUEUE_HPP
template <class T, class C = std::less<T>> using pq = __gnu_pbds::priority_queue<T, C>;
#else
template <class T, class C = std::less<T>> using pq = std::priority_queue<T, vec<T>, C>;
#endif
template <class T> using pqg = pq<T, std::greater<T>>;
// clang-format on
#define mk1_(V, A, T) using V##A = V<T>;
#define mk_(V, A, T) mk1_(V, A, T) mk1_(c##V, A, T)
#define mk(A, T) mk_(edge_t, A, T) mk_(ptt, A, T) mk_(pt3, A, T) mk_(pt4, A, T) mk_(vec, A, T) mk_(vvec, A, T) mk_(v3ec, A, T) mk_(vecpt, A, T) mk_(vvecpt, A, T) mk_(ptvec, A, T) mk_(ptvvec, A, T) mk1_(spn, A, T) mk1_(itl, A, T)
mk(b, bool) mk(c, chr) mk(i, i32) mk(u, u32) mk(ii, i64) mk(uu, u64) mk(t, isz) mk(z, usz) mk(f, f32) mk(d, f64) mk(s, strn);
#undef mk
#undef mk_
#undef mk1_
} // namespace tifa_libs
#line 4 "src/util/traits/others/lib.hpp"
namespace tifa_libs {
//! only for template without non-type argument
template <class, template <class...> class> CEXP bool specialized_from_v = false;
template <template <class...> class T, class... Args> CEXP bool specialized_from_v<T<Args...>, T> = true;
static_assert(specialized_from_v<vecu, std::vector>);
template <class T> concept container_c = common_range<T> && !std::is_array_v<std::remove_cvref_t<T>> && !std::same_as<std::remove_cvref_t<T>, strn> && !std::same_as<std::remove_cvref_t<T>, strnv>;
template <class T> concept istream_c = std::derived_from<T, std::istream> || std::derived_from<T, std::wistream> || requires(T is) { is.peek(); };
template <class T> concept ostream_c = std::derived_from<T, std::ostream> || std::derived_from<T, std::wostream> || requires(T os) { os.flush(); };
} // namespace tifa_libs
// clang-format on
#line 4 "src/graph/ds/graph_c/lib.hpp"
namespace tifa_libs {
namespace graph_info_impl_ {
struct graph_info_tag_base {};
template <class... Info>
requires(std::derived_from<Info, graph_info_tag_base> && ...)
struct graph_tag_base : Info... {
CEXP graph_tag_base(auto&&... args) NE : Info(std::forward<decltype(args)>(args)...)... {}
protected:
CEXP void add_arc(auto&&... args) NE { (Info::add_arc(std::forward<decltype(args)>(args)...), ...); }
CEXP void del_arc(auto&&... args) NE { (Info::del_arc(std::forward<decltype(args)>(args)...), ...); }
};
template <class T, class = std::is_void<T>::type>
struct E;
template <class T>
struct E<T, std::false_type> {
u32 to;
T cost;
CEXP E() = default;
CEXP E(u32 v, cT_(T) c) NE : to(v), cost(c) {}
CEXP operator u32() CNE { return to; }
};
template <class T>
struct E<T, std::true_type> {
u32 to;
CEXP E() = default;
CEXP E(u32 v) NE : to(v) {}
CEXP operator u32() CNE { return to; }
};
} // namespace graph_info_impl_
namespace graph_impl_ {
template <class etag_t>
struct graph : etag_t {
using Et = etag_t::val_t;
CEXP graph() = default;
CEXPE graph(u32 n, auto&&... e_args) NE : etag_t(n, std::forward<decltype(e_args)>(e_args)...) {}
CEXP void add_edge(u32 u, u32 v, auto&&... args) NE { etag_t::add_arc(u, v, std::forward<decltype(args)>(args)...), etag_t::add_arc(v, u, std::forward<decltype(args)>(args)...); }
template <class F>
CEXP void foreach(u32 u, F&& f) CNE {
if CEXP (std::is_void_v<Et>)
for (auto v : (*this)[u]) f(v);
else
for (auto [v, w] : (*this)[u]) f(v, w);
}
};
} // namespace graph_impl_
// clang-format off
#define CONCEPT_GRAPH(name, base) \
template <class T> concept name##_c = specialized_from_v<T, base>; \
template <class T> concept u##name##_c = name##_c<T> && std::same_as<TPN T::Et, void>; \
template <class T> concept w##name##_c = name##_c<T> && !std::same_as<TPN T::Et, void>
// clang-format on
CONCEPT_GRAPH(graph, graph_impl_::graph);
} // namespace tifa_libs
#line 4 "src/graph/ds/alist/lib.hpp"
namespace tifa_libs {
namespace alist_impl_ {
template <class T, class... Info>
class alist_tag : public graph_info_impl_::graph_tag_base<Info...> {
using base_t = graph_info_impl_::graph_tag_base<Info...>;
vvec<graph_info_impl_::E<T>> g;
protected:
using val_t = T;
CEXPE alist_tag(u32 n) NE : base_t(n), g(n) {}
public:
CEXP void build() CNE {}
CEXP void add_arc(u32 u, auto&&... args) NE { base_t::add_arc(u, std::forward<decltype(args)>(args)...), g[u].emplace_back(std::forward<decltype(args)>(args)...); }
ND CEXP u32 vsize() CNE { return (u32)g.size(); }
ND CEXP u32 deg_out(u32 u) CNE { return (u32)g[u].size(); }
CEXP auto CR operator[](u32 u) CNE { return g[u]; }
CEXP auto& operator[](u32 u) NE { return g[u]; }
};
} // namespace alist_impl_
template <class Et = void, class... Info>
using alist = graph_impl_::graph<alist_impl_::alist_tag<Et, Info...>>;
} // namespace tifa_libs
#line 2 "src/tree/hld/lib.hpp"
#line 2 "src/ds/segtree/hp/lib.hpp"
#line 4 "src/ds/segtree/hp/lib.hpp"
namespace tifa_libs {
namespace segtree_impl_ {
template <bool enable_tag, class T, auto op, class F, auto mapping, auto composition>
requires requires(T val, T new_val, F tag, F new_tag) {
{ op(val, new_val) } -> std::same_as<T>;
{ mapping(val, tag) } -> std::same_as<void>;
{ composition(tag, new_tag) } -> std::same_as<void>;
}
struct segtree {
const T E;
const F ID;
private:
u32 sz, lbn, n;
vec<T> val;
vec<F> tag;
vecb vset;
public:
CEXP segtree(cT_(T) e, cT_(F) id) NE : E(e), ID(id), sz(0), lbn(0), n(0), val{}, tag{}, vset{} {}
template <class V>
CEXP segtree(cT_(T) e, cT_(F) id, V&& a) NE : segtree(e, id) { reset(std::forward<V>(a)); }
CEXP segtree(cT_(T) e, cT_(F) id, u32 n) NE : segtree(e, id) { reset(vec<T>(n, e)); }
template <class V>
CEXP void reset(V&& a) NE {
if (a.empty()) {
sz = lbn = n = 0, val.clear(), tag.clear(), vset.clear();
return;
}
sz = (u32)a.size(), lbn = (u32)std::bit_width(sz - 1), n = 1_u32 << lbn;
if (!n) return;
val = vec<T>(n * 2, E), copy(a, begin(val) + n);
if CEXP (enable_tag) tag = vec<F>(n, ID), vset = vecb(n);
for (u32 i = n - 1; i; --i) pushup(i);
}
//! 0-indexed, [l, r)
CEXP void update(u32 l, u32 r, cT_(F) v) NE { upd_set<true>(l, r, v); }
//! 0-indexed, [l, r)
// set(3, 7, v): val[[3, 4), [4, 6), [6, 7)] <- v
//! val[[4, 6)] != op(val[[3, 4)], val[[6, 7)])
CEXP void set(u32 l, u32 r, cT_(F) v) NE { upd_set<false>(l, r, v); }
//! 0-indexed, [l, r)
CEXP T query(u32 l, u32 r) NE {
if (assert(l <= r && r <= sz); l == r) return E;
l += n, r += n;
cu32 zl = (u32)std::countr_zero(l), zr = (u32)std::countr_zero(r), ie = (u32)max(1, (i32)min(zl, zr));
for (u32 i = lbn; i >= ie; --i) {
if (zl < i) pushdown(l >> i);
if (zr < i) pushdown((r - 1) >> i);
}
T ql = E, qr = E;
while (l < r) {
if (l & 1) ql = op(ql, val[l++]);
if (r & 1) qr = op(val[--r], qr);
l /= 2, r /= 2;
}
return op(ql, qr);
}
CEXP void update(u32 x, cT_(F) v) NE { upd_set<true>(x, v); }
CEXP void set(u32 x, cT_(T) v) NE { upd_set<false>(x, v); }
CEXP T query(u32 x) NE {
assert(x < sz), x += n;
for (u32 i = lbn; i; --i) pushdown(x >> i);
return val[x];
}
template <class G>
requires requires(G check, T val) {
{ check(val) } -> std::same_as<bool>;
}
CEXP u32 max_right(u32 l, G&& chk) NE {
if (assert(l <= sz && chk(ID)); l == n) return n;
l += n;
for (u32 i = lbn; i; --i) pushdown(l >> i);
T _ = E;
do {
if (!chk(op(_, val[l >>= std::countr_zero(l)]))) {
while (l < n)
if (pushdown(l), l *= 2; chk(op(_, val[l]))) _ = op(_, val[l++]);
return l - n;
}
_ = op(_, val[l++]);
} while (!std::has_single_bit(l));
return sz;
}
template <class G>
requires requires(G check, T val) {
{ check(val) } -> std::same_as<bool>;
}
CEXP u32 min_left(u32 r, G chk) NE {
if (assert(r <= sz && chk(ID)); !r) return 0;
r += n;
for (u32 i = lbn; i; --i) pushdown((r - 1) >> i);
T _ = E;
do {
if (!(--r, r >>= std::countr_one(r))) r = 1;
if (!chk(op(val[r], _))) {
while (r < n)
if (pushdown(r), r = r * 2 + 1; chk(op(val[r], _))) _ = op(val[r--], _);
return r + 1 - n;
}
_ = op(val[r], _);
} while (!std::has_single_bit(r));
return 0;
}
private:
CEXP void compose(F& a, cT_(F) b) CNE {
if (a == ID) a = b;
else composition(a, b);
}
CEXP void pushup(u32 x) NE { val[x] = op(val[x * 2], val[x * 2 + 1]); }
template <bool upd>
CEXP void apply(u32 x, std::conditional_t<upd, cT_(F), cT_(T)> f) NE {
if CEXP (upd) {
if (f == ID) return;
if CEXP (mapping(val[x], f); enable_tag)
if (x < n) compose(tag[x], f);
} else if CEXP (val[x] = f; enable_tag)
if (x < n) tag[x] = ID, vset[x] = true;
}
CEXP void pushdown(u32 x) NE {
if CEXP (enable_tag) {
if (vset[x]) {
val[x * 2] = val[x * 2 + 1] = val[x];
if (x * 2 < n) tag[x * 2] = tag[x * 2 + 1] = ID, vset[x * 2] = vset[x * 2 + 1] = true;
vset[x] = false;
} else if (tag[x] != ID) {
mapping(val[x * 2], tag[x]), mapping(val[x * 2 + 1], tag[x]);
if (x * 2 < n) compose(tag[x * 2], tag[x]), compose(tag[x * 2 + 1], tag[x]);
tag[x] = ID;
}
}
}
template <bool upd>
CEXP void upd_set(u32 l, u32 r, std::conditional_t<upd, cT_(F), cT_(T)> v) NE {
if (assert(l <= r && r <= sz); l == r) return;
l += n, r += n;
cu32 zl = (u32)std::countr_zero(l), zr = (u32)std::countr_zero(r), zm = min(zl, zr), ie = (u32)max(1, (i32)zm);
for (u32 i = lbn; i >= ie; --i) {
if (zl < i) pushdown(l >> i);
if (zr < i) pushdown((r - 1) >> i);
}
u32 l2 = l, r2 = r;
while (l2 < r2) {
if (l2 & 1) apply<upd>(l2++, v);
if (r2 & 1) apply<upd>(--r2, v);
l2 /= 2, r2 /= 2;
}
flt_ (u32, i, zm + 1, lbn + 1) {
if (zl < i) pushup(l >> i);
if (zr < i) pushup((r - 1) >> i);
}
}
template <bool upd>
CEXP void upd_set(u32 x, std::conditional_t<upd, cT_(F), cT_(T)> v) NE {
assert(x < sz), x += n;
for (u32 i = lbn; i; --i) pushdown(x >> i);
if CEXP (upd) mapping(val[x], v);
else val[x] = v;
flt_ (u32, i, 1, lbn + 1) pushup(x >> i);
}
};
} // namespace segtree_impl_
template <class T, auto op, class F, auto mapping, auto composition>
using segtree = segtree_impl_::segtree<true, T, op, F, mapping, composition>;
template <class T, auto op, auto mapping>
class segtree_notag : public segtree_impl_::segtree<false, T, op, T, mapping, mapping> {
using base = segtree_impl_::segtree<false, T, op, T, mapping, mapping>;
public:
CEXPE segtree_notag(cT_(T) e) NE : base(e, e) {}
template <class V>
CEXP segtree_notag(cT_(T) e, V&& a) NE : base(e, e, std::forward<V>(a)) {}
CEXP segtree_notag(cT_(T) e, u32 n) NE : base(e, e, n) {}
};
} // namespace tifa_libs
#line 2 "src/tree/dfs/info/lib.hpp"
#line 2 "src/tree/ds/lib.hpp"
#line 4 "src/tree/ds/lib.hpp"
namespace tifa_libs {
template <graph_c graph_t>
struct tree : graph_t {
u32 root;
CEXP tree(graph_t CR g, u32 root = 0) NE : graph_t(g), root(root) {}
CEXP tree(graph_t&& g, u32 root = 0) NE : graph_t(std::move(g)), root(root) {}
CEXPE tree(u32 n, u32 root = 0) NE : graph_t(n), root(root) {}
};
CONCEPT_GRAPH(tree, tree);
} // namespace tifa_libs
#line 5 "src/tree/dfs/info/lib.hpp"
namespace tifa_libs {
struct tdi_dfn {
vecu dfn;
protected:
u32 cnt{0};
CEXPE tdi_dfn(u32 n) NE : dfn(n) {}
void init(u32 u, u32) NE { dfn[u] = cnt++; }
void pre_dfs(u32, u32, auto) NE {}
void post_dfs(u32, u32, auto) NE {}
void before_return(u32, u32) NE {}
};
struct tdi_sz {
vecu sz;
protected:
CEXPE tdi_sz(u32 n) NE : sz(n) {}
void init(u32 u, u32) NE { sz[u] = 1; }
void pre_dfs(u32, u32, auto) NE {}
void post_dfs(u32 to, u32 u, auto) NE { sz[u] += sz[to]; }
void before_return(u32, u32) NE {}
};
struct tdi_fa {
vecu fa;
protected:
CEXPE tdi_fa(u32 n) NE : fa(n) {}
void init(u32 u, u32 f) NE { fa[u] = f; }
void pre_dfs(u32, u32, auto) NE {}
void post_dfs(u32, u32, auto) NE {}
void before_return(u32, u32) NE {}
};
struct tdi_dep {
vecu dep;
protected:
CEXPE tdi_dep(u32 n) NE : dep(n) {}
void init(u32, u32) NE {}
void pre_dfs(u32 to, u32 u, auto) NE { dep[to] = dep[u] + 1; }
void post_dfs(u32, u32, auto) NE {}
void before_return(u32, u32) NE {}
};
struct tdi_maxson : tdi_sz {
vecu maxson;
protected:
CEXPE tdi_maxson(u32 n) NE : tdi_sz(n), maxson(n, n) {}
void init(u32 u, u32 f) NE { tdi_sz::init(u, f); }
void pre_dfs(u32 to, u32 u, auto w) NE { tdi_sz::pre_dfs(to, u, w); }
void post_dfs(u32 to, u32 u, auto w) NE {
if (tdi_sz::post_dfs(to, u, w); maxson[u] == (u32)maxson.size() || sz[to] > sz[maxson[u]]) maxson[u] = to;
}
void before_return(u32 u, u32 f) NE { tdi_sz::before_return(u, f); }
};
struct tdi_maxdfn {
vecu maxdfn;
protected:
u32 cnt{0};
CEXPE tdi_maxdfn(u32 n) NE : maxdfn(n) {}
void init(u32, u32) NE { ++cnt; }
void pre_dfs(u32, u32, auto) NE {}
void post_dfs(u32, u32, auto) NE {}
void before_return(u32 u, u32) NE { maxdfn[u] = cnt - 1; }
};
struct tdi_euler {
vecu euler;
protected:
u32 cnt{0};
CEXPE tdi_euler(u32 n) NE : euler(n) {}
void init(u32 u, u32) NE { euler[cnt++] = u; }
void pre_dfs(u32, u32, auto) NE {}
void post_dfs(u32, u32, auto) NE {}
void before_return(u32, u32) NE {}
};
struct tdi_go {
vvecu go;
protected:
CEXP static u32 N = 21;
CEXPE tdi_go(u32 n) NE : go(n, vecu(N, n)) { assert(n < 1u << N); }
void init(u32 u, u32 f) NE {
go[u][0] = f;
for (u32 i = 1; i < N && go[u][i - 1] < go.size(); ++i) go[u][i] = go[go[u][i - 1]][i - 1];
}
void pre_dfs(u32, u32, auto) NE {}
void post_dfs(u32, u32, auto) NE {}
void before_return(u32, u32) NE {}
};
template <tree_c G>
struct tdi_dis {
using w_t = std::conditional_t<std::is_void_v<TPN G::Et>, u32, TPN G::Et>;
vec<w_t> dis;
protected:
CEXPE tdi_dis(u32 n) NE : dis(n) {}
void init(u32, u32) NE {}
void pre_dfs(u32 to, u32 u, auto w) NE { dis[to] = dis[u] + w; }
void post_dfs(u32, u32, auto) NE {}
void before_return(u32, u32) NE {}
};
template <tree_c G, class... Ts>
struct tree_dfs_info : Ts... {
using w_t = std::conditional_t<std::is_void_v<TPN G::Et>, u32, TPN G::Et>;
CEXPE tree_dfs_info(G CR tree) : Ts(tree.vsize())... { dfs(tree, tree.root); }
private:
void dfs(G CR g, u32 u, u32 fa = -1_u32) NE {
if CEXP ((Ts::init(u, fa), ...); wtree_c<G>) {
for (auto [v, w] : g[u])
if (v != fa) (Ts::pre_dfs(v, u, w), ...), dfs(g, v, u), (Ts::post_dfs(v, u, w), ...);
} else
for (auto v : g[u])
if ((u32)v != fa) (Ts::pre_dfs((u32)v, u, 1), ...), dfs(g, (u32)v, u), (Ts::post_dfs((u32)v, u, 1), ...);
(Ts::before_return(u, fa), ...);
}
};
} // namespace tifa_libs
#line 2 "src/tree/dfs/top/lib.hpp"
#line 5 "src/tree/dfs/top/lib.hpp"
namespace tifa_libs {
template <tree_c G, bool need_dfn = false>
CEXP vecu tree_top(G CR tr, std::conditional_t<need_dfn, vecu&, spnu> dfn, spnu maxson) NE {
cu32 n = tr.vsize();
if CEXP (need_dfn) dfn = vecu(n);
vecu top(n, n);
u32 cnt = 0; // NOLINT(misc-const-correctness)
auto f = [&](auto&& f, u32 u, u32 top_) NE -> void {
if CEXP (need_dfn) dfn[u] = cnt++;
if (top[u] = top_; maxson[u] == tr.vsize()) return;
for (f(f, maxson[u], top_); auto v : tr[u])
if (top[(u32)v] == tr.vsize()) f(f, (u32)v, (u32)v);
};
f(f, tr.root, tr.root);
return top;
}
} // namespace tifa_libs
#line 7 "src/tree/hld/lib.hpp"
namespace tifa_libs {
namespace hld_impl_ {
template <bool enable_tag, tree_c tree_t, class T, auto op, class F, auto mapping, auto composition>
class hld {
segtree_impl_::segtree<enable_tag, T, op, F, mapping, composition> t;
public:
using tree_info_t = tree_dfs_info<tree_t, tdi_dfn, tdi_maxson, tdi_dep, tdi_fa>;
tree_t CR tr;
tree_info_t info;
vecu top;
CEXP hld(cT_(T) e, cT_(F) id, tree_t CR tr, tree_info_t CR info_) NE : t(e, id), tr(tr), info{info_}, top(tree_top<tree_t, true>(tr, info.dfn, info.maxson)) {}
CEXP hld(cT_(T) e, cT_(F) id, tree_t CR tr) NE : hld(e, id, tr, tree_info_t(tr)) {}
CEXP hld(cT_(T) e, cT_(F) id, tree_t CR tr, tree_info_t CR info_, spn<T> a) NE : hld(e, id, tr, info_) {
vec<T> b(a.size());
flt_ (u32, i, 0, (u32)a.size()) b[info.dfn[i]] = a[i];
build(b);
}
CEXP hld(tree_t CR tr, spn<T> a) NE : hld(tr, tree_info_t(tr), a) {}
CEXP void build(spn<T> a) NE { t.reset(a); }
CEXP void chain_update(u32 u, u32 v, cT_(F) f) NE {
while (top[u] != top[v]) {
if (info.dep[top[u]] < info.dep[top[v]]) swap(u, v);
t.update(info.dfn[top[u]], info.dfn[u] + 1, f);
u = info.fa[top[u]];
}
if (info.dfn[u] < info.dfn[v]) swap(u, v);
t.update(info.dfn[v], info.dfn[u] + 1, f);
}
CEXP void subtree_update(u32 u, cT_(F) f) NE { t.update(info.dfn[u], info.dfn[u] + info.sz[u], f); }
CEXP void node_update(u32 u, cT_(F) f) NE { t.update(info.dfn[u], f); }
CEXP void chain_set(u32 u, u32 v, cT_(T) f) NE {
while (top[u] != top[v]) {
if (info.dep[top[u]] < info.dep[top[v]]) swap(u, v);
t.set(info.dfn[top[u]], info.dfn[u] + 1, f), u = info.fa[top[u]];
}
if (info.dfn[u] < info.dfn[v]) swap(u, v);
t.set(info.dfn[v], info.dfn[u] + 1, f);
}
CEXP void subtree_set(u32 u, cT_(T) f) NE { t.set(info.dfn[u], info.dfn[u] + info.sz[u], f); }
CEXP void node_set(u32 u, cT_(T) f) NE { t.set(info.dfn[u] + 1, f); }
CEXP T chain_query(u32 u, u32 v) NE {
T ret = t.E;
while (top[u] != top[v]) {
if (info.dep[top[u]] < info.dep[top[v]]) swap(u, v);
ret = op(ret, t.query(info.dfn[top[u]], info.dfn[u] + 1)), u = info.fa[top[u]];
}
if (info.dfn[u] < info.dfn[v]) swap(u, v);
return op(ret, t.query(info.dfn[v], info.dfn[u] + 1));
}
CEXP T subtree_query(u32 u) NE { return t.query(info.dfn[u], info.dfn[u] + info.sz[u]); }
CEXP T node_query(u32 u) NE { return t.query(info.dfn[u]); }
};
} // namespace hld_impl_
template <tree_c tree_t, class T, auto op, class F, auto mapping, auto composition>
using hld = hld_impl_::hld<true, tree_t, T, op, F, mapping, composition>;
template <tree_c tree_t, class T, auto op, auto mapping>
class hld_notag : public hld_impl_::hld<false, tree_t, T, op, T, mapping, mapping> {
using base = hld_impl_::hld<false, tree_t, T, op, T, mapping, mapping>;
public:
CEXP hld_notag(cT_(T) e, tree_t CR tr, base::tree_info_t CR info) NE : base(e, e, tr, info) {}
template <class V>
CEXP hld_notag(cT_(T) e, tree_t CR tr) NE : base(e, e, tr) {}
CEXP hld_notag(cT_(T) e, tree_t CR tr, base::tree_info_t CR info, spn<T> a) NE : base(e, e, tr, info, a) {}
};
} // namespace tifa_libs
#line 2 "src/tree/lca_hld/lib.hpp"
#line 5 "src/tree/lca_hld/lib.hpp"
namespace tifa_libs {
template <tree_c G>
struct lca_hld {
using tree_info_t = tree_dfs_info<G, tdi_dfn, tdi_maxson, tdi_dep, tdi_fa>;
tree_info_t info;
vecu top;
CEXP lca_hld(G CR tr) : info{tr} { top = tree_top(tr, info.dfn, info.maxson); }
CEXP u32 operator()(u32 u, u32 v) CNE {
while (top[u] != top[v]) info.dep[top[u]] < info.dep[top[v]] ? v = info.fa[top[v]] : u = info.fa[top[u]];
retif_((info.dep[u] > info.dep[v]), v, u);
}
CEXP ptt<vecptu> getchain(u32 u, u32 v) NE {
u32 lca = (*this)(u, v);
vecptu retu, retv;
while (top[u] != top[lca]) retu.emplace_back(u, top[u]), u = info.fa[top[u]];
retu.emplace_back(u, lca);
while (top[v] != top[lca]) retv.emplace_back(top[v], v), v = info.fa[top[v]];
if (v != lca) retv.emplace_back(info.maxson[lca], v);
reverse(retv);
return {retu, retv};
}
};
} // namespace tifa_libs
#line 6 "test/cpv/library-checker-tree/vertex_set_path_composite.mintd-bd.cpp"
using namespace tifa_libs;
CEXP u32 MOD = 998244353;
#line 2 "src/math/ds/mint/bd/lib.hpp"
#line 2 "src/nt/mod/barrett/lib.hpp"
#line 4 "src/nt/mod/barrett/lib.hpp"
namespace tifa_libs {
template <u64 MOD, u64 B_ = 1>
struct barrett {
static CEXP u64 B = B_ % MOD, R = ((u128)B << 64) / MOD;
static CEXP u64 reduce(u64 a) NE {
if (u64 q = u64((u128)a * R >> 64); (a = a * B - q * MOD) >= MOD) a -= MOD;
return a;
}
};
template <> // dynamic
struct barrett<0> {
u64 mod, b, r;
CEXP barrett() NE = default;
CEXPE barrett(u64 mod, u64 b = 1) NE { reset(mod, b); }
CEXP void reset(u64 mod_, u64 b_ = 1) NE { assert(mod_), mod = mod_, b = b_ % mod, r = (u64(((u128)b << 64) / mod)); }
ND CEXP u64 reduce(u64 a) CNE {
if (cu64 q = u64((u128)a * r >> 64); (a = a * b - q * mod) >= mod) a -= mod;
return a;
}
};
} // namespace tifa_libs
#line 2 "src/math/ds/mint/_base/lib.hpp"
#line 2 "src/nt/inverse/lib.hpp"
#line 2 "src/nt/gl/inv_gcd/lib.hpp"
#line 2 "src/math/safe_mod/lib.hpp"
#line 2 "src/util/traits/math/lib.hpp"
// clang-format off
#line 4 "src/util/traits/math/lib.hpp"
namespace tifa_libs {
template <class T> concept char_c = std::same_as<T, char> || std::same_as<T, signed char> || std::same_as<T, unsigned char>;
#pragma GCC diagnostic ignored "-Wpedantic"
template <class T> concept s128_c = std::same_as<T, __int128_t> || std::same_as<T, __int128>;
template <class T> concept u128_c = std::same_as<T, __uint128_t> || std::same_as<T, unsigned __int128>;
template <class T> concept i128_c = s128_c<T> || u128_c<T>;
#pragma GCC diagnostic warning "-Wpedantic"
template <class T> concept imost64_c = std::integral<T> && sizeof(T) * __CHAR_BIT__ <= 64;
template <class T> concept smost64_c = imost64_c<T> && std::signed_integral<T>;
template <class T> concept umost64_c = imost64_c<T> && std::unsigned_integral<T>;
template <class T> concept int_c = i128_c<T> || imost64_c<T>;
template <class T> concept sint_c = s128_c<T> || smost64_c<T>;
template <class T> concept uint_c = u128_c<T> || umost64_c<T>;
template <class T> concept arithm_c = std::is_arithmetic_v<T> || int_c<T>;
template <class T> concept mint_c = requires(T x) { {x.mod()} -> uint_c; {x.val()} -> uint_c; };
template <class T> concept dft_c = requires(T x, std::vector<TPN T::data_t> v, u32 n) { {x.size()} -> std::same_as<u32>; x.bzr(n); x.dif(v, n); x.dit(v, n); };
template <class T> concept ntt_c = dft_c<T> && requires(T x) { T::max_size; T::G; };
template <class T> struct to_sint : std::make_signed<T> {};
template <> struct to_sint<u128> { using type = i128; };
template <> struct to_sint<i128> { using type = i128; };
template <class T> using to_sint_t = TPN to_sint<T>::type;
template <class T> struct to_uint : std::make_unsigned<T> {};
template <> struct to_uint<u128> { using type = u128; };
template <> struct to_uint<i128> { using type = u128; };
template <class T> using to_uint_t = TPN to_uint<T>::type;
template <arithm_c T> struct to_bigger : std::make_unsigned<T> {};
#define _(w,ww) template <> struct to_bigger<w> { using type = ww; }
#define _2(w,ww) _(i##w,i##ww); _(u##w,u##ww);
_2(8, 16); _2(16, 32); _2(32, 64); _2(64, 128); _(f32, f64); _(f64, f128);
#undef _2
#undef _
template <class T> using to_bigger_t = TPN to_bigger<T>::type;
template <arithm_c T> CEXP T inf_v = [] {
if CEXP(sint_c<T>) return T(to_uint_t<T>(-1) / 4 - 1);
else if CEXP(uint_c<T>) return T(-1) / 2 - 1;
else return std::numeric_limits<T>::max() / 2 - 1;
}();
} // namespace tifa_libs
// clang-format on
#line 4 "src/math/safe_mod/lib.hpp"
namespace tifa_libs {
template <int_c T>
CEXP T safe_mod(T x, to_uint_t<T> mod) NE {
if CEXP (sint_c<T>) {
if (x <= -(T)mod || x >= (T)mod) x %= (T)mod;
retif_((x < 0), x + (T)mod, x);
} else {
retif_((x >= mod), x % mod, x);
}
}
} // namespace tifa_libs
#line 2 "src/nt/gl/exgcd/lib.hpp"
#line 4 "src/nt/gl/exgcd/lib.hpp"
namespace tifa_libs {
// Binary exgcd
template <uint_c U, bool only_x = false>
CEXP auto exgcd_b(U a, U b) NE {
using T = to_sint_t<U>;
if CEXP (only_x) {
if (!a) return std::make_tuple(b, (T)0);
if (!b) return std::make_tuple(a, (T)1);
} else {
if (!a) return std::make_tuple(b, (T)0, (T) !!b);
if (!b) return std::make_tuple(a, (T)1, (T)0);
}
auto r = std::__countr_zero(a | b);
a >>= r, b >>= r;
T x = (T)a, y = (T)b, s = 1, t = 0, u = 0, v = 1;
while (x) {
while (!(x & 1))
if (x /= 2; !((s | t) & 1)) s /= 2, t /= 2;
else s = (s + (T)b) / 2, t = (t - (T)a) / 2;
while (!(y & 1))
if (y /= 2; !((u | v) & 1)) u /= 2, v /= 2;
else u = (u + (T)b) / 2, v = (v - (T)a) / 2;
if (x >= y) x -= y, s -= u, t -= v;
else y -= x, u -= s, v -= t;
}
if (y > 1) a /= (U)y, b /= (U)y;
if (a && (U)abs(v) >= a) {
const T _ = v / (T)a;
v -= _ * (T)a, u += _ * (T)b;
}
if (b && (U)abs(u) >= b) {
const T _ = u / (T)b;
u -= _ * (T)b, v += _ * (T)a;
}
if (const T u_ = u + (T)b, v_ = v - (T)a; abs(u_) + abs(v_) <= abs(u) + abs(v)) u = u_, v = v_;
if (const T u_ = u - (T)b, v_ = v + (T)a; abs(u_) + abs(v_) <= abs(u) + abs(v)) u = u_, v = v_;
if CEXP (only_x) return std::make_tuple(U(y << r), u);
else return std::make_tuple(U(y << r), u, v);
}
// @return then return tuple(g, x[, y]) s.t. g = gcd(a, b), xa + yb = g, |x| + |y| is the minimal (primary) and x <= y (secondarily)
template <sint_c T, bool only_x = false>
CEXP auto exgcd(T a, T b) NE {
using U = to_uint_t<T>;
if (auto [x, y] = minmax(a, b); x >= 0 && y <= T(U(-1) >> sizeof(U))) return exgcd_b<U, only_x>((U)a, (U)b);
if CEXP (only_x) {
T s = 1, u = 0;
while (b) {
T c = a / b;
std::tie(s, u, a, b) = std::make_tuple(u, s - u * c, b, a - b * c);
}
return std::make_tuple((U)a, s);
} else {
T s = 1, t = 0, u = 0, v = 1;
while (b) {
T c = a / b;
std::tie(s, t, u, v, a, b) = std::make_tuple(u, v, s - u * c, t - v * c, b, a - b * c);
}
return std::make_tuple((U)a, s, t);
}
}
} // namespace tifa_libs
#line 6 "src/nt/gl/inv_gcd/lib.hpp"
namespace tifa_libs {
template <uint_c T>
CEXP ptt<T> inv_gcd(T n, T mod) NE {
using U = to_sint_t<T>;
auto [g, x] = exgcd<U, true>(U(n % mod), (U)mod);
return {g, safe_mod(x, mod)};
}
} // namespace tifa_libs
#line 4 "src/nt/inverse/lib.hpp"
namespace tifa_libs {
// simple but slower: inv(n, mod) -> 1 < n ? mod - inv(mod % n, n) * mod / n : 1;
template <uint_c T, uint_c U>
CEXP U inverse(T n, U mod) NE {
auto [g, x] = inv_gcd(U(n % mod), mod);
assert(g == 1);
return x;
}
} // namespace tifa_libs
#line 5 "src/math/ds/mint/_base/lib.hpp"
namespace tifa_libs::mint_impl_ {
struct mint_tag_base {};
template <std::derived_from<mint_tag_base> tag_t>
struct mint : tag_t {
CEXP mint() = default;
CEXP mint(int_c auto v) NE : tag_t(v) {}
using raw_t = tag_t::raw_t;
using sraw_t = to_sint_t<raw_t>;
static CEXP sraw_t smod() NE { return (sraw_t)tag_t::mod(); }
ND CEXP sraw_t sval() CNE { return (sraw_t)tag_t::val(); }
template <int_c T>
CEXPE operator T() CNE { return (T)tag_t::val(); }
CEXP mint& operator+=(mint CR r) NE {
mint::add(r);
return *this;
}
CEXP mint& operator-=(mint CR r) NE {
mint::sub(r);
return *this;
}
CEXP mint& operator*=(mint CR r) NE {
mint::mul(r);
return *this;
}
CEXP mint& operator/=(mint CR r) NE { return *this = *this * r.inv(); }
CEXP mint CR operator+() CNE { return *this; }
CEXP mint operator-() CNE { return tag_t::template neg<mint>(); }
ND CEXP mint inv() CNE { return inverse(tag_t::val(), tag_t::mod()); }
friend CEXP mint operator+(mint l, mint CR r) NE { return l += r; }
friend CEXP mint operator-(mint l, mint CR r) NE { return l -= r; }
friend CEXP mint operator*(mint l, mint CR r) NE { return l *= r; }
friend CEXP mint operator/(mint l, mint CR r) NE { return l /= r; }
friend CEXP bool operator==(mint CR l, mint CR r) NE { return l.val() == r.val(); }
friend CEXP auto operator<=>(mint CR l, mint CR r) NE { return l.sval() <=> r.sval(); }
friend auto& operator>>(istream_c auto& is, mint& x) NE {
i64 _;
is >> _, x = mint(_);
return is;
}
friend auto& operator<<(ostream_c auto& os, mint CR x) NE { return os << x.val(); }
friend CEXP auto abs(mint CR x) NE { return x.val(); }
};
} // namespace tifa_libs::mint_impl_
#line 5 "src/math/ds/mint/bd/lib.hpp"
namespace tifa_libs {
template <i64 ID>
class mint_bd_tag : public mint_impl_::mint_tag_base {
static inline barrett<0> core;
public:
static CEXP bool FIXED_MOD = false;
static CEXP void set_mod(u32 m) NE { core.reset(m); }
protected:
using raw_t = u32;
raw_t v_{};
CEXP mint_bd_tag() NE = default;
CEXP mint_bd_tag(int_c auto v) NE : v_{mod(v)} {}
public:
static CEXP raw_t mod(sint_c auto v) NE {
if (v >= 0) return mod((to_uint_t<decltype(v)>)v);
if (auto ret = mod((to_uint_t<decltype(v)>)-v); ret) return mod() - ret;
else return ret;
}
static CEXP raw_t mod(uint_c auto v) NE {
if CEXP (umost64_c<decltype(v)>) return (raw_t)core.reduce((u64)v);
else if (v < UINT64_MAX) return (raw_t)core.reduce((u64)v);
else return raw_t(v % mod());
}
static CEXP raw_t mod() NE { return (raw_t)core.mod; }
ND CEXP raw_t val() CNE { return v_; }
CEXP raw_t& data() NE { return v_; }
protected:
template <class mint>
CEXP auto neg() CNE {
mint res;
if (v_) res.v_ = mod() - v_;
return res;
}
CEXP void add(mint_bd_tag CR r) NE {
if ((v_ += r.v_) >= mod()) v_ -= mod();
}
CEXP void sub(mint_bd_tag CR r) NE {
if (i32(v_ -= r.v_) < 0) v_ += mod();
}
CEXP void mul(mint_bd_tag CR r) NE { v_ = (raw_t)core.reduce(u64(v_) * r.v_); }
};
template <i64 ID>
using mint_bd = mint_impl_::mint<mint_bd_tag<ID>>;
} // namespace tifa_libs
#line 11 "test/cpv/library-checker-tree/vertex_set_path_composite.mintd-bd.cpp"
using namespace tifa_libs;
using mint = mint_bd<__LINE__>;
using Ty = mint;
using T = std::pair<Ty, Ty>;
using F = T;
using tree_t = tree<alist<>>;
CEXP auto op_ab(T a, T b) { // a(b(x))
return T{a.first * b.first, a.first * b.second + a.second};
}
CEXP auto op_ba(T a, T b) { // b(a(x))
return op_ab(b, a);
}
CEXP auto e() { return T{1, 0}; }
CEXP auto id() { return F{1, 0}; }
CEXP void mapping(T& x, F a) { x = a; }
CEXP void composition(F& x, F) { x = F{1, 0}; }
int main() {
mint::set_mod(MOD);
std::cin.tie(nullptr)->std::ios::sync_with_stdio(false);
u32 n, q;
std::cin >> n >> q;
vec<T> a(n);
for (auto& x : a) std::cin >> x.first >> x.second;
tree_t tr(n);
for (u32 i = 1, u, v; i < n; ++i) std::cin >> u >> v, tr.add_arc(u, v), tr.add_arc(v, u);
tifa_libs::lca_hld lca(tr);
tifa_libs::hld<tree_t, T, op_ba, F, mapping, composition> hld(e(), id(), tr, lca.info, a);
tifa_libs::hld<tree_t, T, op_ab, F, mapping, composition> hld1(e(), id(), tr, lca.info, a);
for (u32 i = 0, opt; i < q; ++i) {
std::cin >> opt;
if (opt == 0) {
u32 x;
Ty y, z;
std::cin >> x >> y >> z;
hld.node_update(x, F(y, z)), hld1.node_update(x, F(y, z));
} else {
u32 x, y;
Ty z;
std::cin >> x >> y >> z;
auto [retu, retv] = lca.getchain(x, y);
T ret1 = e(), ret2 = e();
for (auto x : retu) ret1 = op_ba(ret1, hld1.chain_query(x.first, x.second));
for (auto x : retv) ret2 = op_ba(ret2, hld.chain_query(x.first, x.second));
ret1 = op_ba(ret1, ret2);
std::cout << ret1.first * z + ret1.second << '\n';
}
}
return 0;
}