#include #include #include using namespace std; using namespace atcoder; using ll = long long; //#define endl "\n"; ll N, M, Q, A[200009], L[200009], R[200009], pos[200009]; using S = ll; S op(S a, S b) { return a+b; } S e() { return 0LL; } int main(){ cin >> N >> M; ll ans = 0; segtree seg(M + 1); fenwick_tree fw(M + 1); for(int i = 0; i < N; i++){ cin >> A[i] >> L[i] >> R[i]; L[i]--; ans += (R[i] - L[i]) * A[i]; pos[i] = i; seg.set(i, A[i]); fw.add(L[i], 1); fw.add(R[i], -1); } for(int i = 0; i < N; i++) ans -= seg.prod(L[i], R[i]); cin >> Q; for(int i = 1; i <= Q; i++){ ll x, y, l, r; cin >> x >> y >> l >> r; x--, y--, l--; ans -= (R[x] - L[x]) * A[x]; ll deg = fw.sum(0, pos[x] + 1); ans += A[x] * deg; fw.add(L[x], -1); fw.add(R[x], 1); seg.set(pos[x], 0); ans += seg.prod(L[x], R[x]); pos[x] = y; L[x] = l, R[x] = r; ans += (R[x] - L[x]) * A[x]; deg = fw.sum(0, pos[x] + 1); ans -= A[x] * deg; seg.set(pos[x], A[x]); fw.add(L[x], 1); fw.add(R[x], -1); ans -= seg.prod(L[x], R[x]); cout << ans << endl; } return 0; }