#include using namespace std; using ll = long long; using pll = pair; #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const ll MOD1000000007 = 1000000007; const ll MOD998244353 = 998244353; const ll MOD[3] = {999727999, 1070777777, 1000000007}; const ll LINF = 1LL << 60LL; const int IINF = (1 << 30) - 1; #include using namespace atcoder; 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; } ll op2(ll a, ll b){ return a+b; } ll e2(){ return 0LL; } void solve(){ int N, M; cin >> N >> M; vector A(N); vector L(N), R(N); vector H(N); for(int i=0; i> A[i] >> L[i] >> R[i]; L[i]--; R[i]--; H[i] = i; } vector v(M, {0, 1}); lazy_segtree cnt(v); for(int i=0; i seg(M); for(int i=0; i> Q; while(Q--){ int X, Y, U, V; cin >> X >> Y >> U >> V; X--; Y--; U--; V--; // erase X ans -= (ll)(R[X]-L[X]+1)*A[X] - seg.prod(L[X], R[X]+1); cnt.apply(L[X], R[X]+1, -1); ans += A[X]*cnt.prod(H[X], H[X]+1).value; seg.set(H[X], 0); // remove home Y H[X] = Y; L[X] = U, R[X] = V; seg.set(Y, A[X]); ans += (ll)(R[X]-L[X]+1)*A[X] - seg.prod(L[X], R[X]+1); ans -= A[X]*cnt.prod(H[X], H[X]+1).value; cnt.apply(L[X], R[X]+1, 1); cout << ans << "\n"; } } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int T=1; //cin >> T; while(T--) solve(); }