#include #define debug(x) cerr << #x << ": " << x << '\n' #define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n' using namespace std; typedef long long ll; typedef unsigned long long ull; typedef tuple Pll; typedef vector vll; const ll INF = LLONG_MAX/10; const ll MOD = 1e18+9; template class LazySegmentTree{ private: typedef function F; typedef function G; typedef function H; typedef function P; int n; F f; G g; H h; T ti; E ei; P p; vector dat; vector laz; inline void eval(int len,int k){ if(laz[k]==ei) return; if(k*2+1 v){ int n_=v.size(); init(n_); for(int i=0;i=0;i--) dat[i]=f(dat[i*2+1],dat[i*2+2]); } T update(int a,int b,E x,int k=0,int l=0,int r=-1){ if(r<0)r=n; eval(r-l,k); if(r<=a||b<=l) return dat[k]; if(a<=l&&r<=b){ laz[k]=h(laz[k],x); return g(dat[k],p(laz[k],r-l)); } return dat[k]=f(update(a,b,x,k*2+1,l,(l+r)/2), update(a,b,x,k*2+2,(l+r)/2,r)); } T query(int a,int b,int k=0,int l=0,int r=-1){ if(r<0)r=n; eval(r-l,k); if(r<=a||b<=l) return ti; if(a<=l&&r<=b) return dat[k]; T vl=query(a,b,k*2+1,l,(l+r)/2); T vr=query(a,b,k*2+2,(l+r)/2,r); return f(vl,vr); } T operator[](const int &k) {return query(k,k+1);} }; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll N;cin>>N; ll Q;cin>>Q; vector> query(Q); vll v; v.push_back(0); for(ll q=0;q>x>>l>>r; query[q]=make_tuple(x,l,r); v.push_back(l); v.push_back(r); v.push_back(r+1); } v.push_back(N); sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); map mp; vector >A(v.size()); for(ll i=0;i<(ll)v.size();i++){ mp[v[i]]=i; A[i] = make_tuple(0ll,i+1<(ll)v.size()?v[i+1]-v[i]:1); } auto f=[](tuple a,tuple b){return make_tuple(get<0>(a)+get<0>(b),get<1>(a)+get<1>(b));}; auto g=[](tuple a,tuple b){return make_tuple(get<1>(b)? get<0>(b)*get<1>(a):get<0>(b)*get<1>(a)+get<0>(a),get<1>(a));}; auto h=[](tuple a,tuple b){return get<1>(b)? b:make_tuple(get<0>(a)+get<0>(b),get<1>(a));}; vector,tuple > > seg(5,LazySegmentTree,tuple >(f,g,h,make_tuple(0ll,0ll),make_tuple(0ll,false))); for(ll i=0;i<5;i++)seg[i].build(A); vll score(5,0); for(ll q=0;q