#include // c #include // io #include #include #include #include // container #include #include #include #include #include #include // other #include #include #include #include #include using namespace std; typedef long long ll;typedef unsigned long long ull;typedef long double ld; #define ALL(c) c.begin(),c.end() #define IN(l,v,r) (l<=v && v < r) template void UNIQUE(T v){v.erase(unique(ALL(v)),v.end());} //debug #define DUMP(x) cerr << #x <<" = " << (x) #define LINE() cerr<< " (L" << __LINE__ << ")" struct range{ struct Iter{ int v,step; Iter& operator++(){v+=step;return *this;} bool operator!=(Iter& itr){return vitr.v;} int& operator*(){return v;} }; Iter i, n; rrange(int i, int n,int step):i({i-1,step}), n({n-1,step}){} rrange(int i, int n):rrange(i,n,1){} rrange(int n) :rrange(0,n){} Iter& begin(){return n;} Iter& end(){return i;} }; //input template istream& operator >> (istream& is,pair& p){return is>>p.first>>p.second;} template istream& operator >> (istream& is,tuple& t){return is >> get<0>(t);} template istream& operator >> (istream& is,tuple& t){return is >> get<0>(t) >> get<1>(t);} template istream& operator >> (istream& is,tuple& t){return is >>get<0>(t)>>get<1>(t)>>get<2>(t);} template istream& operator >> (istream& is,tuple& t){return is >> get<0>(t)>>get<1>(t)>>get<2>(t)>>get<3>(t);} template istream& operator >> (istream& is,vector& as){for(int i:range(as.size()))is >>as[i];return is;} //output template ostream& operator << (ostream& os, const set& ss){for(auto a:ss){if(a!=ss.begin())os<<" "; os< ostream& operator << (ostream& os, const pair& p){return os< ostream& operator << (ostream& os, const map& m){bool isF=true;for(auto& p:m){if(!isF)os< ostream& operator << (ostream& os, const tuple& t){return os << get<0>(t);} template ostream& operator << (ostream& os, const tuple& t){return os << get<0>(t)<<" "<(t);} template ostream& operator << (ostream& os, const tuple& t){return os << get<0>(t)<<" "<(t)<<" "<(t);} template ostream& operator << (ostream& os, const tuple& t){return os << get<0>(t)<<" "<(t)<<" "<(t)<<" "<(t);} template ostream& operator << (ostream& os, const vector& as){for(int i:range(as.size())){if(i!=0)os<<" "; os< ostream& operator << (ostream& os, const vector>& as){for(int i:range(as.size())){if(i!=0)os< inline T INF(){assert(false);}; template<> inline int INF(){return 1<<28;}; template<> inline ll INF(){return 1LL<<58;}; template<> inline double INF(){return 1e16;}; template<> inline long double INF(){return 1e16;}; template inline T EPS(){assert(false);}; template<> inline int EPS(){return 1;}; template<> inline ll EPS(){return 1LL;}; template<> inline double EPS(){return 1e-8;}; template<> inline long double EPS(){return 1e-8;}; // min{2^r | n < 2^r} template T upper_pow2(T n){ T res=1;while(res T msb(T n){ int d=62;while((1LL<n)d--;return d;} template T pmod(T v,U M){return (v%M+M)%M;} ll gcd_positive(ll a,ll b) { return b == 0 ? a : gcd_positive(b,a%b); } ll gcd(ll a,ll b) { return gcd_positive(abs(a), abs(b)); } ll lcm(ll a,ll b){return a/gcd(a,b)*b;} template class StarrySkyTree{ public: const int size,n2; vector dat,lazy; StarrySkyTree(int n):size(n),n2(upper_pow2(size)){ dat = vector(n2*2,0); lazy = vector(n2*2,-1); } inline T get(int v){update(v);return dat[v+n2];} void set(int v,T a){ v+=n2;dat[v]=a; propagate(v); } //+=x in [a,b) void lquery(int a,int b,T x){lquery(a,b,1,0,n2,x);} //+= in [a,b) T query(int a,int b){return query(a,b,1,0,n2);} private: void propagate(int v){ while(v!=1){ v = v/2; update(v); } } void update(int v){ int chl=2*v,chr=2*v+1; if(not (chl < n2*2)) return; if(lazy[v]!=-1){ dat[chl] = lazy[v]*(1<< (msb(n2)-msb(chl)));lazy[chl]=lazy[v]; dat[chr] = lazy[v]*(1<< (msb(n2)-msb(chr)));lazy[chr]=lazy[v]; } dat[v] = (dat[chl] + dat[chr]); lazy[v]= -1; } void lquery(int a,int b,int v,int l,int r,T x){ if(r<=a || b<=l)return;//out range if(a<=l && r<=b){ dat[v] = x * (r-l); lazy[v] = x; propagate(v); return; } lquery(a,b,v*2,l,(l+r)/2,x);lquery(a,b,v*2+1,(l+r)/2,r,x); } T query(int a,int b,int v,int l,int r){//[a,b) on v:[l,r) if(r<=a || b<=l)return 0;//out range update(v); if(a<=l && r<=b)return dat[v]; return (query(a,b,v*2,l,(l+r)/2) + query(a,b,v*2+1,(l+r)/2,r)); } }; class Main{ public: void run(){ int N;cin >> N; int Q;cin >> Q; ll a=0,b=0; StarrySkyTree as(N),bs(N); for(int q:range(Q)){ int x,l,r;cin >> x >> l >> r;r++; if(x==0){ ll av = as.query(l, r),bv = bs.query(l, r); if(av>bv)a+=av; else if(av