#include #include #include #include #include #include using namespace atcoder; using namespace std; using ll = long long; using ull = unsigned long long; template using max_heap = priority_queue; template using min_heap = priority_queue, greater<>>; ll ll_min = numeric_limits::min(); ll ll_max = numeric_limits::max(); ll ALPHABET_N = 26; using mint = modint998244353; #define rep(i, n) for (ll i = (ll)0; i < (ll)n; i++) #define rep_(i, k, n) for (ll i = (ll)k; i < (ll)n; i++) #define all(a) a.begin(), a.end() struct S { long long value; int size; }; using F = long long; S op(S a, S b) { return {a.value + b.value, a.size + b.size}; } S e() { return {0, 0}; } S mapping(F f, S x) { return {x.value + f * x.size, x.size}; } F composition(F f, F g) { return f + g; } F id() { return 0; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, m; cin >> n >> m; lazy_segtree cnt_seg(m), a_seg(m); vector x2idx(m); rep(i, m) { cnt_seg.set(i, {0, 1}); a_seg.set(i, {0, 1}); x2idx[i] = i; } vector A(n), L(n), R(n); ll ans = 0; rep(i, n) { cin >> A[i] >> L[i] >> R[i]; L[i]--; cnt_seg.apply(L[i], R[i], 1); a_seg.set(i, {A[i], 1}); ans += A[i] * (R[i] - L[i]); } rep(i, m) { ll k = cnt_seg.get(i).value; ans -= a_seg.get(i).value * (k); } ll q; cin >> q; rep(_, q) { ll x, y, u, v; cin >> x >> y >> u >> v; x--; u--; y--; ll idx = x2idx[x]; x2idx[x] = y; ans -= A[x] * (R[x] - L[x]); ans += A[x] * (cnt_seg.get(idx).value - (L[x] <= idx && idx < R[x] ? 1 : 0)); ans += a_seg.prod(L[x], R[x]).value; cnt_seg.apply(L[x], R[x], -1); a_seg.set(idx, {0, 1}); L[x] = u; R[x] = v; cnt_seg.apply(L[x], R[x], 1); a_seg.set(y, {A[x], 1}); ans += A[x] * (R[x] - L[x]); ans -= A[x] * (cnt_seg.get(y).value - (L[x] <= y && y < R[x] ? 1 : 0)); ans -= a_seg.prod(L[x], R[x]).value; cout << ans << endl; } return 0; }