/*  ***  In The Name of God ... ***  */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int long long
#define all(v) v.begin() , v.end()

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

const int N = 1e5 + 10 , sq = 400 ;

int n , m , sum [ N / sq + 1 ] , tim = 1 , ok [ N / sq + 1 ] , d [ N ] , f [ N / sq + 1 ] ;
pair < int , int > ar [ N ] , lz [ N / sq + 1 ] ;

int color ( int p ) {
	if ( lz [ p / sq ] . second > ar [ p ] . second )
		return lz [ p / sq ] . first ;
	return ar [ p ] . first ;
}

void alone ( int p , int x ) {
	d [ p ] += abs ( color ( p ) - x ) ;
	sum [ p / sq ] += abs ( color ( p ) - x ) ;
	ar [ p ] = { x , tim } ;
	ok [ p / sq ] = 0 ;
}

void add ( int l , int r , int x ) {
	while ( l < r ) {
		if ( l % sq == 0 && l + sq <= r ) {
			if ( ok [ l / sq ] ) {
				int &cur = sum [ l / sq ] ;
				int All = ok [ l / sq ] ;
				int nw = abs ( All - x ) ;
				int sz = min ( n - 1 , l + sq - 1 ) - l + 1 ;
				cur += ( sz * nw ) ;
				f [ l / sq ] += abs ( All - x ) ;
 			}
			else {
				for ( int i = l ; i <= min ( n - 1 , l + sq - 1 ) ; ++ i )
					alone ( i , x ) ;
			}
			ok [ l / sq ] = x ;
			lz [ l / sq ] = { x , tim } ;
			l += sq ;
		}
		else {
			alone ( l ++ , x ) ;
		}
	}
}

int get ( int l , int r ) {
	int res = 0 ;
	while ( l < r ) {
		if ( l % sq == 0 && l + sq <= r ) {
			res += sum [ l / sq ] ;
			l += sq ;
		}
		else {
			res += d [ l ] + f [ l / sq ] ;
			++ l ;
		}
	}
	return res ;
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m ;
	for ( int i = 0 ; i < n ; ++ i ) {
		ar [ i ] = { i + 1 , 0 } ;
	}
	for ( ; tim <= m ; ++ tim ) {
		int typ ;
		cin >> typ ;
		if ( typ == 1 ) {
			int l , r , x ;
			cin >> l >> r >> x ;
			l -- ;
			add ( l , r , x ) ;
		}
		else {
			int l , r ;
			cin >> l >> r ;
			l -- ;
			cout << get ( l , r ) << '\n' ;
		}
	}
}


/*  ***  In The Name of God ... ***  */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int long long
#define all(v) v.begin() , v.end()

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

const int N = 1e5 + 10 , sq = 350 ;

int n , m , sum [ N / sq + 1 ] , tim = 1 , ok [ N / sq + 1 ] , d [ N ] , f [ N / sq + 1 ] ;
pair < int , int > ar [ N ] , lz [ N / sq + 1 ] ;

int color ( int p ) {
	if ( lz [ p / sq ] . second > ar [ p ] . second )
		return lz [ p / sq ] . first ;
	return ar [ p ] . first ;
}

void alone ( int p , int x ) {
	d [ p ] += abs ( color ( p ) - x ) ;
	ar [ p ] = { x , tim ++ } ;
}

void add ( int l , int r , int x ) {
	while ( l < r ) {
		if ( l % sq == 0 && l + sq <= r ) {
			if ( ok [ l / sq ] ) {
				int &cur = sum [ l / sq ] ;
				int All = ok [ l / sq ] ;
				int nw = abs ( All - x ) ;
				int sz = min ( n - 1 , l + sq - 1 ) - l + 1 ;
				cur += ( sz * All ) ;
				lz [ l / sq ] = { x , tim ++ } ;
				ok [ l / sq ] = x ;
				f [ l / sq ] += abs ( All - x ) ;
 			}
			else {
				for ( int i = l ; i <= min ( n - 1 , l + sq - 1 ) ; ++ i )
					alone ( i , x ) ;
				ok [ l / sq ] = x ;
			}
			l += sq ;
		}
		else {
			alone ( l ++ , x ) ;
		}
	}
}

int get ( int l , int r ) {
	int res = 0 ;
	while ( l < r ) {
		if ( l % sq == 0 && l + sq <= r ) {
			res += sum [ l / sq ] ;
			l += sq ;
		}
		else {
			res += d [ l ] + f [ l / sq ] ;
			++ l ;
		}
	}
	return res ;
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m ;
	for ( int i = 0 ; i < n ; ++ i ) {
		ar [ i ] = { i + 1 , 0 } ;
	}
	while ( m -- ) {
		int typ ;
		cin >> typ ;
		if ( typ == 1 ) {
			int l , r , x ;
			cin >> l >> r >> x ;
			l -- ;
			add ( l , r , x ) ;
		}
		else {
			int l , r ;
			cin >> l >> r ;
			l -- ;
			cout << get ( l , r ) << '\n' ;
		}
	}
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int N=1e5+10 , bsize=sqrt(N)+1;
ll contrib[N]={0} , dp[bsize]={0} ,   extra[N]={0} , a[N] ,prev_val[bsize]={0} ,x  ;
int n,q,t,l,r , st[bsize] , en[bsize] , lazy[N]  ;

void semi_update(int bno , int L,int R){
    if(lazy[bno]){
        for(int i=st[bno];i<=en[bno];i++){
            contrib[i]+=extra[bno];
            a[i]=prev_val[bno];

        }
        lazy[bno]=0;
    }

    for(int i=L;i<=R;i++){
        dp[bno]+=abs(a[i]-x);
        contrib[i]+=abs(a[i]-x);
        a[i]=x;
    }
}

void update(int bno){
    if(lazy[bno]){
        ll tmp=(en[bno]-st[bno]+1);
        dp[bno]+=abs(prev_val[bno]-x)*tmp;
        extra[bno]+=abs(prev_val[bno]-x);

    }
    else{
        for(int i=st[bno];i<=en[bno];i++){
            dp[bno]+=abs(x-a[i]);
            contrib[i]+=abs(x-a[i]);
            a[i]=x;
        }
    }
    lazy[bno]=1;
    prev_val[bno]=x;
}

ll semi_query(int bno , int L,int R){
    if(lazy[bno]){
        for(int i=st[bno];i<=en[bno];i++){
            contrib[i]+=extra[bno];
            a[i]=prev_val[bno];

        }
        lazy[bno]=0;
    }
    ll ans=0;
    for(int i=L;i<=R;i++){
        ans+=contrib[i];
    }
    return ans;
}

ll query(int bno){
    return dp[bno];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    scanf("%d%d",&n,&q);
    for(int i=0;i<n;i++) a[i]=i+1;

    for(int i=0;i<bsize;i++){
        st[i]=i*bsize;
        en[i]=st[i]+bsize-1;
    }

    while(q--){
        scanf("%d%d%d",&t,&l,&r);
        l--; r--;
        int bl = l/bsize , br=r/bsize;
        if(t==1){
            //update
            scanf("%lld",&x);
            semi_update(bl , l , min(en[bl] , r));
            if(bl-br) semi_update(br , max(l,st[br]) , r);

            for(int i=bl+1;i<br;i++) update(i);

        }
        else{
            ll ans=semi_query(bl,l,min(en[bl] , r));
            if(bl-br) ans+=semi_query(br , max(l,st[br]) , r);
            for(int i=bl+1;i<br;i++) ans+=query(i);

            printf("%lld\n",ans);
        }
    }
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int N=1e5+10 , bsize=sqrt(N)+1;
ll contrib[N]={0} , dp[bsize] ,   extra[N] , a[N] ,x  ;
int n,q,t,l,r , st[bsize] , en[bsize] , lazy[N] , prev_val[bsize];

void semi_update(int bno , int L,int R){
    if(lazy[bno]){
        for(int i=st[bno];i<=en[bno];i++){
            contrib[i]+=extra[bno];
            a[i]=prev_val[bno];

        }
        lazy[bno]=0;
    }

    for(int i=L;i<=R;i++){
        dp[bno]+=abs(a[i]-x);
        contrib[i]+=abs(a[i]-x);
        a[i]=x;
    }
}

void update(int bno){
    if(lazy[bno]){
        dp[bno]+=abs(prev_val[bno]-x)*(en[bno]-st[bno]+1);
        extra[bno]+=abs(prev_val[bno]-x);

    }
    else{
        for(int i=st[bno];i<=en[bno];i++){
            dp[bno]+=abs(x-a[i]);
            contrib[i]+=abs(x-a[i]);
            a[i]=x;
        }
    }
    lazy[bno]=1;
    prev_val[bno]=x;
}

ll semi_query(int bno , int L,int R){
    if(lazy[bno]){
        for(int i=st[bno];i<=en[bno];i++){
            contrib[i]+=extra[bno];
            a[i]=prev_val[bno];

        }
        lazy[bno]=0;
    }
    ll ans=0;
    for(int i=L;i<=R;i++){
        ans+=contrib[i];
    }
    return ans;
}

ll query(int bno){
    return dp[bno];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    scanf("%d%d",&n,&q);
    for(int i=0;i<n;i++) a[i]=i+1;

    for(int i=0;i<bsize;i++){
        st[i]=i*bsize;
        en[i]=st[i]+bsize-1;
    }

    while(q--){
        scanf("%d%d%d",&t,&l,&r);
        l--; r--;
        int bl = l/bsize , br=r/bsize;
        if(t==1){
            //update
            scanf("%lld",&x);
            semi_update(bl , l , min(en[bl] , r));
            if(bl-br) semi_update(br , max(l,st[br]) , r);

            for(int i=bl+1;i<br;i++) update(i);

        }
        else{
            ll ans=semi_query(bl,l,min(en[bl] , r));
            if(bl-br) ans+=semi_query(br , max(l,st[br]) , r);
            for(int i=bl+1;i<br;i++) ans+=query(i);

            printf("%lld\n",ans);
        }
    }
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int N=1e5+10 , bsize=sqrt(N)+1;
ll contrib[N]={0} , dp[bsize]={0} ,   extra[N]={0} , a[N] ,prev_val[bsize]={0} ,x  ;
int n,q,t,l,r , st[bsize] , en[bsize] , lazy[N]  ;

void semi_update(int bno , int L,int R){
    if(lazy[bno]){
        for(int i=st[bno];i<=en[bno];i++){
            contrib[i]+=extra[bno];
            a[i]=prev_val[bno];

        }
        lazy[bno]=0;  extra[bno]=0;
    }

    for(int i=L;i<=R;i++){
        dp[bno]+=abs(a[i]-x);
        contrib[i]+=abs(a[i]-x);
        a[i]=x;
    }
}

void update(int bno){
    if(lazy[bno]){
        ll tmp=(en[bno]-st[bno]+1);
        dp[bno]+=abs(prev_val[bno]-x)*tmp;
        extra[bno]+=abs(prev_val[bno]-x);

    }
    else{
        for(int i=st[bno];i<=en[bno];i++){
            dp[bno]+=abs(x-a[i]);
            contrib[i]+=abs(x-a[i]);
            a[i]=x;
        }
    }
    lazy[bno]=1;
    prev_val[bno]=x;
}

ll semi_query(int bno , int L,int R){
    if(lazy[bno]){
        for(int i=st[bno];i<=en[bno];i++){
            contrib[i]+=extra[bno];
            a[i]=prev_val[bno];

        }
        lazy[bno]=0;
        extra[bno]=0;
    }
    ll ans=0;
    for(int i=L;i<=R;i++){
        ans+=contrib[i];
    }
    return ans;
}

ll query(int bno){
    return dp[bno];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    scanf("%d%d",&n,&q);
    for(int i=0;i<n;i++) a[i]=i+1;

    for(int i=0;i<bsize;i++){
        st[i]=i*bsize;
        en[i]=st[i]+bsize-1;
    }

    while(q--){
        scanf("%d%d%d",&t,&l,&r);
        l--; r--;
        int bl = l/bsize , br=r/bsize;
        if(t==1){
            //update
            scanf("%lld",&x);
            semi_update(bl , l , min(en[bl] , r));
            if(bl-br) semi_update(br , max(l,st[br]) , r);

            for(int i=bl+1;i<br;i++) update(i);

        }
        else{
            ll ans=semi_query(bl,l,min(en[bl] , r));
            if(bl-br) ans+=semi_query(br , max(l,st[br]) , r);
            for(int i=bl+1;i<br;i++) ans+=query(i);

            printf("%lld\n",ans);
        }
    }
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int N=1e5+10 , bsize=sqrt(N)+1;
ll contrib[N]={0} , dp[bsize]={0} ,   extra[N]={0} , a[N] ,prev_val[bsize]={0} ,x  ;
int n,q,t,l,r , st[bsize] , en[bsize] , lazy[N]  ;

void semi_update(int bno , int L,int R){
    if(lazy[bno]){
        for(int i=st[bno];i<=en[bno];i++){
            contrib[i]+=extra[bno];
            a[i]=prev_val[bno];

        }
        lazy[bno]=0;  extra[bno]=0;
    }

    for(int i=L;i<=R;i++){
        dp[bno]+=abs(a[i]-x);
        contrib[i]+=abs(a[i]-x);
        a[i]=x;
    }
}

void update(int bno){
    if(lazy[bno]){
        ll tmp=(en[bno]-st[bno]+1);
        dp[bno]+=abs(prev_val[bno]-x)*tmp;
        extra[bno]+=abs(prev_val[bno]-x);

    }
    else{
        for(int i=st[bno];i<=en[bno];i++){
            dp[bno]+=abs(x-a[i]);
            contrib[i]+=abs(x-a[i]);
            a[i]=x;
        }
    }
    lazy[bno]=1;
    prev_val[bno]=x;
}

ll semi_query(int bno , int L,int R){
    if(lazy[bno]){
        for(int i=st[bno];i<=en[bno];i++){
            contrib[i]+=extra[bno];
            a[i]=prev_val[bno];

        }
        lazy[bno]=0;
        extra=0;
    }
    ll ans=0;
    for(int i=L;i<=R;i++){
        ans+=contrib[i];
    }
    return ans;
}

ll query(int bno){
    return dp[bno];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    scanf("%d%d",&n,&q);
    for(int i=0;i<n;i++) a[i]=i+1;

    for(int i=0;i<bsize;i++){
        st[i]=i*bsize;
        en[i]=st[i]+bsize-1;
    }

    while(q--){
        scanf("%d%d%d",&t,&l,&r);
        l--; r--;
        int bl = l/bsize , br=r/bsize;
        if(t==1){
            //update
            scanf("%lld",&x);
            semi_update(bl , l , min(en[bl] , r));
            if(bl-br) semi_update(br , max(l,st[br]) , r);

            for(int i=bl+1;i<br;i++) update(i);

        }
        else{
            ll ans=semi_query(bl,l,min(en[bl] , r));
            if(bl-br) ans+=semi_query(br , max(l,st[br]) , r);
            for(int i=bl+1;i<br;i++) ans+=query(i);

            printf("%lld\n",ans);
        }
    }
}


#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <cassert>
#include <set>
#include <complex>
#include <bitset>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <string>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define eps 1e-8
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen ("in.txt", "r", stdin),freopen ("out.txt", "w", stdout);
#define filein freopen ("in.txt", "r", stdin);
#define all(v) ((v).begin()), ((v).end())
#define mid ((st + en) >> 1)

const int N = 1e5 + 5;

int n, m;

struct range{
 int L, R, x;
 range(int L, int R, int x) : L(L), R(R), x(x){}
 bool operator<(const range &that) const{
  if(L != that.L)
   return L < that.L;
  assert(R != that.R);
  return R < that.R;
 }
};

set<range> st;

long long tree[N * 4], lazy[N * 4];

inline void apply(int root, int &st, int &en, int &R, int &L){
 lazy[R] += lazy[root];
 lazy[L] += lazy[root];
 tree[L] += (mid - st + 1) * 1LL * lazy[root];
 tree[R] += (en - mid) * 1LL * lazy[root];
 lazy[root] = 0;
}

void update(int L, int R, int x, int st = 1, int en = n,
            int root = 1){
 if(L > en || R < st)
  return;
 if(st >= L && en <= R){
  tree[root] += (en - st + 1) * 1LL * x;
  lazy[root] += x;
  return;
 }
 apply(root, st, en, R, L);
 update(L, R, x, st, mid, root << 1);
 update(L, R, x, mid + 1, en, (root << 1)|1);
 tree[root] = tree[(root << 1)] + tree[(root << 1)|1];
}

long long query(int L, int R, int st = 1, int en = n, int root = 1){
 if(L > en || R < st)
  return 0;
 if(st >= L && en <= R)
  return tree[root];
 apply(root, st, en, R, L);
 return query(L, R, st, mid, root << 1) +
  query(L, R, mid + 1, en, (root << 1)|1);
}

int main(){

 io;
 cin >> n >> m;
 for(int i = 1; i <= n; i++)
  st.insert(range(i, i, i));

 while(m--){
  int t, L, R;
  cin >> t >> L >> R;
  if(t == 1){
   int x;
   cin >> x;
   auto it = --st.upper_bound(range(L, N, N));
   for(; it != st.end() && it->L <= R;){
    int Li = it->L, Ri = it->R, xi = it->x;
    if(Li < L){
     st.insert(range(Li, L - 1, xi));
     Li = L;
    }
    if(Ri > R){
     st.insert(range(R + 1, Ri, xi));
     Ri = R;
    }
    update(Li, Ri, abs(xi - x));
    st.erase(it++);
   }
   st.insert(range(L, R, x));
  }else{
   long long ret = query(L, R);
   cout << ret << endl;
  }
 }
 return 0;
}


#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <cassert>
#include <set>
#include <complex>
#include <bitset>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <string>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define eps 1e-8
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen ("in.txt", "r", stdin),freopen ("out.txt", "w", stdout);
#define filein freopen ("in.txt", "r", stdin);
#define all(v) ((v).begin()), ((v).end())
#define mid ((st + en) >> 1)

const int N = 1e5 + 5;

int n, m;

struct node{
 long long sum;
 int x;
 bool f;
};
node tree[N * 4];
long long lazy[N * 4];

inline void build(int st = 0, int en = n - 1, int root = 1){
 if(st == en){
  tree[root].f = 1;
  tree[root].x = st + 1;
  return;
 }
 build(st, mid, root << 1);
 build(mid + 1, en, (root << 1)|1);
}

inline void apply(int root, int st, int en){
 if(lazy[root] == 0)
  return;
 int L = root << 1, R = (root << 1)|1;
 tree[L].x = tree[R].x = tree[root].x;
 lazy[R] += lazy[root];
 lazy[L] += lazy[root];
 tree[L].sum += (mid - st + 1) * 1LL * lazy[root];
 tree[R].sum += (en - mid) * 1LL * lazy[root];
 lazy[root] = 0;
}

void update(int L, int R, int x, int st = 0, int en = n - 1,
            int root = 1){

 if(L > en || R < st)
  return;

 if(st >= L && en <= R && tree[root].f){
  tree[root].sum += (en - st + 1) * 1LL * abs(x - tree[root].x);
  lazy[root] += abs(x - tree[root].x);
  tree[root].x = x;
  return;
 }

 apply(root, st, en);

 update(L, R, x, st, mid, root << 1);
 update(L, R, x, mid + 1, en, (root << 1)|1);

 if(tree[root << 1].f && tree[(root << 1)|1].f && tree[root << 1].x
    == tree[(root << 1)|1].x){
  tree[root].f = 1;
  tree[root].x = tree[root << 1].x;
 }else
  tree[root].f = 0;
 tree[root].sum = tree[(root << 1)].sum + tree[(root << 1)|1].sum;
}

long long query(int L, int R, int st = 0, int en = n - 1, int root = 1){
 if(L > en || R < st)
  return 0;
 if(st >= L && en <= R)
  return tree[root].sum;
 apply(root, st, en);
 return query(L, R, st, mid, root << 1) +
    query(L, R, mid + 1, en, (root << 1)|1);
}

int main(){
 //filein;
 io;

 cin >> n >> m;
 build();

 while(m--){
  int t, L, R;
  cin >> t >> L >> R;
  L--, R--;
  if(t == 1){
   int x;
   cin >> x;
   update(L, R, x);
  }else{
   long long ret = query(L, R);
   cout << ret << endl;
  }
 }
 return 0;
}


#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <cassert>
#include <set>
#include <complex>
#include <bitset>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <string>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define eps 1e-8
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen ("in.txt", "r", stdin),freopen ("out.txt", "w", stdout);
#define filein freopen ("in.txt", "r", stdin);
#define all(v) ((v).begin()), ((v).end())
#define mid ((st + en) >> 1)

const int N = 1e5 + 5;

int n, m;

struct node{
 long long sum;
 int x;
 bool f;
};
node tree[N * 4], lazy[N * 4];

inline void build(int st = 0, int en = n - 1, int root = 1){

 if(st == en){
  tree[root].f = 1;
  tree[root].x = st + 1;
  return;
 }
 build(st, mid, root << 1);
 build(mid + 1, en, (root << 1)|1);
}

inline void apply(int root, int st, int en){
 if(lazy[root].x == 0)
  return;

// if(tree[root].x != lazy[root].x)
//  cout << tree[root].x << " " << lazy[root].x << endl;

 int L = root << 1, R = (root << 1)|1;

 lazy[R].x = lazy[L].x = tree[L].x = tree[R].x = lazy[root].x;
 lazy[R].sum += lazy[root].sum;
 lazy[L].sum += lazy[root].sum;
 tree[L].sum += (mid - st + 1) * 1LL * lazy[root].sum;
 tree[R].sum += (en - mid) * 1LL * lazy[root].sum;
 lazy[root].sum = 0;
}

void update(int L, int R, int x, int st = 0, int en = n - 1,
            int root = 1){

 if(L > en || R < st)
  return;

 if(st >= L && en <= R && tree[root].f){
  tree[root].sum += (en - st + 1) * 1LL * abs(x - tree[root].x);
//  cout << st << " " << en << endl;
//  cout << "tree[root].x " << tree[root].x << endl;
//  cout << "tree[root].sum " << tree[root].sum << endl;
  lazy[root].sum += abs(x - tree[root].x);
  tree[root].x = x;
  lazy[root].x = x;

  return;
 }

 if(tree[root].f)
  apply(root, st, en);

 update(L, R, x, st, mid, root << 1);
 update(L, R, x, mid + 1, en, (root << 1)|1);

 if(tree[root << 1].f && tree[(root << 1)|1].f && tree[root << 1].x
    == tree[(root << 1)|1].x){
  tree[root].f = 1;
  tree[root].x = tree[root << 1].x;
 }else{
  tree[root].f = 0;
  lazy[root].x = 0;
 }

 tree[root].sum = tree[(root << 1)].sum + tree[(root << 1)|1].sum;
}

long long query(int L, int R, int st = 0, int en = n - 1, int root = 1){
 if(L > en || R < st)
  return 0;

 if(st >= L && en <= R && tree[root].f)
  return tree[root].sum;

 if(tree[root].f)
  apply(root, st, en);

 return query(L, R, st, mid, root << 1) +
    query(L, R, mid + 1, en, (root << 1)|1);
}

int main(){
 //filein;
 io;

 cin >> n >> m;
 build();

 while(m--){
  int t, L, R;
  cin >> t >> L >> R;
  L--, R--;
  if(t == 1){
   int x;
   cin >> x;
   update(L, R, x);
  }else{
   long long ret = query(L, R);
   cout << ret << endl;
  }
 }
 return 0;
}


#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <cassert>
#include <set>
#include <complex>
#include <bitset>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <string>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define eps 1e-8
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen ("in.txt", "r", stdin),freopen ("out.txt", "w", stdout);
#define filein freopen ("in.txt", "r", stdin);
#define all(v) ((v).begin()), ((v).end())
#define mid ((st + en) >> 1)

const int N = 1e5 + 5;

int n, m;

struct node{
 long long sum;
 int x;
 bool f;
};
node tree[N * 4], lazy[N * 4];

inline void build(int st = 0, int en = n - 1, int root = 1){
 if(st == en){
  tree[root].f = 1;
  tree[root].x = st + 1;
  return;
 }
 build(st, mid, root << 1);
 build(mid + 1, en, (root << 1)|1);
}

inline void apply(int root, int st, int en, int L, int R){
 lazy[R].x = lazy[L].x = tree[L].x = tree[R].x = tree[root].x;
 lazy[R].sum += lazy[root].sum;
 lazy[L].sum += lazy[root].sum;
 tree[L].sum += (mid - st + 1) * 1LL * lazy[root].sum;
 tree[R].sum += (en - mid) * 1LL * lazy[root].sum;
 lazy[root].sum = 0;
}

void update(int L, int R, int x, int st = 0, int en = n - 1,
            int root = 1){

 if(L > en || R < st)
  return;

 if(st >= L && en <= R && tree[root].f){
  tree[root].sum += (en - st + 1) * 1LL * abs(x - tree[root].x);
  tree[root].x = x;
  lazy[root].x = x;
  lazy[root].sum += abs(x - tree[root].x);
  return;
 }

 if(tree[root].f)
  apply(root, st, en, (root << 1), (root << 1)|1);

 update(L, R, x, st, mid, root << 1);
 update(L, R, x, mid + 1, en, (root << 1)|1);

 tree[root].f = tree[(root << 1)].f && tree[(root << 1)|1].f
    && (tree[root << 1].x == tree[(root << 1)|1].x);

 tree[root].sum = tree[(root << 1)].sum + tree[(root << 1)|1].sum;
}

long long query(int L, int R, int st = 0, int en = n - 1, int root = 1){
 if(L > en || R < st)
  return 0;
 if(st >= L && en <= R && tree[root].f)
  return tree[root].sum;
 if(tree[root].f)
  apply(root, st, en, (root << 1), (root << 1)|1);
 return query(L, R, st, mid, root << 1) +
 query(L, R, mid + 1, en, (root << 1)|1);
}

int main(){
 //filein;
 io;

 cin >> n >> m;
 build();

 while(m--){
  int t, L, R;
  cin >> t >> L >> R;
  L--, R--;
  if(t == 1){
   int x;
   cin >> x;
   update(L, R, x);
  }else{
   long long ret = query(L, R);
   cout << ret << endl;
  }
 }
 return 0;
}


#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <cassert>
#include <set>
#include <complex>
#include <bitset>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <string>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define eps 1e-8
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen ("in.txt", "r", stdin),freopen ("out.txt", "w", stdout);
#define filein freopen ("in.txt", "r", stdin);
#define all(v) ((v).begin()), ((v).end())
#define mid ((st + en) >> 1)

const int N = 1e5 + 5;

int n, m;

struct range{
 int L, R, x;
 range(int L, int R, int x) : L(L), R(R), x(x){}
 bool operator<(const range &that) const{
  if(L != that.L)
   return L < that.L;
  assert(R != that.R);
  return R < that.R;
 }
};

set<range> st;

long long tree[N * 4], lazy[N * 4];

inline void apply(int root, int st, int en, int L, int R){
 lazy[R] += lazy[root];
 lazy[L] += lazy[root];
 tree[L] += (mid - st + 1) * 1LL * lazy[root];
 tree[R] += (en - mid) * 1LL * lazy[root];
 lazy[root] = 0;
}

void update(int L, int R, int x, int st = 0, int en = n - 1,
            int root = 1){
 if(L > en || R < st)
  return;
 if(st >= L && en <= R){
  tree[root] += (en - st + 1) * 1LL * x;
  lazy[root] += x;
  return;
 }
 apply(root, st, en, (root << 1), (root << 1)|1);
 update(L, R, x, st, mid, root << 1);
 update(L, R, x, mid + 1, en, (root << 1)|1);
 tree[root] = tree[(root << 1)] + tree[(root << 1)|1];
}

long long query(int L, int R, int st = 0, int en = n - 1, int root = 1){
 if(L > en || R < st)
  return 0;
 if(st >= L && en <= R)
  return tree[root];
 apply(root, st, en, (root << 1), (root << 1)|1);
 return query(L, R, st, mid, root << 1) +
  query(L, R, mid + 1, en, (root << 1)|1);
}

int main(){
 //filein;
 io;

 cin >> n >> m;
 for(int i = 0; i < n; i++)
  st.insert(range(i, i, i + 1));

 while(m--){
  int t, L, R;
  cin >> t >> L >> R;
  L--, R--;
  if(t == 1){
   int x;
   cin >> x;
   auto it = --st.upper_bound(range(L, N, N));
   for(; it != st.end() && it->L <= R;){
    int Li = it->L, Ri = it->R, xi = it->x;
    if(Li < L){
     st.insert(range(Li, L - 1, xi));
     Li = L;
    }
    if(Ri > R){
     st.insert(range(R + 1, Ri, xi));
     Ri = R;
    }
    update(Li, Ri, abs(xi - x));
    st.erase(it++);
   }
   st.insert(range(L, R, x));
  }else{
   long long ret = query(L, R);
   cout << ret << endl;
  }
 }
 return 0;
}


#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <cassert>
#include <set>
#include <complex>
#include <bitset>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <string>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define eps 1e-8
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen ("in.txt", "r", stdin),freopen ("out.txt", "w", stdout);
#define filein freopen ("in.txt", "r", stdin);
#define all(v) ((v).begin()), ((v).end())
#define mid ((st + en) >> 1)

const int N = 1e5 + 5;

int n, m;

struct node{
 long long sum;
 int x;
 bool f;
};
node tree[N * 4], lazy[N * 4];

inline void build(int st = 0, int en = n - 1, int root = 1){
 if(st == en){
  tree[root].f = 1;
  tree[root].x = st + 1;
  return;
 }
 build(st, mid, root << 1);
 build(mid + 1, en, (root << 1)|1);
}

inline void apply(int root, int st, int en, int L, int R){
 lazy[R].x = lazy[L].x = tree[L].x = tree[R].x = tree[root].x;
 lazy[R].sum += lazy[root].sum;
 lazy[L].sum += lazy[root].sum;
 tree[L].sum += (mid - st + 1) * 1LL * lazy[root].sum;
 tree[R].sum += (en - mid) * 1LL * lazy[root].sum;
 lazy[root].sum = 0;
}

void update(int L, int R, int x, int st = 0, int en = n - 1,
            int root = 1){

 if(L > en || R < st)
  return;

 if(st >= L && en <= R && tree[root].f){
  tree[root].sum += (en - st + 1) * 1LL * abs(x - tree[root].x);
  tree[root].x = x;
  lazy[root].x = x;
  lazy[root].sum += abs(x - tree[root].x);
  return;
 }

 if(tree[root].f)
  apply(root, st, en, (root << 1), (root << 1)|1);

 update(L, R, x, st, mid, root << 1);
 update(L, R, x, mid + 1, en, (root << 1)|1);

 tree[root].f = tree[(root << 1)].f && tree[(root << 1)|1].f
    && (tree[root << 1].x == tree[(root << 1)|1].f);

 tree[root].sum = tree[(root << 1)].sum + tree[(root << 1)|1].sum;
}

long long query(int L, int R, int st = 0, int en = n - 1, int root = 1){
 if(L > en || R < st)
  return 0;
 if(st >= L && en <= R && tree[root].f)
  return tree[root].sum;
 if(tree[root].f)
  apply(root, st, en, (root << 1), (root << 1)|1);
 return query(L, R, st, mid, root << 1) +
 query(L, R, mid + 1, en, (root << 1)|1);
}

int main(){
 //filein;
 io;

 cin >> n >> m;
 build();

 while(m--){
  int t, L, R;
  cin >> t >> L >> R;
  L--, R--;
  if(t == 1){
   int x;
   cin >> x;
   update(L, R, x);
  }else{
   long long ret = query(L, R);
   cout << ret << endl;
  }
 }
 return 0;
}


#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <cassert>
#include <set>
#include <complex>
#include <bitset>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <string>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define eps 1e-8
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen ("in.txt", "r", stdin),freopen ("out.txt", "w", stdout);
#define filein freopen ("in.txt", "r", stdin);
#define all(v) ((v).begin()), ((v).end())
#define mid ((st + en) >> 1)

const int N = 1e5 + 5;

int n, m;

struct node{
 long long sum;
 int x;
 bool f;
};
node tree[N * 4];
long long lazy[N * 4];

inline void build(int st = 0, int en = n - 1, int root = 1){
 if(st == en){
  tree[root].f = 1;
  tree[root].x = st + 1;
  return;
 }
 build(st, mid, root << 1);
 build(mid + 1, en, (root << 1)|1);
}

inline void apply(int root, int st, int en){
 if(lazy[root] == 0)
  return;
 int L = root << 1, R = (root << 1)|1;
 lazy[R] += lazy[root];
 lazy[L] += lazy[root];
 tree[L].sum += (mid - st + 1) * 1LL * lazy[root];
 tree[R].sum += (en - mid) * 1LL * lazy[root];
 lazy[root] = 0;
}

void update(int L, int R, int x, int st = 0, int en = n - 1,
            int root = 1){
 if(L > en || R < st)
  return;

 if(st >= L && en <= R && tree[root].f){
  tree[root].sum += (en - st + 1) * 1LL * abs(x - tree[root].x);
  lazy[root] += abs(x - tree[root].x);
  tree[root].x = x;
  return;
 }
 apply(root, st, en);
 update(L, R, x, st, mid, root << 1);
 update(L, R, x, mid + 1, en, (root << 1)|1);

 if(tree[root << 1].f && tree[(root << 1)|1].f && tree[root << 1].x
    == tree[(root << 1)|1].x){
  tree[root].f = 1;
  tree[root].x = tree[root << 1].x;
 }else
  tree[root].f = 0;
 tree[root].sum = tree[(root << 1)].sum + tree[(root << 1)|1].sum;
}

long long query(int L, int R, int st = 0, int en = n - 1, int root = 1){
 if(L > en || R < st)
  return 0;
 if(st >= L && en <= R)
  return tree[root].sum;
 apply(root, st, en);
 return query(L, R, st, mid, root << 1) +
    query(L, R, mid + 1, en, (root << 1)|1);
}

int main(){
 //filein;
 io;

 cin >> n >> m;
 build();

 while(m--){
  int t, L, R;
  cin >> t >> L >> R;
  L--, R--;
  if(t == 1){
   int x;
   cin >> x;
   update(L, R, x);
  }else{
   long long ret = query(L, R);
   cout << ret << endl;
  }
 }
 return 0;
}


#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <cassert>
#include <set>
#include <complex>
#include <bitset>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <string>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define eps 1e-8
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen ("in.txt", "r", stdin),freopen ("out.txt", "w", stdout);
#define filein freopen ("in.txt", "r", stdin);
#define all(v) ((v).begin()), ((v).end())
#define mid ((st + en) >> 1)

const int N = 1e5 + 5;

int n, m;

struct node{
 long long sum;
 int x;
 bool f;
};
node tree[N * 4], lazy[N * 4];

inline void build(int st = 0, int en = n - 1, int root = 1){

 if(st == en){
  tree[root].f = 1;
  tree[root].x = st + 1;
  return;
 }
 build(st, mid, root << 1);
 build(mid + 1, en, (root << 1)|1);
}

inline void apply(int root, int st, int en){
 if(lazy[root].x == 0)
  return;

// if(tree[root].x != lazy[root].x)
//  cout << tree[root].x << " " << lazy[root].x << endl;

 int L = root << 1, R = (root << 1)|1;

 tree[L].f = tree[R].f = 1;
 lazy[R].x = lazy[L].x = tree[L].x = tree[R].x = lazy[root].x;
 lazy[R].sum += lazy[root].sum;
 lazy[L].sum += lazy[root].sum;
 tree[L].sum += (mid - st + 1) * 1LL * lazy[root].sum;
 tree[R].sum += (en - mid) * 1LL * lazy[root].sum;
 lazy[root].sum = 0;
}

void update(int L, int R, int x, int st = 0, int en = n - 1,
            int root = 1){

 if(L > en || R < st)
  return;

 if(st >= L && en <= R && tree[root].f){
  tree[root].sum += (en - st + 1) * 1LL * abs(x - tree[root].x);
//  cout << st << " " << en << endl;
//  cout << "tree[root].x " << tree[root].x << endl;
//  cout << "tree[root].sum " << tree[root].sum << endl;
  lazy[root].sum += abs(x - tree[root].x);
  tree[root].x = x;
  lazy[root].x = x;

  return;
 }

 if(tree[root].f)
  apply(root, st, en);

 update(L, R, x, st, mid, root << 1);
 update(L, R, x, mid + 1, en, (root << 1)|1);

 if(tree[root << 1].f && tree[(root << 1)|1].f && tree[root << 1].x
    == tree[(root << 1)|1].x){
  tree[root].f = 1;
  tree[root].x = tree[root << 1].x;
 }else{
  tree[root].f = 0;
  lazy[root].x = 0;
 }

 tree[root].sum = tree[(root << 1)].sum + tree[(root << 1)|1].sum;
}

long long query(int L, int R, int st = 0, int en = n - 1, int root = 1){
 if(L > en || R < st)
  return 0;

 if(st >= L && en <= R)
  return tree[root].sum;

 if(tree[root].f)
  apply(root, st, en);

 return query(L, R, st, mid, root << 1) +
    query(L, R, mid + 1, en, (root << 1)|1);
}

int main(){
 //filein;
 io;

 cin >> n >> m;
 build();

 while(m--){
  int t, L, R;
  cin >> t >> L >> R;
  L--, R--;
  if(t == 1){
   int x;
   cin >> x;
   update(L, R, x);
  }else{
   long long ret = query(L, R);
   cout << ret << endl;
  }
 }
 return 0;
}


#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <cassert>
#include <set>
#include <complex>
#include <bitset>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <string>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define eps 1e-8
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen ("in.txt", "r", stdin),freopen ("out.txt", "w", stdout);
#define filein freopen ("in.txt", "r", stdin);
#define all(v) ((v).begin()), ((v).end())
#define mid ((st + en) >> 1)

const int N = 1e5 + 5;

int n, m;

struct range{
 int L, R, x;
 range(int L, int R, int x) : L(L), R(R), x(x){}
 bool operator<(const range &that) const{
  if(L != that.L)
   return L < that.L;
  assert(R != that.R);
  return R < that.R;
 }
};

set<range> st;

long long tree[N * 4], lazy[N * 4];

inline void apply(int root, int st, int en, int L, int R){
 lazy[R] += lazy[root];
 lazy[L] += lazy[root];
 tree[L] += (mid - st + 1) * 1LL * lazy[root];
 tree[R] += (en - mid) * 1LL * lazy[root];
 lazy[root] = 0;
}

void update(int L, int R, int x, int st = 0, int en = n - 1,
            int root = 1){
 if(L > en || R < st)
  return;
 if(st >= L && en <= R){
  tree[root] += (en - st + 1) * 1LL * x;
  lazy[root] += x;
  return;
 }
 apply(root, st, en, (root << 1), (root << 1)|1);
 update(L, R, x, st, mid, root << 1);
 update(L, R, x, mid + 1, en, (root << 1)|1);
 tree[root] = tree[(root << 1)] + tree[(root << 1)|1];
}

long long query(int L, int R, int st = 0, int en = n - 1, int root = 1){
 if(L > en || R < st)
  return 0;
 if(st >= L && en <= R)
  return tree[root];
 apply(root, st, en, (root << 1), (root << 1)|1);
 return query(L, R, st, mid, root << 1) +
  query(L, R, mid + 1, en, (root << 1)|1);
}

int main(){
 //filein;
 io;

 cin >> n >> m;
 for(int i = 0; i < n; i++)
  st.insert(range(i, i, i + 1));

 while(m--){
  int t, L, R;
  cin >> t >> L >> R;
  L--, R--;
  if(t == 1){
   int x;
   cin >> x;
   auto it = --st.upper_bound(range(L, N, N));
   for(; it != st.end() && it->L <= R;){
    int Li = it->L, Ri = it->R, xi = it->x;
    if(Li < L)
     st.insert(range(Li, L - 1, xi));
    if(Ri > R)
     st.insert(range(R + 1, Ri, xi));
    update(max(Li, L), min(Ri, R), abs(xi - x));
    st.erase(it++);
   }
   st.insert(range(L, R, x));
  }else{
   long long ret = query(L, R);
   cout << ret << endl;
  }
 }
 return 0;
}


#include <iostream>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include <cassert>
#include <set>
#include <complex>
#include <bitset>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <string>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define eps 1e-8
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen ("in.txt", "r", stdin),freopen ("out.txt", "w", stdout);
#define filein freopen ("in.txt", "r", stdin);
#define all(v) ((v).begin()), ((v).end())
#define mid ((st + en) >> 1)

const int N = 1e5 + 5;

int n, m;

struct node{
 long long sum;
 int x;
 bool f;
};
node tree[N * 4], lazy[N * 4];

inline void build(int st = 0, int en = n - 1, int root = 1){

 if(st == en){
  tree[root].f = 1;
  tree[root].x = st + 1;
  return;
 }
 build(st, mid, root << 1);
 build(mid + 1, en, (root << 1)|1);
}

inline void apply(int root, int st, int en){
 if(lazy[root].x == 0)
  return;

// if(tree[root].x != lazy[root].x)
//  cout << tree[root].x << " " << lazy[root].x << endl;

 int L = root << 1, R = (root << 1)|1;

 tree[L].f = tree[R].f = 1;
 lazy[R].x = lazy[L].x = tree[L].x = tree[R].x = lazy[root].x;
 lazy[R].sum += lazy[root].sum;
 lazy[L].sum += lazy[root].sum;
 tree[L].sum += (mid - st + 1) * 1LL * lazy[root].sum;
 tree[R].sum += (en - mid) * 1LL * lazy[root].sum;
 lazy[root].sum = 0;
}

void update(int L, int R, int x, int st = 0, int en = n - 1,
            int root = 1){

 if(L > en || R < st)
  return;

 if(st >= L && en <= R && tree[root].f){
  tree[root].sum += (en - st + 1) * 1LL * abs(x - tree[root].x);
//  cout << st << " " << en << endl;
//  cout << "tree[root].x " << tree[root].x << endl;
//  cout << "tree[root].sum " << tree[root].sum << endl;
  lazy[root].sum += abs(x - tree[root].x);
  tree[root].x = x;
  lazy[root].x = x;

  return;
 }

 if(tree[root].f)
  apply(root, st, en);

 update(L, R, x, st, mid, root << 1);
 update(L, R, x, mid + 1, en, (root << 1)|1);

 if(tree[root << 1].f && tree[(root << 1)|1].f && tree[root << 1].x
    == tree[(root << 1)|1].x){
  tree[root].f = 1;
  tree[root].x = tree[root << 1].x;
 }else{
  tree[root].f = 0;
  lazy[root].x = 0;
 }

 tree[root].sum = tree[(root << 1)].sum + tree[(root << 1)|1].sum;
}

long long query(int L, int R, int st = 0, int en = n - 1, int root = 1){
 if(L > en || R < st)
  return 0;

 if(st >= L && en <= R && tree[root].f)
  return tree[root].sum;

 if(tree[root].f)
  apply(root, st, en);

 return query(L, R, st, mid, root << 1) +
    query(L, R, mid + 1, en, (root << 1)|1);
}

int main(){
 //filein;
 io;

 cin >> n >> m;
 build();

 while(m--){
  int t, L, R;
  cin >> t >> L >> R;
  L--, R--;
  if(t == 1){
   int x;
   cin >> x;
   update(L, R, x);
  }else{
   long long ret = query(L, R);
   cout << ret << endl;
  }
 }
 return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 100900
#define INF 0x3f3f3f3f
#define ls (now << 1)
#define rs (now << 1 | 1)
#define mid ((l + r) >> 1)

int n , m;
int sml[MAX * 4] , big[MAX * 4] , tag[MAX * 4] , sum[MAX * 4] , val[MAX * 4];

void Pull(int now , int l , int r){
    sml[now] = min(sml[ls] , sml[rs]);
    big[now] = max(big[ls] , big[rs]);
    sum[now] = sum[ls] + sum[rs];
    val[now] = val[ls] + val[rs];
}
void Build(int now , int l , int r){
    if(l == r){
        sml[now] = big[now] = sum[now] = l;
        tag[now] = val[now] = 0;
    }
    else {
        Build(ls , l , mid) , Build(rs , mid + 1 , r);
        Pull(now , l , r);
    }
}

int Push(int now , int l , int r){
    if(tag[now] && l != r){
        Push(ls , l , mid + 0);
        Push(rs , mid + 1 , r);

        int lsiz = (mid - l + 1) , rsiz = (r - (mid + 1) + 1);
        sml[ls] = big[ls] = tag[ls] = tag[now];
        val[ls] += abs(tag[now] * lsiz - sum[ls]);
        sum[ls] = lsiz * tag[now];

        sml[rs] = big[rs] = tag[rs] = tag[now];
        val[rs] += abs(tag[now] * rsiz - sum[rs]);
        sum[rs] = rsiz * tag[now];

    }
    tag[now] = 0;
}
// int sml[MAX * 4] , big[MAX * 4] , tag[MAX * 4] , sum[MAX * 4] , val[MAX];
void update(int now , int l , int r , int ql , int qr , int v){
    Push(now , l , r);
    int siz = r - l + 1;
    if(ql <= l && r <= qr){
        if(big[now] <= v || sml[now] >= v){
            sml[now] = big[now] = tag[now] = v;
            val[now] += abs(v * siz - sum[now]);
            sum[now] = v * siz;
            return;
        }
        else {
            update(ls , l , mid + 0 , ql , qr , v);
            update(rs , mid + 1 , r , ql , qr , v);
            Pull(now , l , r);
            return;
        }
    }
    else{
        if(qr <= mid + 0)      update(ls , l , mid + 0 , ql , qr , v);
        else if(mid + 1 <= ql) update(rs , mid + 1 , r , ql , qr , v);
        else {
            update(ls , l , mid + 0 , ql , qr , v);
            update(rs , mid + 1 , r , ql , qr , v);
        }
        Pull(now , l , r);
    }
}
int query(int now , int l , int r , int ql , int qr){
    Push(now , l , r);
    if(ql <= l && r <= qr) return val[now];
    else if(qr <= mid + 0) return query(ls , l , mid + 0 , ql , qr);
    else if(mid + 1 <= ql) return query(rs , mid + 1 , r , ql , qr);
    return query(ls , l , mid + 0 , ql , qr) + query(rs , mid + 1 , r , ql , qr);
}
int32_t main(){
    IOS;
    cin >> n >> m;
    Build(1 , 1 , n);
    REP(i , 1 , m + 1){
        int ty , l , r , v;
        cin >> ty >> l >> r;
        if(ty == 1){
            cin >> v;
            update(1 , 1 , n , l , r , v);
        }
        else cout << query(1 , 1 , n , l , r) << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 100900
#define INF 0x3f3f3f3f
#define ls (now << 1)
#define rs (now << 1 | 1)
#define mid ((l + r) >> 1)

int n , m;
int sml[MAX * 4] , big[MAX * 4] , tag[MAX * 4] , sum[MAX * 4] , val[MAX * 4];

void Pull(int now , int l , int r){
    sml[now] = min(sml[ls] , sml[rs]);
    big[now] = max(big[ls] , big[rs]);
    sum[now] = sum[ls] + sum[rs];
    val[now] = val[ls] + val[rs];
}
void Build(int now , int l , int r){
    if(l == r){
        sml[now] = big[now] = sum[now] = l;
        tag[now] = val[now] = 0;
    }
    else {
        Build(ls , l , mid) , Build(rs , mid + 1 , r);
        Pull(now , l , r);
    }
}

int Push(int now , int l , int r){
    if(tag[now] && l != r){
        int lsiz = (mid - l + 1) , rsiz = (r - (mid + 1) + 1);
        sml[ls] = big[ls] = tag[ls] = tag[now];
        val[ls] += abs(tag[now] * lsiz - sum[ls]);
        sum[ls] = lsiz * tag[now];
        tag[ls] = tag[now];

        sml[rs] = big[rs] = tag[rs] = tag[now];
        val[rs] += abs(tag[now] * rsiz - sum[rs]);
        sum[rs] = rsiz * tag[now];
        tag[rs] = tag[now];
        tag[now] = 0;
    }
}
// int sml[MAX * 4] , big[MAX * 4] , tag[MAX * 4] , sum[MAX * 4] , val[MAX];
void update(int now , int l , int r , int ql , int qr , int v){
    Push(now , l , r);
    int siz = r - l + 1;
    if(ql <= l && r <= qr){
        if(big[now] <= v || sml[now] >= v){
            sml[now] = big[now] = tag[now] = v;
            val[now] += abs(v * siz - sum[now]);
            sum[now] = v * siz;
            return;
        }
        else {
            update(ls , l , mid + 0 , ql , qr , v);
            update(rs , mid + 1 , r , ql , qr , v);
            Pull(now , l , r);
        }
    }
    else{
        if(qr <= mid)          update(ls , l , mid + 0 , ql , qr , v);
        else if(mid + 1 <= ql) update(rs , mid + 1 , r , ql , qr , v);
        else {
            update(ls , l , mid + 0 , ql , qr , v);
            update(rs , mid + 1 , r , ql , qr , v);
        }
        Pull(now , l , r);
    }
}
int query(int now , int l , int r , int ql , int qr){
    Push(now , l , r);
    if(ql <= l && r <= qr) return val[now];
    else if(qr <= mid + 0) return query(ls , l , mid + 0 , ql , qr);
    else if(mid + 1 <= ql) return query(rs , mid + 1 , r , ql , qr);
    return query(ls , l , mid + 0 , ql , qr) , query(rs , mid + 1 , r , ql , qr);
}
int32_t main(){
    IOS;
    cin >> n >> m;
    Build(1 , 1 , n);
    REP(i , 1 , m + 1){
        int ty , l , r , v;
        cin >> ty >> l >> r;
        if(ty == 1){
            cin >> v;
            update(1 , 1 , n , l , r , v);
        }
        else cout << query(1 , 1 , n , l , r) << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 100900
#define INF 0x3f3f3f3f
#define ls (now << 1)
#define rs (now << 1 | 1)
#define mid ((l + r) >> 1)

int n , m;
int sml[MAX * 4] , big[MAX * 4] , tag[MAX * 4] , sum[MAX * 4] , val[MAX];

void Pull(int now , int l , int r){
    sml[now] = min(sml[ls] , sml[rs]);
    big[now] = max(big[ls] , big[rs]);
    sum[now] = sum[ls] + sum[rs];
    val[now] = val[ls] + val[rs];
}
void Build(int now , int l , int r){
    // DB4(now , l , r , "QQ");
    if(l == r){
        sml[now] = big[now] = sum[now] = l;
        tag[now] = -1 , val[now] = 0;
    }
    else {
        tag[now] = -1;
        Build(ls , l , mid) , Build(rs , mid + 1 , r);
        Pull(now , l , r);
        // DB4("now = " , l , r , sum[now]);
    }
}

int Push(int now , int l , int r){
    if(tag[now] != -1 && l != r){
        int lsiz = (mid - l + 1) , rsiz = (r - (mid + 1) + 1);
        sml[ls] = big[ls] = tag[ls] = tag[now];
        val[ls] += abs(tag[now] * lsiz - sum[ls]);
        sum[ls] = lsiz * tag[now];

        sml[rs] = big[rs] = tag[rs] = tag[now];
        val[rs] += abs(tag[now] * rsiz - sum[rs]);
        sum[rs] = rsiz * tag[now];
        tag[now] = -1;
    }
}
// int sml[MAX * 4] , big[MAX * 4] , tag[MAX * 4] , sum[MAX * 4] , val[MAX];
void update(int now , int l , int r , int ql , int qr , int v){
    // DB4("update" , l , r , sum[now]);
    Push(now , l , r);
    int siz = r - l + 1;
    if(ql <= l && r <= qr){
        if(big[now] <= v || sml[now] >= v){
            // cout << "======\t\t";DB4(v , siz , "=" , sum[now]);
            val[now] += abs(v * siz - sum[now]);

            tag[now] = v;
            sml[now] = big[now] = v;
            sum[now] = v * siz;
            return;
        }
        else {
            update(ls , l , mid + 0 , ql , qr , v);
            update(rs , mid + 1 , r , ql , qr , v);
        }
    }
    else{
        if(qr <= mid)     update(ls , l , mid + 0 , ql , qr , v);
        else if(mid + 1 <= ql) update(rs , mid + 1 , r , ql , qr , v);
        else {
            update(ls , l , mid + 0 , ql , qr , v);
            update(rs , mid + 1 , r , ql , qr , v);
        }
        Pull(now , l , r);
    }
}
int query(int now , int l , int r , int ql , int qr){
    Push(now , l , r);
    if(ql <= l && r <= qr) return val[now];
    else if(qr <= mid + 0) return query(ls , l , mid + 0 , ql , qr);
    else if(mid + 1 <= ql) return query(rs , mid + 1 , r , ql , qr);
    return query(ls , l , mid + 0 , ql , qr) , query(rs , mid + 1 , r , ql , qr);
}
int32_t main(){
    IOS;
    cin >> n >> m;
    Build(1 , 1 , n);
    REP(i , 1 , m + 1){
        int ty , l , r , v;
        cin >> ty >> l >> r;
        if(ty == 1){
            cin >> v;
            update(1 , 1 , n , l , r , v);
        }
        else cout << query(1 , 1 , n , l , r) << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 100900
#define INF 0x3f3f3f3f
#define ls (now << 1)
#define rs (now << 1 | 1)
#define mid ((l + r) >> 1)

int n , m;
int sml[MAX * 4] , big[MAX * 4] , tag[MAX * 4] , add[MAX * 4] , val[MAX * 4];
inline void Pull(int now , int l , int r){
    sml[now] = min(sml[ls] , sml[rs]);
    big[now] = max(big[ls] , big[rs]);
    val[now] = val[ls] + val[rs];
}
inline void Build(int now , int l , int r){
    if(l == r){
        sml[now] = big[now] = l;
        tag[now] = val[now] = 0;
    }
    else {
        Build(ls , l , mid) , Build(rs , mid + 1 , r);
        Pull(now , l , r);
    }
}
inline int Push(int now , int l , int r){
    if(add[now] && l != r){
        val[ls] += add[now] * (mid - l + 1);
        val[rs] += add[now] * (r - (mid + 1) + 1);
        add[ls] += add[now];
        add[rs] += add[now];
        add[now] = 0;
    }
    if(tag[now] && l != r){
        sml[ls] = big[ls] = tag[ls] = tag[now];
        sml[rs] = big[rs] = tag[rs] = tag[now];
        tag[now] = 0;
    }
}
inline void update(int now , int l , int r , int ql , int qr , int v){
    Push(now , l , r);
    int siz = r - l + 1;
    if(ql <= l && r <= qr){
        if(sml[now] == big[now]){
            add[now] = abs(v - sml[now]);
            sml[now] = big[now] = tag[now] = v;
            val[now] += add[now] * (r - l + 1);
        }
        else {
            update(ls , l , mid + 0 , ql , qr , v);
            update(rs , mid + 1 , r , ql , qr , v);
            Pull(now , l , r);
            return;
        }
    }
    else{
        if(qr <= mid + 0)      update(ls , l , mid + 0 , ql , qr , v);
        else if(mid + 1 <= ql) update(rs , mid + 1 , r , ql , qr , v);
        else {
            update(ls , l , mid + 0 , ql , qr , v);
            update(rs , mid + 1 , r , ql , qr , v);
        }
        Pull(now , l , r);
    }
}
inline int query(int now , int l , int r , int ql , int qr){
    Push(now , l , r);
    if(ql <= l && r <= qr) return val[now];
    else if(qr <= mid + 0) return query(ls , l , mid + 0 , ql , qr);
    else if(mid + 1 <= ql) return query(rs , mid + 1 , r , ql , qr);
    return query(ls , l , mid + 0 , ql , qr) + query(rs , mid + 1 , r , ql , qr);
}
int32_t main(){
    IOS;
    cin >> n >> m;
    Build(1 , 1 , n);
    REP(i , 1 , m + 1){
        int ty , l , r , v;
        cin >> ty >> l >> r;
        if(ty == 1){
            cin >> v;
            update(1 , 1 , n , l , r , v);
        }
        else cout << query(1 , 1 , n , l , r) << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 100900
#define INF 0x3f3f3f3f
#define ls (now << 1)
#define rs (now << 1 | 1)
#define mid ((l + r) >> 1)

int n , m;
int sml[MAX * 4] , big[MAX * 4] , tag[MAX * 4] , sum[MAX * 4] , val[MAX * 4];

void Pull(int now , int l , int r){
    sml[now] = min(sml[ls] , sml[rs]);
    big[now] = max(big[ls] , big[rs]);
    sum[now] = sum[ls] + sum[rs];
    val[now] = val[ls] + val[rs];
}
void Build(int now , int l , int r){
    if(l == r){
        sml[now] = big[now] = sum[now] = l;
        tag[now] = val[now] = 0;
    }
    else {
        Build(ls , l , mid) , Build(rs , mid + 1 , r);
        Pull(now , l , r);
    }
}

int Push(int now , int l , int r){
    if(tag[now] && l != r){
        if(tag[ls]) Push(ls , l , mid + 0);
        if(tag[rs]) Push(rs , mid + 1 , r);
        int lsiz = (mid - l + 1) , rsiz = (r - (mid + 1) + 1);
        sml[ls] = big[ls] = tag[ls] = tag[now];
        val[ls] += abs(tag[now] * lsiz - sum[ls]);
        sum[ls] = lsiz * tag[now];

        sml[rs] = big[rs] = tag[rs] = tag[now];
        val[rs] += abs(tag[now] * rsiz - sum[rs]);
        sum[rs] = rsiz * tag[now];

        tag[now] = 0;
    }
}
// int sml[MAX * 4] , big[MAX * 4] , tag[MAX * 4] , sum[MAX * 4] , val[MAX];
void update(int now , int l , int r , int ql , int qr , int v){
    Push(now , l , r);
    int siz = r - l + 1;
    if(ql <= l && r <= qr){
        if(big[now] <= v || sml[now] >= v){
            sml[now] = big[now] = tag[now] = v;
            val[now] += abs(v * siz - sum[now]);
            sum[now] = v * siz;
            return;
        }
        else {
            update(ls , l , mid + 0 , ql , qr , v);
            update(rs , mid + 1 , r , ql , qr , v);
            Pull(now , l , r);
        }
    }
    else{
        if(qr <= mid)          update(ls , l , mid + 0 , ql , qr , v);
        else if(mid + 1 <= ql) update(rs , mid + 1 , r , ql , qr , v);
        else {
            update(ls , l , mid + 0 , ql , qr , v);
            update(rs , mid + 1 , r , ql , qr , v);
        }
        Pull(now , l , r);
    }
}
int query(int now , int l , int r , int ql , int qr){
    Push(now , l , r);
    if(ql <= l && r <= qr) return val[now];
    else if(qr <= mid + 0) return query(ls , l , mid + 0 , ql , qr);
    else if(mid + 1 <= ql) return query(rs , mid + 1 , r , ql , qr);
    return query(ls , l , mid + 0 , ql , qr) , query(rs , mid + 1 , r , ql , qr);
}
int32_t main(){
    IOS;
    cin >> n >> m;
    Build(1 , 1 , n);
    REP(i , 1 , m + 1){
        int ty , l , r , v;
        cin >> ty >> l >> r;
        if(ty == 1){
            cin >> v;
            update(1 , 1 , n , l , r , v);
        }
        else cout << query(1 , 1 , n , l , r) << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 100900
#define INF 0x3f3f3f3f
#define ls (now << 1)
#define rs (now << 1 | 1)
#define mid ((l + r) >> 1)

int n , m;
int sml[MAX * 4] , big[MAX * 4] , tag[MAX * 4] , sum[MAX * 4] , val[MAX * 4];

void Pull(int now , int l , int r){
    sml[now] = min(sml[ls] , sml[rs]);
    big[now] = max(big[ls] , big[rs]);
    sum[now] = sum[ls] + sum[rs];
    val[now] = val[ls] + val[rs];
}
void Build(int now , int l , int r){
    if(l == r){
        sml[now] = big[now] = sum[now] = l;
        tag[now] = val[now] = 0;
    }
    else {
        Build(ls , l , mid) , Build(rs , mid + 1 , r);
        Pull(now , l , r);
    }
}

int Push(int now , int l , int r){
    if(tag[now] && l != r){
        int lsiz = (mid - l + 1) , rsiz = (r - (mid + 1) + 1);
        sml[ls] = big[ls] = tag[ls] = tag[now];
        val[ls] += abs(tag[now] * lsiz - sum[ls]);
        sum[ls] = lsiz * tag[now];

        sml[rs] = big[rs] = tag[rs] = tag[now];
        val[rs] += abs(tag[now] * rsiz - sum[rs]);
        sum[rs] = rsiz * tag[now];
        tag[now] = 0;
    }
}
// int sml[MAX * 4] , big[MAX * 4] , tag[MAX * 4] , sum[MAX * 4] , val[MAX];
void update(int now , int l , int r , int ql , int qr , int v){
    Push(now , l , r);
    int siz = r - l + 1;
    if(ql <= l && r <= qr){
        if(big[now] <= v || sml[now] >= v){
            sml[now] = big[now] = tag[now] = v;
            val[now] += abs(v * siz - sum[now]);
            sum[now] = v * siz;
            return;
        }
        else {
            update(ls , l , mid + 0 , ql , qr , v);
            update(rs , mid + 1 , r , ql , qr , v);
            Pull(now , l , r);
        }
    }
    else{
        if(qr <= mid)          update(ls , l , mid + 0 , ql , qr , v);
        else if(mid + 1 <= ql) update(rs , mid + 1 , r , ql , qr , v);
        else {
            update(ls , l , mid + 0 , ql , qr , v);
            update(rs , mid + 1 , r , ql , qr , v);
        }
        Pull(now , l , r);
    }
}
int query(int now , int l , int r , int ql , int qr){
    Push(now , l , r);
    if(ql <= l && r <= qr) return val[now];
    else if(qr <= mid + 0) return query(ls , l , mid + 0 , ql , qr);
    else if(mid + 1 <= ql) return query(rs , mid + 1 , r , ql , qr);
    return query(ls , l , mid + 0 , ql , qr) , query(rs , mid + 1 , r , ql , qr);
}
int32_t main(){
    IOS;
    cin >> n >> m;
    Build(1 , 1 , n);
    REP(i , 1 , m + 1){
        int ty , l , r , v;
        cin >> ty >> l >> r;
        if(ty == 1){
            cin >> v;
            update(1 , 1 , n , l , r , v);
        }
        else cout << query(1 , 1 , n , l , r) << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 100900
#define INF 0x3f3f3f3f
#define ls (now << 1)
#define rs (now << 1 | 1)
#define mid ((l + r) >> 1)

int n , m;
int sml[MAX * 4] , big[MAX * 4] , tag[MAX * 4] , sum[MAX * 4] , val[MAX];

void Pull(int now , int l , int r){
    sml[now] = min(sml[ls] , sml[rs]);
    big[now] = max(big[ls] , big[rs]);
    sum[now] = sum[ls] + sum[rs];
    val[now] = val[ls] + val[rs];
}
void Build(int now , int l , int r){
    if(l == r){
        sml[now] = big[now] = sum[now] = l;
        tag[now] = val[now] = 0;
    }
    else {
        Build(ls , l , mid) , Build(rs , mid + 1 , r);
        Pull(now , l , r);
    }
}

int Push(int now , int l , int r){
    if(tag[now] && l != r){
        int lsiz = (mid - l + 1) , rsiz = (r - (mid + 1) + 1);
        sml[ls] = big[ls] = tag[ls] = tag[now];
        val[ls] += abs(tag[now] * lsiz - sum[ls]);
        sum[ls] = lsiz * tag[now];

        sml[rs] = big[rs] = tag[rs] = tag[now];
        val[rs] += abs(tag[now] * rsiz - sum[rs]);
        sum[rs] = rsiz * tag[now];
        tag[now] = 0;
    }
}
// int sml[MAX * 4] , big[MAX * 4] , tag[MAX * 4] , sum[MAX * 4] , val[MAX];
void update(int now , int l , int r , int ql , int qr , int v){
    Push(now , l , r);
    int siz = r - l + 1;
    if(ql <= l && r <= qr){
        if(big[now] <= v || sml[now] >= v){
            sml[now] = big[now] = tag[now] = v;
            val[now] += abs(v * siz - sum[now]);
            sum[now] = v * siz;
            return;
        }
        else {
            update(ls , l , mid + 0 , ql , qr , v);
            update(rs , mid + 1 , r , ql , qr , v);
            Pull(now , l , r);
        }
    }
    else{
        if(qr <= mid)          update(ls , l , mid + 0 , ql , qr , v);
        else if(mid + 1 <= ql) update(rs , mid + 1 , r , ql , qr , v);
        else {
            update(ls , l , mid + 0 , ql , qr , v);
            update(rs , mid + 1 , r , ql , qr , v);
        }
        Pull(now , l , r);
    }
}
int query(int now , int l , int r , int ql , int qr){
    Push(now , l , r);
    if(ql <= l && r <= qr) return val[now];
    else if(qr <= mid + 0) return query(ls , l , mid + 0 , ql , qr);
    else if(mid + 1 <= ql) return query(rs , mid + 1 , r , ql , qr);
    return query(ls , l , mid + 0 , ql , qr) , query(rs , mid + 1 , r , ql , qr);
}
int32_t main(){
    IOS;
    cin >> n >> m;
    Build(1 , 1 , n);
    REP(i , 1 , m + 1){
        int ty , l , r , v;
        cin >> ty >> l >> r;
        if(ty == 1){
            cin >> v;
            update(1 , 1 , n , l , r , v);
        }
        else cout << query(1 , 1 , n , l , r) << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 100900
#define INF 0x3f3f3f3f
#define ls (now << 1)
#define rs (now << 1 | 1)
#define mid ((l + r) >> 1)

int n , m;
int sml[MAX * 4] , big[MAX * 4] , tag[MAX * 4] , sum[MAX * 4] , val[MAX * 4];

inline void Pull(int now , int l , int r){
    sml[now] = min(sml[ls] , sml[rs]);
    big[now] = max(big[ls] , big[rs]);
    sum[now] = sum[ls] + sum[rs];
    val[now] = val[ls] + val[rs];
}
inline void Build(int now , int l , int r){
    if(l == r){
        sml[now] = big[now] = sum[now] = l;
        tag[now] = val[now] = 0;
    }
    else {
        Build(ls , l , mid) , Build(rs , mid + 1 , r);
        Pull(now , l , r);
    }
}

inline int Push(int now , int l , int r){
    if(tag[now] && l != r){
        if(tag[now] != tag[ls]) Push(ls , l , mid + 0);
        if(tag[now] != tag[rs]) Push(rs , mid + 1 , r);

        int lsiz = (mid - l + 1) , rsiz = (r - (mid + 1) + 1);
        sml[ls] = big[ls] = tag[ls] = tag[now];
        val[ls] += abs(tag[now] * lsiz - sum[ls]);
        sum[ls] = lsiz * tag[now];

        sml[rs] = big[rs] = tag[rs] = tag[now];
        val[rs] += abs(tag[now] * rsiz - sum[rs]);
        sum[rs] = rsiz * tag[now];

    }
    tag[now] = 0;
}
// int sml[MAX * 4] , big[MAX * 4] , tag[MAX * 4] , sum[MAX * 4] , val[MAX];
inline void update(int now , int l , int r , int ql , int qr , int v){
    Push(now , l , r);
    int siz = r - l + 1;
    if(ql <= l && r <= qr){
        if(sml[now] == v && big[now] == v) return ;
        if(big[now] <= v || sml[now] >= v){
            sml[now] = big[now] = tag[now] = v;
            val[now] += abs(v * siz - sum[now]);
            sum[now] = v * siz;
            return;
        }
        else {
            update(ls , l , mid + 0 , ql , qr , v);
            update(rs , mid + 1 , r , ql , qr , v);
            Pull(now , l , r);
            return;
        }
    }
    else{
        if(qr <= mid + 0)      update(ls , l , mid + 0 , ql , qr , v);
        else if(mid + 1 <= ql) update(rs , mid + 1 , r , ql , qr , v);
        else {
            update(ls , l , mid + 0 , ql , qr , v);
            update(rs , mid + 1 , r , ql , qr , v);
        }
        Pull(now , l , r);
    }
}
inline int query(int now , int l , int r , int ql , int qr){
    Push(now , l , r);
    if(ql <= l && r <= qr) return val[now];
    else if(qr <= mid + 0) return query(ls , l , mid + 0 , ql , qr);
    else if(mid + 1 <= ql) return query(rs , mid + 1 , r , ql , qr);
    return query(ls , l , mid + 0 , ql , qr) + query(rs , mid + 1 , r , ql , qr);
}
int32_t main(){
    IOS;
    cin >> n >> m;
    Build(1 , 1 , n);
    REP(i , 1 , m + 1){
        int ty , l , r , v;
        cin >> ty >> l >> r;
        if(ty == 1){
            cin >> v;
            update(1 , 1 , n , l , r , v);
        }
        else cout << query(1 , 1 , n , l , r) << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 100900
#define INF 0x3f3f3f3f
#define ls (now << 1)
#define rs (now << 1 | 1)
#define mid ((l + r) >> 1)

int n , m;
int sml[MAX * 4] , big[MAX * 4] , tag[MAX * 4] , sum[MAX * 4] , val[MAX * 4];

void Pull(int now , int l , int r){
    sml[now] = min(sml[ls] , sml[rs]);
    big[now] = max(big[ls] , big[rs]);
    sum[now] = sum[ls] + sum[rs];
    val[now] = val[ls] + val[rs];
}
void Build(int now , int l , int r){
    if(l == r){
        sml[now] = big[now] = sum[now] = l;
        tag[now] = val[now] = 0;
    }
    else {
        Build(ls , l , mid) , Build(rs , mid + 1 , r);
        Pull(now , l , r);
    }
}

int Push(int now , int l , int r){
    if(tag[now] && l != r){
        Push(ls , l , mid + 0);
        Push(rs , mid + 1 , r);
        Pull(now , l , r);
        int lsiz = (mid - l + 1) , rsiz = (r - (mid + 1) + 1);
        sml[ls] = big[ls] = tag[ls] = tag[now];
        val[ls] += abs(tag[now] * lsiz - sum[ls]);
        sum[ls] = lsiz * tag[now];

        sml[rs] = big[rs] = tag[rs] = tag[now];
        val[rs] += abs(tag[now] * rsiz - sum[rs]);
        sum[rs] = rsiz * tag[now];

        tag[now] = 0;
    }
}
// int sml[MAX * 4] , big[MAX * 4] , tag[MAX * 4] , sum[MAX * 4] , val[MAX];
void update(int now , int l , int r , int ql , int qr , int v){
    Push(now , l , r);
    int siz = r - l + 1;
    if(ql <= l && r <= qr){
        if(big[now] <= v || sml[now] >= v){
            sml[now] = big[now] = tag[now] = v;
            val[now] += abs(v * siz - sum[now]);
            sum[now] = v * siz;
            return;
        }
        else {
            update(ls , l , mid + 0 , ql , qr , v);
            update(rs , mid + 1 , r , ql , qr , v);
            Pull(now , l , r);
        }
    }
    else{
        if(qr <= mid)          update(ls , l , mid + 0 , ql , qr , v);
        else if(mid + 1 <= ql) update(rs , mid + 1 , r , ql , qr , v);
        else {
            update(ls , l , mid + 0 , ql , qr , v);
            update(rs , mid + 1 , r , ql , qr , v);
        }
        Pull(now , l , r);
    }
}
int query(int now , int l , int r , int ql , int qr){
    Push(now , l , r);
    if(ql <= l && r <= qr) return val[now];
    else if(qr <= mid + 0) return query(ls , l , mid + 0 , ql , qr);
    else if(mid + 1 <= ql) return query(rs , mid + 1 , r , ql , qr);
    return query(ls , l , mid + 0 , ql , qr) , query(rs , mid + 1 , r , ql , qr);
}
int32_t main(){
    IOS;
    cin >> n >> m;
    Build(1 , 1 , n);
    REP(i , 1 , m + 1){
        int ty , l , r , v;
        cin >> ty >> l >> r;
        if(ty == 1){
            cin >> v;
            update(1 , 1 , n , l , r , v);
        }
        else cout << query(1 , 1 , n , l , r) << endl;
    }
    return 0;
}


// In The Name Of God :
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std ;
using namespace __gnu_pbds;
#define X first
#define Y second
//#define int long long
typedef long long ll ;
typedef pair < long long , long long > pii ;
typedef pair < pii , long long > pii_i ;
#define ordered_set(TYPE) tree<TYPE, null_type, less<TYPE>, rb_tree_tag, tree_order_statistics_node_update>
//#define "%I64d" "%I64d"
const long long maxn = 1e5 + 20 ;
const long long maxL = 20 ;
//const int inf = 1e12 ;
int n , m , ar [ maxn ] ;
ll data [ 4 * maxn ] ;
ll flag [ 4 * maxn ] ;
set < int > ST ;

void relax_flag ( const ll &st , const ll &en ,const  int id )
{
  data [ id ] += (en-st)*flag[id] ;
  if ( en - st > 1 )
    {
      flag [ id<<1 ] += flag [ id ] ;
      flag [ id<<1^1 ] += flag [ id ] ;
    }
  flag [ id ] = 0 ;
}

int get ( const int &l ,const  int &r , ll st = 0 , ll en = n , int id = 1 )
{
  relax_flag ( st , en , id ) ;
  if ( r <= st || en <= l )
    return 0 ;
  if ( l <= st && en <= r )
    return data [ id ] ;
  int mid = ( st + en ) >> 1 ;
  return get ( l , r , st , mid , id<<1 ) +
    get( l , r , mid , en , id<<1^1 ) ;
}

void add (const  int &l ,const int &r ,const ll &val , ll st = 0 , ll en = n , int id = 1 )
{
  relax_flag ( st , en , id ) ;
  if ( r <= st || en <= l )
    return ;
  if ( l <= st && en <= r )
    {
      flag [ id ] += val ;
      relax_flag ( st , en , id ) ;
      return ;
    }
  int mid = ( st + en ) >> 1 ;
  add ( l , r , val , st , mid , id<<1 ) ;
  add ( l , r , val , mid , en , id<<1^1 ) ;
  data [ id ] = get ( st , mid , st , mid , id<<1 ) +
    get ( mid , en , mid , en , id<<1^1 ) ;
}

main ( )
{
  scanf ( "%d%d" , &n , &m ) ;
  for ( int i = 0 ; i < n ; i ++ )
    ST . insert ( i ) , ar [ i ] = i + 1 ;
  ST . insert ( n ) ;
  int type , l , r , c ;

  for ( int i = 0 ; i < m ; i ++ )
    {
      scanf ( "%d" , &type ) ;
      if ( type == 1 )
	{
	  scanf ( "%d%d%d" , &l , &r , &c ) ;
	  l -- ;
	  set < int > :: iterator it = lower_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  /*if ( ST . find ( l ) == ST . end ( ) )
	    ar [ l ] = ar [ *((lower_bound(ST.begin(),ST.end(),l)--)) ] ;
	  if ( ST . find ( r ) == ST . end ( ) )
	    ar [ r ] = ar [ *((lower_bound(ST.begin(),ST.end(),r)--)) ] ;
	  */
	    if ( *it != l )
	    {
	      it -- ;
	      ar [ l ] = ar [ *it ] ;
	    }
	  it = lower_bound ( ST . begin ( ) , ST . end ( ) , r ) ;
	  if ( *it != r )
	    {
	      it -- ;
	      ar [ r ] = ar [ *it ] ;
	      //	      ST . erase ( *it ) ;
	    }
	  ST . insert ( r ) ;
	  ST . insert ( l ) ;
	  it = upper_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  int cur = l ;
	  while ( 1 )
	    {
	      //	      cerr << "ADD: " << cur << ' ' << *it << ' ' << abs ( c - ar [ cur ] ) << endl ;
	      add ( cur , *it , abs ( c - ar [ cur ] ) ) ;
	      cur = *it ;
	      if ( cur == r )
		break ;
	      it ++ ;
	    }
	  ar [ l ] = c ;
	  it = upper_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  while ( *it < r )
	    {
	      cur = *it ;
	      it ++ ;
	      ST . erase ( cur ) ;
	    }
	}
      else
	scanf("%d%d" , &l , &r ) , printf("%d\n" , get ( l - 1 , r ) ) ;
    }
}


// In The Name Of God :
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std ;
using namespace __gnu_pbds;
#define X first
#define Y second
//#define int long long
typedef int ll ;
typedef pair < long long , long long > pii ;
typedef pair < pii , long long > pii_i ;
#define ordered_set(TYPE) tree<TYPE, null_type, less<TYPE>, rb_tree_tag, tree_order_statistics_node_update>
//#define "%I64d" "%I64d"
const long long maxn = 1e5 + 20 ;
const long long maxL = 20 ;
//const int inf = 1e12 ;
int n , m , ar [ maxn ] ;
ll data [ 4 * maxn ] ;
ll flag [ 4 * maxn ] ;
set < int > ST ;

void relax_flag ( const ll &st , const ll &en ,const  int id )
{
  data [ id ] += (en-st)*flag[id] ;
  if ( en - st > 1 )
    {
      flag [ id<<1 ] += flag [ id ] ;
      flag [ id<<1^1 ] += flag [ id ] ;
    }
  flag [ id ] = 0 ;
}

int get ( const int &l ,const  int &r , ll st = 0 , ll en = n , int id = 1 )
{
  relax_flag ( st , en , id ) ;
  if ( r <= st || en <= l )
    return 0 ;
  if ( l <= st && en <= r )
    return data [ id ] ;
  int mid = ( st + en ) >> 1 ;
  return get ( l , r , st , mid , id<<1 ) +
    get( l , r , mid , en , id<<1^1 ) ;
}

void add (const  int &l ,const int &r ,const ll &val , ll st = 0 , ll en = n , int id = 1 )
{
  relax_flag ( st , en , id ) ;
  if ( r <= st || en <= l )
    return ;
  if ( l <= st && en <= r )
    {
      flag [ id ] += val ;
      relax_flag ( st , en , id ) ;
      return ;
    }
  int mid = ( st + en ) >> 1 ;
  add ( l , r , val , st , mid , id<<1 ) ;
  add ( l , r , val , mid , en , id<<1^1 ) ;
  data [ id ] = get ( st , mid , st , mid , id<<1 ) +
    get ( mid , en , mid , en , id<<1^1 ) ;
}

main ( )
{
  scanf ( "%d%d" , &n , &m ) ;
  for ( int i = 0 ; i < n ; i ++ )
    ST . insert ( i ) , ar [ i ] = i + 1 ;
  ST . insert ( n ) ;
  int type , l , r , c ;

  for ( int i = 0 ; i < m ; i ++ )
    {
      scanf ( "%d" , &type ) ;
      if ( type == 1 )
	{
	  scanf ( "%d%d%d" , &l , &r , &c ) ;
	  l -- ;
	  set < int > :: iterator it = lower_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  if ( ST . find ( l ) == ST . end ( ) )
	    it=(lower_bound(ST.begin(),ST.end(),l)), it-- , ar [ l ] = ar [ *it ] ;
	  if ( ST . find ( r ) == ST . end ( ) )
	    it=(lower_bound(ST.begin(),ST.end(),r)), it-- , ar [ r ] = ar [ *it ] ;

	  ST . insert ( r ) ;
	  ST . insert ( l ) ;
	  it = upper_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  int cur = l ;
	  while ( 1 )
	    {
	      //	      cerr << "ADD: " << cur << ' ' << *it << ' ' << abs ( c - ar [ cur ] ) << endl ;
	      add ( cur , *it , abs ( c - ar [ cur ] ) ) ;
	      cur = *it ;
	      if ( cur == r )
		break ;
	      it ++ ;
	    }
	  ar [ l ] = c ;
	  it = upper_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  while ( *it < r )
	    {
	      cur = *it ;
	      it ++ ;
	      ST . erase ( cur ) ;
	    }
	}
      else
	scanf("%d%d" , &l , &r ) , printf("%d\n" , get ( l - 1 , r ) ) ;
    }
}


// In The Name Of God :
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std ;
using namespace __gnu_pbds;
#define X first
#define Y second
typedef long long ll ;
//#define int long long
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef pair < int , int > pii ;
typedef pair < pii , int > pii_i ;
typedef pair < pii , pii > pii_ii ;
#define ordered_set(TYPE) tree<TYPE, null_type, less<TYPE>, rb_tree_tag, tree_order_statistics_node_update>
//#define "%I64d" "%I64d"
const int maxn = 1e5 + 10 ;
const int maxL = 35 ;
//const int inf = 1e15 ;
const int mod = 1e9+7 ;
int  n , m , col [ maxn ] ;
long long  data[4*maxn], flag[4*maxn] ;

void relax_flag(const int  &node,const int  &st,const int  &en){
    data[node] += flag[node]*(en-st);
    if(en != st+1){
      flag[node<<1] += flag[node];
      flag[node<<1^1] += flag[node];
    }
    flag[node] = 0;
}

long long  get(int  node, int  st, int  en, int  l, int  r){
    relax_flag(node, st, en);
    if(st==l && en==r){
        return data[node];
    }
    int  mid = (st+en)>>1;
    if(r<=mid) return get(node<<1, st, mid, l, r);
    if(l>=mid) return get(node<<1^1, mid, en, l, r);
    return get(node<<1, st, mid, l, mid)+
      get(node<<1^1, mid, en, mid, r);
}

void add(int  node, int  st, int  en, int  l, int r, long long  x){
  relax_flag(node, st, en);
  if(st == l && en == r){
    flag[node] += x;
    return ;
  }
  int   mid = (st+en)/2;
  if(r<=mid) add(node<<1, st, mid, l, r ,x);
  else if(l>=mid) add(node<<1^1, mid, en, l, r, x);
  else{
    add(node<<1, st, mid, l, mid, x);
    add(node<<1^1, mid, en, mid, r, x);
  }
  data[node] = get(node<<1, st, mid, st, mid)+
    get(node<<1^1, mid, en , mid, en);
}

set < int  > st ;

int bin ( const int  &x )
{
  auto it = st.lower_bound ( x ) ;
  it -- ;
  return *it ;
}

main ( )
{
  //  fast ;
  int salam ;
  set<int >::iterator it0 ;
  int  type , a , b , x , cur ;
  //cin >> n >> m ;
  scanf ( "%d%d" , &n , &m ) ;
  for ( int  i = 0 ; i <= n ; i ++ )
    st . insert ( i ) , col [ i ] = i + 1 ;
  for ( int i = 0 ; i < m ; i ++ )
    {
      //      prlong long  ( ) ;
      scanf ( "%d" , &type ) ;
      if ( type == 1 )
	{
	  scanf ( "%d%d%d" , &a , &b , &x ) ;
	  //cerr << a << ' ' << b << ' ' << x << endl ;
	  a -- ;
	  if ( st . find ( a ) == st . end ( ) )
	    col [ a ] = col [ bin ( a ) ] , st . insert ( a ) ;
	  if ( st . find ( b ) == st . end ( ) )
	    col [ b ] = col [ bin ( b ) ] , st . insert ( b ) ;
	  it0 = st . lower_bound ( a ) ;
	  cur = a ;
	  while (1 )
	    {
	      it0 ++ ;
	      if ( cur != a )
		st . erase ( cur ) ;
	      add ( 1 , 0 , n , cur , *it0 , abs ( col [ cur ] - x ) ) ;
	      cur = *it0 ;
	      if ( cur == b )
		break ;
	    }
	  col [ a ] = x ;
	}
      else
	scanf ( "%d%d" , &a , &b ) ,
	printf ( "%I64d\n" , get ( 1 , 0 , n , a - 1 , b ) ) ;
    }
}


// In The Name Of God :
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std ;
using namespace __gnu_pbds;
#define X first
#define Y second
//#define int long long
typedef int ll ;
typedef pair < long long , long long > pii ;
typedef pair < pii , long long > pii_i ;
#define ordered_set(TYPE) tree<TYPE, null_type, less<TYPE>, rb_tree_tag, tree_order_statistics_node_update>
//#define "%I64d" "%I64d"
const long long maxn = 1e5 + 20 ;
const long long maxL = 20 ;
//const int inf = 1e12 ;
int n , m , ar [ maxn ] ;
ll data [ 4 * maxn ] ;
ll flag [ 4 * maxn ] ;
set < int > ST ;

void relax_flag ( const ll &st , const ll &en ,const  int id )
{
  data [ id ] += (en-st)*flag[id] ;
  if ( en - st > 1 )
    {
      flag [ id<<1 ] += flag [ id ] ;
      flag [ id<<1^1 ] += flag [ id ] ;
    }
  flag [ id ] = 0 ;
}

int get ( const int &l ,const  int &r , ll st = 0 , ll en = n , int id = 1 )
{
  relax_flag ( st , en , id ) ;
  if ( r <= st || en <= l )
    return 0 ;
  if ( l <= st && en <= r )
    return data [ id ] ;
  int mid = ( st + en ) >> 1 ;
  return get ( l , r , st , mid , id<<1 ) +
    get( l , r , mid , en , id<<1^1 ) ;
}

void add (const  int &l ,const int &r ,const ll &val , ll st = 0 , ll en = n , int id = 1 )
{
  relax_flag ( st , en , id ) ;
  if ( r <= st || en <= l )
    return ;
  if ( l <= st && en <= r )
    {
      flag [ id ] += val ;
      relax_flag ( st , en , id ) ;
      return ;
    }
  int mid = ( st + en ) >> 1 ;
  add ( l , r , val , st , mid , id<<1 ) ;
  add ( l , r , val , mid , en , id<<1^1 ) ;
  data [ id ] = get ( st , mid , st , mid , id<<1 ) +
    get ( mid , en , mid , en , id<<1^1 ) ;
}

main ( )
{
  scanf ( "%d%d" , &n , &m ) ;
  for ( int i = 0 ; i < n ; i ++ )
    ST . insert ( i ) , ar [ i ] = i + 1 ;
  ST . insert ( n ) ;
  int type , l , r , c , cur ;
  set < int > :: iterator it ;
  for ( int i = 0 ; i < m ; i ++ )
    {
      scanf ( "%d" , &type ) ;
      if ( type == 1 )
	{
	  scanf ( "%d%d%d" , &l , &r , &c ) ;
	  l -- ;
	   it = lower_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  if ( ST . find ( l ) == ST . end ( ) )
	    it=(lower_bound(ST.begin(),ST.end(),l)), it-- , ar [ l ] = ar [ *it ] ;
	  else
	    ST . insert ( l ) ;
	  if ( ST . find ( r ) == ST . end ( ) )
	    it=(lower_bound(ST.begin(),ST.end(),r)), it-- , ar [ r ] = ar [ *it ] ;
	  else
	    ST . insert ( r ) ;
	  it = upper_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  cur = l ;
	  while ( 1 )
	    {
	      //	      cerr << "ADD: " << cur << ' ' << *it << ' ' << abs ( c - ar [ cur ] ) << endl ;
	      add ( cur , *it , abs ( c - ar [ cur ] ) ) ;
	      cur = *it ;
	      if ( cur == r )
		break ;
	      it ++ ;
	    }
	  ar [ l ] = c ;
	  it = upper_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  while ( *it < r )
	    {
	      cur = *it ;
	      it ++ ;
	      ST . erase ( cur ) ;
	    }
	}
      else
	scanf("%d%d" , &l , &r ) , printf("%d\n" , get ( l - 1 , r ) ) ;
    }
}


// In The Name Of God :
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std ;
using namespace __gnu_pbds;
#define X first
#define Y second
//#define int long long
typedef int ll ;
typedef pair < long long , long long > pii ;
typedef pair < pii , long long > pii_i ;
#define ordered_set(TYPE) tree<TYPE, null_type, less<TYPE>, rb_tree_tag, tree_order_statistics_node_update>
//#define "%I64d" "%I64d"
const long long maxn = 1e5 + 20 ;
const long long maxL = 20 ;
//const int inf = 1e12 ;
int n , m , ar [ maxn ] ;
ll data [ 4 * maxn ] ;
ll flag [ 4 * maxn ] ;
set < int > ST ;

inline void relax_flag ( const ll &st , const ll &en ,const  int id )
{
  data [ id ] += (en-st)*flag[id] ;
  if ( en - st > 1 )
    {
      flag [ id<<1 ] += flag [ id ] ;
      flag [ id<<1^1 ] += flag [ id ] ;
    }
  flag [ id ] = 0 ;
}

int get ( const int &l ,const  int &r , ll st = 0 , ll en = n , int id = 1 )
{
  relax_flag ( st , en , id ) ;
  if ( r <= st || en <= l )
    return 0 ;
  if ( l <= st && en <= r )
    return data [ id ] ;
  int mid = ( st + en ) >> 1 ;
  return get ( l , r , st , mid , id<<1 ) +
    get( l , r , mid , en , id<<1^1 ) ;
}

void add (const  int &l ,const int &r ,const ll &val , ll st = 0 , ll en = n , int id = 1 )
{
  relax_flag ( st , en , id ) ;
  if ( r <= st || en <= l )
    return ;
  if ( l <= st && en <= r )
    {
      flag [ id ] += val ;
      relax_flag ( st , en , id ) ;
      return ;
    }
  int mid = ( st + en ) >> 1 ;
  add ( l , r , val , st , mid , id<<1 ) ;
  add ( l , r , val , mid , en , id<<1^1 ) ;
  data [ id ] = get ( st , mid , st , mid , id<<1 ) +
    get ( mid , en , mid , en , id<<1^1 ) ;
}

main ( )
{
  scanf ( "%d%d" , &n , &m ) ;
  for ( int i = 0 ; i < n ; i ++ )
    ST . insert ( i ) , ar [ i ] = i + 1 ;
  ST . insert ( n ) ;
  int type , l , r , c , cur ;
  set < int > :: iterator it ;
  for ( int i = 0 ; i < m ; i ++ )
    {
      scanf ( "%d" , &type ) ;
      if ( type == 1 )
	{
	  scanf ( "%d%d%d" , &l , &r , &c ) ;
	  l -- ;
	  if ( ST . find ( l ) == ST . end ( ) )
	    it=(lower_bound(ST.begin(),ST.end(),l)), it-- , ar [ l ] = ar [ *it ] ,
	      ST . insert ( l ) ;
	  if ( ST . find ( r ) == ST . end ( ) )
	    it=(lower_bound(ST.begin(),ST.end(),r)), it-- , ar [ r ] = ar [ *it ] ,
	      ST . insert ( r ) ;
	  it = upper_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  cur = l ;
	  while ( 1 )
	    {
	      //	      cerr << "ADD: " << cur << ' ' << *it << ' ' << abs ( c - ar [ cur ] ) << endl ;
	      add ( cur , *it , abs ( c - ar [ cur ] ) ) ;
	      cur = *it ;
	      if ( cur == r )
		break ;
	      it ++ ;
	    }
	  ar [ l ] = c ;
	  it = upper_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  while ( *it < r )
	    {
	      cur = *it ;
	      it ++ ;
	      ST . erase ( cur ) ;
	    }
	}
      else
	scanf("%d%d" , &l , &r ) , printf("%d\n" , get ( l - 1 , r ) ) ;
    }
}


// In The Name Of God :
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std ;
using namespace __gnu_pbds;
#define X first
#define Y second
//#define int long long
typedef int ll ;
typedef pair < long long , long long > pii ;
typedef pair < pii , long long > pii_i ;
#define ordered_set(TYPE) tree<TYPE, null_type, less<TYPE>, rb_tree_tag, tree_order_statistics_node_update>
//#define "%I64d" "%I64d"
const long long maxn = 1e5 + 20 ;
const long long maxL = 20 ;
//const int inf = 1e12 ;
int n , m , ar [ maxn ] ;
ll data [ 4 * maxn ] ;
ll flag [ 4 * maxn ] ;
set < int > ST ;

void relax_flag ( const ll &st , const ll &en ,const  int id )
{
  data [ id ] += (en-st)*flag[id] ;
  if ( en - st > 1 )
    {
      flag [ id<<1 ] += flag [ id ] ;
      flag [ id<<1^1 ] += flag [ id ] ;
    }
  flag [ id ] = 0 ;
}

int get ( const int &l ,const  int &r , ll st = 0 , ll en = n , int id = 1 )
{
  relax_flag ( st , en , id ) ;
  if ( r <= st || en <= l )
    return 0 ;
  if ( l <= st && en <= r )
    return data [ id ] ;
  int mid = ( st + en ) >> 1 ;
  return get ( l , r , st , mid , id<<1 ) +
    get( l , r , mid , en , id<<1^1 ) ;
}

void add (const  int &l ,const int &r ,const ll &val , ll st = 0 , ll en = n , int id = 1 )
{
  relax_flag ( st , en , id ) ;
  if ( r <= st || en <= l )
    return ;
  if ( l <= st && en <= r )
    {
      flag [ id ] += val ;
      relax_flag ( st , en , id ) ;
      return ;
    }
  int mid = ( st + en ) >> 1 ;
  add ( l , r , val , st , mid , id<<1 ) ;
  add ( l , r , val , mid , en , id<<1^1 ) ;
  data [ id ] = get ( st , mid , st , mid , id<<1 ) +
    get ( mid , en , mid , en , id<<1^1 ) ;
}

main ( )
{
  scanf ( "%d%d" , &n , &m ) ;
  for ( int i = 0 ; i < n ; i ++ )
    ST . insert ( i ) , ar [ i ] = i + 1 ;
  ST . insert ( n ) ;
  int type , l , r , c , cur ;
  set < int > :: iterator it ;
  for ( int i = 0 ; i < m ; i ++ )
    {
      scanf ( "%d" , &type ) ;
      if ( type == 1 )
	{
	  scanf ( "%d%d%d" , &l , &r , &c ) ;
	  l -- ;
	   it = lower_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  if ( ST . find ( l ) == ST . end ( ) )
	    it=(lower_bound(ST.begin(),ST.end(),l)), it-- , ar [ l ] = ar [ *it ] ,
	    ST . insert ( l ) ;
	  if ( ST . find ( r ) == ST . end ( ) )
	    it=(lower_bound(ST.begin(),ST.end(),r)), it-- , ar [ r ] = ar [ *it ] ,
	      ST . insert ( r ) ;
	  it = upper_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  cur = l ;
	  while ( 1 )
	    {
	      //	      cerr << "ADD: " << cur << ' ' << *it << ' ' << abs ( c - ar [ cur ] ) << endl ;
	      add ( cur , *it , abs ( c - ar [ cur ] ) ) ;
	      cur = *it ;
	      if ( cur == r )
		break ;
	      it ++ ;
	    }
	  ar [ l ] = c ;
	  it = upper_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  while ( *it < r )
	    {
	      cur = *it ;
	      it ++ ;
	      ST . erase ( cur ) ;
	    }
	}
      else
	scanf("%d%d" , &l , &r ) , printf("%d\n" , get ( l - 1 , r ) ) ;
    }
}


// In The Name Of God :
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std ;
using namespace __gnu_pbds;
#define X first
#define Y second
//#define int long long
typedef pair < long long , long long > pii ;
typedef pair < pii , long long > pii_i ;
#define ordered_set(TYPE) tree<TYPE, null_type, less<TYPE>, rb_tree_tag, tree_order_statistics_node_update>
//#define "%I64d" "%I64d"
const long long maxn = 1e5 + 20 ;
const long long maxL = 20 ;
//const int inf = 1e12 ;
int n , m , ar [ maxn ] ;
int data [ 4 * maxn ] ;
int flag [ 4 * maxn ] ;
set < int > ST ;

void relax_flag ( int st , int en , int id )
{
  data [ id ] += (en-st)*flag[id] ;
  if ( en - st > 1 )
    {
      flag [ id<<1 ] += flag [ id ] ;
      flag [ id<<1^1 ] += flag [ id ] ;
    }
  flag [ id ] = 0 ;
}

int get ( int l , int r , int st = 0 , int en = n , int id = 1 )
{
  relax_flag ( st , en , id ) ;
  if ( r <= st || en <= l )
    return 0 ;
  if ( l <= st && en <= r )
    return data [ id ] ;
  int mid = ( st + en ) >> 1 ;
  return get ( l , r , st , mid , id<<1 ) +
    get( l , r , mid , en , id<<1^1 ) ;
}

void add ( int l , int r , int val , int st = 0 , int en = n , int id = 1 )
{
  relax_flag ( st , en , id ) ;
  if ( r <= st || en <= l )
    return ;
  if ( l <= st && en <= r )
    {
      flag [ id ] += val ;
      relax_flag ( st , en , id ) ;
      return ;
    }
  int mid = ( st + en ) >> 1 ;
  add ( l , r , val , st , mid , id<<1 ) ;
  add ( l , r , val , mid , en , id<<1^1 ) ;
  data [ id ] = get ( st , mid , st , mid , id<<1 ) +
    get ( mid , en , mid , en , id<<1^1 ) ;
}

void print ( )
{
  cout << "\n**************************************\n" ;
  cout << "set : \n" ;
  for ( set < int > :: iterator it = ST.begin();it!=ST.end();++it)
    cout << *it << ' ' ;
  cout << endl ;
  cout << "ar : \n" ;
  for ( int i = 0 ; i < 5  ; i ++ )
    cout << ar [ i ] << ' ' ;
  cout << "\n**************************************\n" ;
}

main ( )
{
  cin >> n >> m ;
  for ( int i = 0 ; i < n ; i ++ )
    ST . insert ( i ) , ar [ i ] = i + 1 ;
  ST . insert ( n ) ;
  int type , l , r , c ;

  for ( int i = 0 ; i < m ; i ++ )
    {
      cin >> type ;
      if ( type == 1 )
	{
	  //	  cout << "Start \n" ;
	  //print ( ) ;
	  cin >> l >> r >> c ;
	  l -- ;
	  set < int > :: iterator it = lower_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  if ( *it != l )
	    {
	      it -- ;
	      ar [ l ] = ar [ *it ] ;
	    }
	  it = lower_bound ( ST . begin ( ) , ST . end ( ) , r ) ;
	  if ( *it != r )
	    {
	      it -- ;
	      ar [ r ] = ar [ *it ] ;
	      ST . erase ( *it ) ;
	    }
	  ST . insert ( r ) ;
	  ST . insert ( l ) ;
	  it = upper_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  int cur = l ;
	  while ( 1 )
	    {
	      //	      cerr << "ADD: " << cur << ' ' << *it << ' ' << abs ( c - ar [ cur ] ) << endl ;
	      add ( cur , *it , abs ( c - ar [ cur ] ) ) ;
	      cur = *it ;
	      if ( cur == r )
		break ;
	      it ++ ;
	    }
	  ar [ l ] = c ;
	  it = upper_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  while ( *it < r )
	    {
	      ST . erase ( *it ) ;
	      it = upper_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	    }
	}
      else
	cin >> l >> r , cout << get ( l - 1 , r ) << endl ;
    }
}


// In The Name Of God :
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std ;
using namespace __gnu_pbds;
#define X first
#define Y second
//#define int long long
typedef int ll ;
typedef pair < long long , long long > pii ;
typedef pair < pii , long long > pii_i ;
#define ordered_set(TYPE) tree<TYPE, null_type, less<TYPE>, rb_tree_tag, tree_order_statistics_node_update>
//#define "%I64d" "%I64d"
const long long maxn = 1e5 + 20 ;
const long long maxL = 20 ;
//const int inf = 1e12 ;
int n , m , ar [ maxn ] ;
ll data [ 4 * maxn ] ;
ll flag [ 4 * maxn ] ;
set < int > ST ;

void relax_flag ( const ll &st , const ll &en ,const  int id )
{
  data [ id ] += (en-st)*flag[id] ;
  if ( en - st > 1 )
    {
      flag [ id<<1 ] += flag [ id ] ;
      flag [ id<<1^1 ] += flag [ id ] ;
    }
  flag [ id ] = 0 ;
}

int get ( const int &l ,const  int &r , ll st = 0 , ll en = n , int id = 1 )
{
  relax_flag ( st , en , id ) ;
  if ( r <= st || en <= l )
    return 0 ;
  if ( l <= st && en <= r )
    return data [ id ] ;
  int mid = ( st + en ) >> 1 ;
  return get ( l , r , st , mid , id<<1 ) +
    get( l , r , mid , en , id<<1^1 ) ;
}

void add (const  int &l ,const int &r ,const ll &val , ll st = 0 , ll en = n , int id = 1 )
{
  relax_flag ( st , en , id ) ;
  if ( r <= st || en <= l )
    return ;
  if ( l <= st && en <= r )
    {
      flag [ id ] += val ;
      relax_flag ( st , en , id ) ;
      return ;
    }
  int mid = ( st + en ) >> 1 ;
  add ( l , r , val , st , mid , id<<1 ) ;
  add ( l , r , val , mid , en , id<<1^1 ) ;
  data [ id ] = get ( st , mid , st , mid , id<<1 ) +
    get ( mid , en , mid , en , id<<1^1 ) ;
}

main ( )
{
  scanf ( "%d%d" , &n , &m ) ;
  for ( int i = 0 ; i < n ; i ++ )
    ST . insert ( i ) , ar [ i ] = i + 1 ;
  ST . insert ( n ) ;
  int type , l , r , c ;

  for ( int i = 0 ; i < m ; i ++ )
    {
      scanf ( "%d" , &type ) ;
      if ( type == 1 )
	{
	  scanf ( "%d%d%d" , &l , &r , &c ) ;
	  l -- ;
	  set < int > :: iterator it = lower_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  /*if ( ST . find ( l ) == ST . end ( ) )
	    ar [ l ] = ar [ *((lower_bound(ST.begin(),ST.end(),l)--)) ] ;
	  if ( ST . find ( r ) == ST . end ( ) )
	    ar [ r ] = ar [ *((lower_bound(ST.begin(),ST.end(),r)--)) ] ;
	  */
	    if ( *it != l )
	    {
	      it -- ;
	      ar [ l ] = ar [ *it ] ;
	    }
	  it = lower_bound ( ST . begin ( ) , ST . end ( ) , r ) ;
	  if ( *it != r )
	    {
	      it -- ;
	      ar [ r ] = ar [ *it ] ;
	      //	      ST . erase ( *it ) ;
	    }
	  ST . insert ( r ) ;
	  ST . insert ( l ) ;
	  it = upper_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  int cur = l ;
	  while ( 1 )
	    {
	      //	      cerr << "ADD: " << cur << ' ' << *it << ' ' << abs ( c - ar [ cur ] ) << endl ;
	      add ( cur , *it , abs ( c - ar [ cur ] ) ) ;
	      cur = *it ;
	      if ( cur == r )
		break ;
	      it ++ ;
	    }
	  ar [ l ] = c ;
	  it = upper_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  while ( *it < r )
	    {
	      cur = *it ;
	      it ++ ;
	      ST . erase ( cur ) ;
	    }
	}
      else
	scanf("%d%d" , &l , &r ) , printf("%d\n" , get ( l - 1 , r ) ) ;
    }
}


// In The Name Of God :
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace std ;
using namespace __gnu_pbds;
#define X first
#define Y second
//#define int long long
typedef long long ll ;
typedef pair < long long , long long > pii ;
typedef pair < pii , long long > pii_i ;
#define ordered_set(TYPE) tree<TYPE, null_type, less<TYPE>, rb_tree_tag, tree_order_statistics_node_update>
//#define "%I64d" "%I64d"
const long long maxn = 1e5 + 20 ;
const long long maxL = 20 ;
//const int inf = 1e12 ;
int n , m , ar [ maxn ] ;
ll data [ 4 * maxn ] ;
ll flag [ 4 * maxn ] ;
set < int > ST ;

void relax_flag ( int st , int en , int id )
{
  data [ id ] += (en-st)*flag[id] ;
  if ( en - st > 1 )
    {
      flag [ id<<1 ] += flag [ id ] ;
      flag [ id<<1^1 ] += flag [ id ] ;
    }
  flag [ id ] = 0 ;
}

int get ( int l , int r , int st = 0 , int en = n , int id = 1 )
{
  relax_flag ( st , en , id ) ;
  if ( r <= st || en <= l )
    return 0 ;
  if ( l <= st && en <= r )
    return data [ id ] ;
  int mid = ( st + en ) >> 1 ;
  return get ( l , r , st , mid , id<<1 ) +
    get( l , r , mid , en , id<<1^1 ) ;
}

void add ( int l , int r , ll val , int st = 0 , int en = n , int id = 1 )
{
  relax_flag ( st , en , id ) ;
  if ( r <= st || en <= l )
    return ;
  if ( l <= st && en <= r )
    {
      flag [ id ] += val ;
      relax_flag ( st , en , id ) ;
      return ;
    }
  int mid = ( st + en ) >> 1 ;
  add ( l , r , val , st , mid , id<<1 ) ;
  add ( l , r , val , mid , en , id<<1^1 ) ;
  data [ id ] = get ( st , mid , st , mid , id<<1 ) +
    get ( mid , en , mid , en , id<<1^1 ) ;
}

main ( )
{
  scanf ( "%d%d" , &n , &m ) ;
  for ( int i = 0 ; i < n ; i ++ )
    ST . insert ( i ) , ar [ i ] = i + 1 ;
  ST . insert ( n ) ;
  int type , l , r , c ;

  for ( int i = 0 ; i < m ; i ++ )
    {
      scanf ( "%d" , &type ) ;
      if ( type == 1 )
	{
	  //	  cout << "Start \n" ;
	  //print ( ) ;
	  scanf ( "%d%d%d" , &l , &r , &c ) ;
	  l -- ;
	  set < int > :: iterator it = lower_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  if ( *it != l )
	    {
	      it -- ;
	      ar [ l ] = ar [ *it ] ;
	    }
	  it = lower_bound ( ST . begin ( ) , ST . end ( ) , r ) ;
	  if ( *it != r )
	    {
	      it -- ;
	      ar [ r ] = ar [ *it ] ;
	      ST . erase ( *it ) ;
	    }
	  ST . insert ( r ) ;
	  ST . insert ( l ) ;
	  it = upper_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  int cur = l ;
	  while ( 1 )
	    {
	      //	      cerr << "ADD: " << cur << ' ' << *it << ' ' << abs ( c - ar [ cur ] ) << endl ;
	      add ( cur , *it , abs ( c - ar [ cur ] ) ) ;
	      cur = *it ;
	      if ( cur == r )
		break ;
	      it ++ ;
	    }
	  ar [ l ] = c ;
	  it = upper_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	  while ( *it < r )
	    {
	      ST . erase ( *it ) ;
	      it = upper_bound ( ST . begin ( ) , ST . end ( ) , l ) ;
	    }
	}
      else
	scanf("%d%d" , &l , &r ) , printf("%d\n" , get ( l - 1 , r ) ) ;
    }
}