/* class segtree: def __init__(self,n): self.size=1 while self.size1: x//=2 self.dat[x]=(self.dat[2*x]+self.dat[2*x+1]) def querry(self,u,v): u+=self.size v+=self.size score=0 while u1: x//=2 self.dat[x]=(self.dat[2*x]+self.dat[2*x+1]) def querry(self,u,v): u+=self.size v+=self.size score=0 while u using namespace std; class segtree { public: int size; vector dat; segtree(int n) { size = 1; while (size < n) size *= 2; dat.assign(2 * size, 0); } void update(int x, long long a) { x += size; dat[x] = a; while (x > 1) { x /= 2; dat[x] = dat[2 * x] + dat[2 * x + 1]; } } long long querry(int u, int v) { u += size; v += size; long long score = 0; while (u < v) { if (u & 1) score += dat[u++]; if (v & 1) score += dat[--v]; u /= 2; v /= 2; } return score; } }; class segtree2 { public: int size; vector dat; segtree2(int n) { size = 1; while (size < n) size *= 2; dat.assign(2 * size, 0); } void update(int x, long long a) { x += size; dat[x] += a; while (x > 1) { x /= 2; dat[x] = dat[2 * x] + dat[2 * x + 1]; } } long long querry(int u, int v) { u += size; v += size; long long score = 0; while (u < v) { if (u & 1) score += dat[u++]; if (v & 1) score += dat[--v]; u /= 2; v /= 2; } return score; } }; int main() { int N, M; cin >> N >> M; segtree Zsum(M + 2); segtree2 Zcount(M + 2); vector> L; vector p(N); vector> h(N, vector(2)); vector T(N); for (int i = 0; i < N; ++i) { int a, l, r; cin >> a >> l >> r; Zsum.update(i + 1, a); Zcount.update(l, 1); Zcount.update(r + 1, -1); L.emplace_back(a, l, r); p[i] = a; h[i][0] = l; h[i][1] = r; T[i] = i + 1; } long long score = 0; for (int i = 0; i < N; ++i) { int a, l, r; tie(a, l, r) = L[i]; score += 1LL * a * (r - l + 1) - Zsum.querry(l, r + 1); } int Q; cin >> Q; while (Q--) { int pos, y, c, d; cin >> pos >> y >> c >> d; pos -= 1; int now = T[pos]; int a = p[pos]; int l = h[pos][0]; int r = h[pos][1]; h[pos][0] = c; h[pos][1] = d; score -= 1LL * a * (r - l + 1) - Zsum.querry(l, r + 1); Zcount.update(l, -1); Zcount.update(r + 1, 1); long long count = Zcount.querry(0, now + 1); score += count * a; Zsum.update(now, 0); Zsum.update(y, a); score += 1LL * a * (d - c + 1) - Zsum.querry(c, d + 1); count = Zcount.querry(0, y + 1); score -= count * a; Zcount.update(c, 1); Zcount.update(d + 1, -1); T[pos] = y; cout << score << '\n'; } return 0; }