- Choose the aggregate stored for each interval or prefix.
- Build or initialize the structure from the input.
- Apply updates and combine the affected nodes to answer each query.
Code notes
- 59 lines of C++ from the credited upstream file yosupo-vertex-set-path-composite.test.cpp.
- The implementation visibly relies on sequence storage, ordered lookup.
- No explicit loop blocks detected.
Complexity
Count the build once, then multiply the logarithmic update or query path by the number of operations.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
1#define PROBLEM "https://judge.yosupo.jp/problem/vertex_set_path_composite"2 3#include "../../template/template.hpp"4 5#include "../../modint/montgomery-modint.hpp"6using mint = LazyMontgomeryModInt<998244353>;7using vm = vector<mint>;8using vvm = vector<vm>;9#include "../../modulo/binomial.hpp"10Binomial<mint> C;11 12#include "../../graph/graph-template.hpp"13#include "../../math/affine-transformation.hpp"14#include "../../segment-tree/segment-tree.hpp"15#include "../../tree/heavy-light-decomposition.hpp"1617using namespace Nyaan;18 19void Nyaan::solve() {20 ini(n, q);21 vm a(n), b(n);22 in2(a, b);23 auto g = graph(n, n - 1, false, false);24 25 HeavyLightDecomposition<vvi> hld(g);26 27 using af = Affine<mint>;28 auto m1 = [](af a_, af b_) { return a_ * b_; };29 auto m2 = [](af a_, af b_) { return b_ * a_; };30 SegmentTree<af, decltype(m1)> seg1(n, m1, af());31 SegmentTree<af, decltype(m2)> seg2(n, m2, af());32 33 rep(i, n) {34 int j = hld.idx(i).first;35 trc(j);36 seg1.set(j, af(a[i], b[i]));37 seg2.set(j, af(a[i], b[i]));38 }39 seg1.build(), seg2.build();40 41 rep(_, q) {42 ini(cmd, x, y, z);43 if (cmd == 0) {44 seg1.update(hld.idx(x).first, af(y, z));45 seg2.update(hld.idx(x).first, af(y, z));46 } else {47 mint ans = z;48 auto f = [&](int l, int r) {49 if (l <= r)50 ans = seg1.query(l, r)(ans);51 else52 ans = seg2.query(r, l)(ans);53 };54 hld.path_noncommutative_query(x, y, true, f);55 out(ans);56 }57 }58}59