#include #include using namespace std; using isize = size_t; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; using i128 = __int128_t; using u128 = __uint128_t; using f64 = long double; using p2 = pair; using el = tuple; using mint = atcoder::modint998244353; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(18); _main(); } i64 pow(i64 x, i64 n) { i64 res = 1; i64 t = x; while (n > 0) { if (n & 1) res *= t; t *= t; n >>= 1; } return res; } i64 op(i64 a, i64 b) {return a + b;} i64 e() {return 0;} p2 ops(p2 a, p2 b) {return {a.first + b.first, a.second + b.second};} p2 es() {return {0, 0};} p2 mpn(i64 f, p2 x) {return {x.first + f * x.second, x.second};} i64 cmp(i64 f, i64 g) {return f + g;} i64 idn() {return 0;} void _main() { i64 n, m; cin >> n >> m; atcoder::segtree segs(m); atcoder::lazy_segtree segc(m); vector alr(n); vector p(n); i64 ans = 0; for (i64 i = 0; i < m; i++) segc.set(i, {0, 1}); for (i64 i = 0; i < n; i++) { i64 a, l, r; cin >> a >> l >> r; l--; alr[i] = {a, l, r}; p[i] = i; segs.set(i, a); segc.apply(l, r, 1); ans += (r - l) * a; } for (i64 i = 0; i < m; i++) ans -= segc.get(i).first * segs.get(i); i64 q; cin >> q; for (;q--;) { i64 x, y, u, v; cin >> x >> y >> u >> v; x--, y--, u--; auto [a, l, r] = alr[x]; ans += a * segc.get(p[x]).first; ans -= a * segc.get(y).first; segs.set(p[x], 0); segs.set(y, a); p[x] = y; ans += segs.prod(l, r); ans -= (r - l) * a; segc.apply(l, r, -1); ans -= segs.prod(u, v); ans += (v - u) * a; segc.apply(u, v, 1); alr[x] = {a, u, v}; cout << ans << "\n"; } }