#include #include using namespace std; #define int long long using S = long long; using F = long long; const S INF = 8e18; S op(S a, S b){ return std::max(a, b); } S e(){ return -INF; } S mapping(F f, S x){ return f+x; } F composition(F f, F g){ return f+g; } F id(){ return 0; } class SegTree{ public: int dat[800999],siz = 1; void init(int N){ siz = 1; while(siz < N) siz *= 2; for(int i = 1; i < siz*2; i++) dat[i] = 0; } void update(int pos, int x){ pos = pos + siz - 1; dat[pos] += x; while(pos >= 1){ pos /= 2; dat[pos] = dat[pos * 2] + dat[pos * 2 + 1]; } } int query(int l, int r, int a, int b, int u){ if(r <= a || b <= l) return 0; if(l <= a && b <= r) return dat[u]; int m = (a + b) / 2; int ansl = query(l,r,a,m,u*2); int ansr = query(l,r,m,b,u*2+1); return ansl + ansr; } }; signed main(){ int N,M; cin>>N>>M; vector A(N+1); vector> B(N+1); vector C(N+1); std::vector v(M+10); atcoder::lazy_segtree seg(v); SegTree Z; Z.init(M+10); int ans = 0; for(int i = 1; i <= N; i++){ cin>>A[i]>>B[i].first>>B[i].second; ans += A[i] * (B[i].second - B[i].first + 1); Z.update(i,A[i]); C[i] = i; seg.apply(B[i].first,B[i].second+1,1); } for(int i = 1; i <= N; i++) ans -= Z.query(B[i].first,B[i].second+1,1,Z.siz+1,1); int Q; cin>>Q; for(int i = 0; i < Q; i++){ int x,y,u,v; cin>>x>>y>>u>>v; //引っ越し前 seg.apply(B[x].first,B[x].second+1,-1); ans += Z.query(B[x].first,B[x].second+1,1,Z.siz+1,1); ans -= A[x] * (B[x].second - B[x].first + 1); ans += seg.get(C[x]) * A[x]; Z.update(C[x],-A[x]); //後 C[x] = y; B[x].first = u; B[x].second = v; Z.update(C[x],A[x]); ans -= seg.get(C[x]) * A[x]; ans += A[x] * (B[x].second - B[x].first + 1); ans -= Z.query(B[x].first,B[x].second+1,1,Z.siz+1,1); seg.apply(B[x].first,B[x].second+1,1); cout << ans << "\n"; } }