#include using namespace std; using ll = long long; #include struct dcin{templatedcin&operator>>(T&x){return std::cin>>x,x--,*this;}}dcin; /* S mapping(F f,S x,int len) 長さlenの区間にfを作用させる F composition(F f,F g,int len) 下の遅延配列に更新する。 いまのところg、さらにfを作用させる。 */ template class lazy_segtree{ public: explicit lazy_segtree(int n) : lazy_segtree(std::vector(n, e())) {} explicit lazy_segtree(const vector& vec) : _n(vec.size()) { _size = 1; while(_size < _n)_size *= 2; dat.assign(2 * _size,e()); lz.assign(2 * _size,id()); for(int i = 0; i < _n;i++){ dat[_size + i] = vec[i]; } for(int i = _size - 1;i > 0;--i){ dat[i] = op(dat[2*i],dat[2*i + 1]); } } S product(int l,int r){ return product(l,r,1,0,_size); } void set(int p,S x){ update(p,p+1,id(),1,0,_size); int idx = p + _size; dat[idx] = x; while(1 dat; vector lz; }; using S = ll; using F = ll; S op(S a,S b){ return a+b; } S e(){ return 0; } F mapping(F f,S x,int len){ return x + f*len; } F composition(F f,F g,int len){ return f+g; } F id(){ return 0; } int main(){ ll n,m,q; cin >> n >> m; vector rate(n),pos(n),l(n),r(n); lazy_segtree lst(m); iota(pos.begin(),pos.end(),0); for(ll i = 0;i> rate[i] >> l[i] >> r[i]; l[i]--; lst.apply(l[i],r[i],1); } atcoder::segtree ll {return a+b;},[]()-> ll {return 0;}> seg(m); for(ll i = 0;i> q; while(q--){ ll x,y,u,v; dcin >> x >> y >> u; cin >> v; // ll sub = (r[x] - l[x])*rate[x] - seg.prod(l[x],r[x]); lst.apply(l[x],r[x],-1); ll add2 = lst.get(pos[x])*rate[x]; // seg.set(pos[x],0); pos[x] = y; seg.set(pos[x],rate[x]); tie(l[x],r[x]) = make_pair(u,v); // ll add = (r[x] - l[x])*rate[x] - seg.prod(l[x],r[x]); ll sub2 = lst.get(pos[x])*rate[x]; lst.apply(l[x],r[x],1); sum = sum - sub + add - sub2 + add2; // cout << sum << '\n'; } flush(cout); }