From 3204ce5c1e6ebe1b34c5f83854df91742b5349a7 Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Tue, 19 Aug 2025 19:26:00 +0800 Subject: [PATCH] update --- src/8/19/segmatrixdp.cpp | 92 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/8/19/segmatrixdp.cpp diff --git a/src/8/19/segmatrixdp.cpp b/src/8/19/segmatrixdp.cpp new file mode 100644 index 0000000..7f6450e --- /dev/null +++ b/src/8/19/segmatrixdp.cpp @@ -0,0 +1,92 @@ +#include +#include +#include +#include +#include + +using ll = int64_t; +const ll INF = INT_MAX; + +struct M22{ + std::vector> v{2,std::vector(2)}; + M22 operator*(const M22&o){ + M22 n; + n.v[0][0]=std::max(v[0][0]+o.v[0][0],v[0][1]+o.v[1][0]); + n.v[0][1]=std::max(v[0][0]+o.v[0][1],v[0][1]+o.v[1][1]); + n.v[1][0]=std::max(v[1][0]+o.v[0][0],v[1][1]+o.v[1][0]); + n.v[1][1]=std::max(v[1][0]+o.v[0][1],v[1][1]+o.v[1][1]); + return n; + } + M22&operator*=(const M22&o){ + *this= *this * o; + return *this; + } +}; +std::vector t; +std::vector nums; + +M22 create(ll l, ll r, ll idx) { + if (l == r) { + t[idx] = nums[l]; + return t[idx]; + } + ll mid = (l + r) / 2; + t[idx] = create(mid + 1, r, 2 * idx + 2)*create(l, mid, 2 * idx + 1); + return t[idx]; +} + +void update(ll l, ll r, ll idx, ll pos,const M22&val) { + if (l == r) { + t[idx] = val; + return; + } + ll mid = (l + r) / 2; + if (pos <= mid) { + update(l, mid, 2 * idx + 1, pos, val); + } else { + update(mid + 1, r, 2 * idx + 2, pos, val); + } + t[idx] = t[2 * idx + 2]*t[2 * idx + 1]; +} + +M22 query(ll cur,ll ql,ll qr,ll l,ll r){ + if(qr>n; + ll q; + std::cin>>q; + t.resize(4*n); + nums.resize(n); + std::vector a(n),b(n); + for(ll i=0; i>a[i]; + std::cin>>b[i]; + } + for(ll i=0;i>idx; + --idx; + std::cin>>a[idx]>>b[idx]; + update(0, n - 1, 0, idx, M22{{{a[idx],b[idx]},{0,INT_MIN}}}); + output(); + } + std::cin>>q; +} \ No newline at end of file