#include using namespace std; using ll = long long; struct S { ll v,s; }; S op(S a,S b) { return {a.v+b.v,a.s+b.s}; } S e() { return {0,0}; } S ma(ll f,S x) { return {f<0?x.v:f*x.s,x.s}; } ll co(ll f,ll g) { return f==-1?g:f; } ll id() { return -1; } int main() { int n,q; cin>>n>>q; atcoder::lazy_segtree A(vector(n,S{0,1})); auto B=A; ll a=0,b=0; for (; q--;) { int x,l,r; cin>>x>>l>>r,r++; if (x) { A.apply(l,r,!~-x); B.apply(l,r,+~-x); } else { ll x=A.prod(l,r).v,y=B.prod(l,r).v; if (x>y) a+=x; if (x