#include <bits/stdc++.h>
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
*/
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
using namespace std;
const ll maxn=1e5+12,inf=1e9,LOG=18,mod=1e9+9,block=350;
ll n,q,a[maxn],b[maxn],add[maxn/block],sum[maxn/block],all[maxn];
ll v[maxn/block][block],pre[maxn/block][block];
void calc1(int i){
	if(all[i]==0)
		return;
	for(int j=0;j<block;j++){
	    a[i*block+j]=all[i];
	    v[i][j]=all[i];
		pre[i][j]=all[i]*(j+1);
	}
	all[i]=0;
}
void calc2(int i){
	for(int j=0;j<block;j++)
		v[i][j]=a[i*block+j];
	sort(v[i],v[i]+block);
	pre[i][0]=v[i][0];
	for(int j=1;j<block;j++)
	    pre[i][j]=pre[i][j-1]+v[i][j];
}

void up(int l, int r,ll x){
	int bl=l/block;
    int br=r/block;
    if(bl==br){
		calc1(bl);
  		for(int i=l;i<=r;i++){
    		b[i]+=abs(a[i]-x);
    		sum[i/block]+=abs(a[i]-x);
    		a[i]=x;
    	}
    	calc2(bl);
    }else{
    	calc1(bl);
    	calc1(br);
    	for(int i=l;i<(bl+1)*block;i++){
    		b[i]+=abs(a[i]-x);
    		sum[i/block]+=abs(a[i]-x);
    		a[i]=x;
    	}
        for(int i=br*block;i<=r;i++){
    		b[i]+=abs(a[i]-x);
    		sum[i/block]+=abs(a[i]-x);
    		a[i]=x;
    	}
        calc2(bl);
    	calc2(br);
    	for(int i=bl+1;i<br;i++){

    		if(all[i]!=0){
    			add[i]+=abs(all[i]-x);
    			sum[i]+=abs(all[i]-x)*block;
    			all[i]=x;
    			continue;
    		}

    		int l=0,r=block-1;
    		while(l<=r){
    			int m=(l+r)/2;
    			if( v[i][m] < x )
    				l=m+1;
    			else
    				r=m-1;
    		}
    		//for(int j=0;j<block;j++)
    		//	cout<<v[i][j]<<" ";
    		//cout<<x<<" "<<l<<endl;
    		//	sum[i]+=abs(x-v[i][j]);
    		if(l==0){
    		    sum[i]+=pre[i][block-1]-x*block;
    		}else{
    			sum[i]+=x*l-pre[i][l-1];
    			sum[i]+=(pre[i][block-1]-pre[i][l-1])-x*(block-l);
    		}
    		all[i]=x;

        }
    }

}
ll get(int l,int r){
	int bl=l/block;
    int br=r/block;
    ll res=0;
    if(bl==br){
		calc1(bl);
  		for(int i=l;i<=r;i++)
    		res+=b[i]+add[i/block];
    	calc2(bl);
    }else{
    	calc1(bl);
    	calc1(br);
    	for(int i=l;i<(bl+1)*block;i++)
    		res+=b[i]+add[i/block];
    	for(int i=br*block;i<=r;i++)
    		res+=b[i]+add[i/block];
    	calc2(bl);
    	calc2(br);
    	for(int i=bl+1;i<br;i++)
    		res+=sum[i];
    }
	return res;
}
int main(){
	#ifdef LOCAL
		freopen ("test.in", "r", stdin);
 	#endif
 	IOS
 	cin>>n>>q;
 	for(int i=1;i<=n;i++){
 		a[i]=i;
  		calc2(i/block);
 	}
 	while(q--){
 		int type,l,r,x;
 		cin>>type;
 		if(type==1){
 			cin>>l>>r>>x;
 			up(l,r,x);
 		}else{
 			cin>>l>>r;
 			cout<<get(l,r)<<endl;
 		}
 	    /*
 		for(int i=1;i<=n;i++)
 			if(all[i/block]==0)
 				cout<<a[i]<<" ";
 	   		else
 	   			cout<<all[i/block]<<" ";cout<<endl;
 		*/
 	}
}


#include <bits/stdc++.h>
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
*/
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
using namespace std;
const ll maxn=1e5+12,inf=1e9,LOG=18,mod=1e9+9,block=300;
ll n,q,a[maxn],b[maxn],add[maxn/block],sum[maxn/block],all[maxn];
ll v[maxn/block][block],pre[maxn/block][block];
void calc1(int i){
	if(all[i]==0)
		return;
	for(int j=0;j<block;j++)
	    a[i*block+j]=all[i];
	all[i]=0;
}
void calc2(int i){
	for(int j=0;j<block;j++)
		v[i][j]=a[i*block+j];
	sort(v[i],v[i]+block);
	pre[i][0]=v[i][0];
	for(int j=1;j<block;j++)
	    pre[i][j]=pre[i][j-1]+v[i][j];
}

void up(int l, int r,ll x){
	int bl=l/block;
    int br=r/block;
    if(bl==br){
		calc1(bl);
  		for(int i=l;i<=r;i++){
    		b[i]+=abs(a[i]-x);
    		sum[i/block]+=abs(a[i]-x);
    		a[i]=x;
    	}
    	calc2(bl);
    }else{
    	calc1(bl);
    	calc1(br);
    	for(int i=l;i<(bl+1)*block;i++){
    		b[i]+=abs(a[i]-x);
    		sum[i/block]+=abs(a[i]-x);
    		a[i]=x;
    	}
        for(int i=br*block;i<=r;i++){
    		b[i]+=abs(a[i]-x);
    		sum[i/block]+=abs(a[i]-x);
    		a[i]=x;
    	}
        calc2(bl);
    	calc2(br);
    	for(int i=bl+1;i<br;i++){

    		if(all[i]!=0){
    			add[i]+=abs(all[i]-x);
    			sum[i]+=abs(all[i]-x)*block;
    			all[i]=x;
    			continue;
    		}

    		int l=0,r=block-1;
    		while(l<=r){
    			int m=(l+r)/2;
    			if( v[i][m] < x )
    				l=m+1;
    			else
    				r=m-1;
    		}
    		//for(int j=0;j<block;j++)
    		//	cout<<v[i][j]<<" ";
    		//cout<<x<<" "<<l<<endl;
    		//	sum[i]+=abs(x-v[i][j]);
    		if(l==0){
    		    sum[i]+=pre[i][block-1]-x*block;
    		}else{
    			sum[i]+=x*l-pre[i][l-1];
    			sum[i]+=(pre[i][block-1]-pre[i][l-1])-x*(block-l);
    		}
    		all[i]=x;

        }
    }

}
ll get(int l,int r){
	int bl=l/block;
    int br=r/block;
    ll res=0;
    if(bl==br){
		calc1(bl);
  		for(int i=l;i<=r;i++)
    		res+=b[i]+add[i/block];
    	calc2(bl);
    }else{
    	calc1(bl);
    	calc1(br);
    	for(int i=l;i<(bl+1)*block;i++)
    		res+=b[i]+add[i/block];
    	for(int i=br*block;i<=r;i++)
    		res+=b[i]+add[i/block];
    	calc2(bl);
    	calc2(br);
    	for(int i=bl+1;i<br;i++)
    		res+=sum[i];
    }
	return res;
}
int main(){
	#ifdef LOCAL
		freopen ("test.in", "r", stdin);
 	#endif
 	scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++){
 		a[i]=i;
  		calc2(i/block);
 	}
 	while(q--){
 		int type,l,r,x;
 		scanf("%d",&type);
        if(type==1){
 			scanf("%d%d%d",&l,&r,&x);
            up(l,r,x);
 		}else{
 			scanf("%d%d",&l,&r);
 			printf("%lld\n",get(l,r));
  		}
 	}
}


#include <bits/stdc++.h>
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
*/
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
using namespace std;
const ll maxn=1e5+12,inf=1e9,LOG=18,mod=1e9+7,block=300;
ll n,q,a[maxn],b[maxn],add[maxn/block],sum[maxn/block],all[maxn];
ll v[maxn/block][block],pre[maxn/block][block];
void calc1(int i){
	if(all[i]==0)
		return;
	for(int j=0;j<block;j++)
	    a[i*block+j]=all[i];
	all[i]=0;
}
void calc2(int i){
	for(int j=0;j<block;j++)
		v[i][j]=a[i*block+j];
	sort(v[i],v[i]+block);
	pre[i][0]=v[i][0];
	for(int j=1;j<block;j++)
	    pre[i][j]=pre[i][j-1]+v[i][j];
}

void up(int l, int r,ll x){
	int bl=l/block;
    int br=r/block;
    if(bl==br){
		calc1(bl);
  		for(int i=l;i<=r;i++){
    		b[i]+=abs(a[i]-x);
    		sum[i/block]+=abs(a[i]-x);
    		a[i]=x;
    	}
    	calc2(bl);
    }else{
    	calc1(bl);
    	calc1(br);
    	for(int i=l;i<(bl+1)*block;i++){
    		b[i]+=abs(a[i]-x);
    		sum[i/block]+=abs(a[i]-x);
    		a[i]=x;
    	}
        for(int i=br*block;i<=r;i++){
    		b[i]+=abs(a[i]-x);
    		sum[i/block]+=abs(a[i]-x);
    		a[i]=x;
    	}
        calc2(bl);
    	calc2(br);
    	for(int i=bl+1;i<br;i++){

    		if(all[i]!=0){
    			add[i]+=abs(all[i]-x);
    			sum[i]+=abs(all[i]-x)*block;
    			all[i]=x;
    			continue;
    		}

    		int l=0,r=block-1;
    		while(l<=r){
    			int m=(l+r)/2;
    			if( v[i][m] <= x )
    				l=m+1;
    			else
    				r=m-1;
    		}
    		//for(int j=0;j<block;j++)
    		//	cout<<v[i][j]<<" ";
    		//cout<<x<<" "<<l<<endl;
    		//	sum[i]+=abs(x-v[i][j]);
    		if(l==0){
    		    sum[i]+=pre[i][block-1]-x*block;
    		}else{
    			sum[i]+=x*l-pre[i][l-1];
    			sum[i]+=(pre[i][block-1]-pre[i][l-1])-x*(block-l);
    		}
    		all[i]=x;

        }
    }

}
ll get(int l,int r){
	int bl=l/block;
    int br=r/block;
    ll res=0;
    if(bl==br){
		calc1(bl);
  		for(int i=l;i<=r;i++)
    		res+=b[i]+add[i/block];
    	calc2(bl);
    }else{
    	calc1(bl);
    	calc1(br);
    	for(int i=l;i<(bl+1)*block;i++)
    		res+=b[i]+add[i/block];
    	for(int i=br*block;i<=r;i++)
    		res+=b[i]+add[i/block];
    	calc2(bl);
    	calc2(br);
    	for(int i=bl+1;i<br;i++)
    		res+=sum[i];
    }
	return res;
}
int main(){
	#ifdef LOCAL
		freopen ("test.in", "r", stdin);
 	#endif
 	scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++){
 		a[i]=i;
  		calc2(i/block);
 	}
 	while(q--){
 		int type,l,r,x;
 		scanf("%d",&type);
        if(type==1){
 			scanf("%d%d%d",&l,&r,&x);
            up(l,r,x);
 		}else{
 			scanf("%d%d",&l,&r);
 			printf("%lld\n",get(l,r));
  		}
 	}
}


#include <bits/stdc++.h>
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
*/
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
using namespace std;
const ll maxn=1e5+12+300,inf=1e9,LOG=18,mod=1e9+7,block=316;
ll n,q,a[maxn],b[maxn],add[maxn/block],sum[maxn/block],all[maxn];
ll v[maxn/block][block],pre[maxn/block][block];
void calc1(int i){
	if(all[i]==0)
		return;
	for(int j=0;j<block;j++)
	   	 a[i*block+j]=all[i];
	all[i]=0;
}
void calc2(int i){
	for(int j=0;j<block;j++)
		v[i][j]=a[i*block+j];
	sort(v[i],v[i]+block);
	pre[i][0]=v[i][0];
	for(int j=1;j<block;j++)
	    pre[i][j]=pre[i][j-1]+v[i][j];
}

void up(int l, int r,ll x){
	int bl=l/block;
    int br=r/block;
    if(bl==br){
		calc1(bl);
  		for(int i=l;i<=r;i++){
    		b[i]+=abs(a[i]-x);
    		sum[bl]+=abs(a[i]-x);
    		a[i]=x;
    	}
    	calc2(bl);
    }else{
    	calc1(bl);
    	calc1(br);
    	for(int i=l;i<(bl+1)*block;i++){
    		b[i]+=abs(a[i]-x);
    		sum[bl]+=abs(a[i]-x);
    		a[i]=x;
    	}
        for(int i=br*block;i<=r;i++){
    		b[i]+=abs(a[i]-x);
    		sum[br]+=abs(a[i]-x);
    		a[i]=x;
    	}
        calc2(bl);
    	calc2(br);
    	for(int i=bl+1;i<br;i++){

    		if(all[i]!=0){
    			add[i]+=abs(all[i]-x);
    			sum[i]+=abs(all[i]-x)*block;
    			all[i]=x;
    			continue;
    		}

    		int l=0,r=block-1;
    		while(l<=r){
    			int m=(l+r)/2;
    			if( v[i][m] <= x )
    				l=m+1;
    			else
    				r=m-1;
    		}

    		if(l==0){
    		    sum[i]+=pre[i][block-1]-x*block;
    		}else{
    			sum[i]+=x*l-pre[i][l-1];
    			sum[i]+=(pre[i][block-1]-pre[i][l-1])-x*(block-l);
    		}
    		all[i]=x;

        }
    }

}
ll get(int l,int r){
	int bl=l/block;
    int br=r/block;
    ll res=0;
    if(bl==br){
		calc1(bl);
  		for(int i=l;i<=r;i++)
    		res+=b[i]+add[bl];
    }else{
    	calc1(bl);
    	calc1(br);
    	for(int i=l;i<(bl+1)*block;i++)
    		res+=b[i]+add[bl];
    	for(int i=br*block;i<=r;i++)
    		res+=b[i]+add[br];
    	for(int i=bl+1;i<br;i++)
    		res+=sum[i];
    }
	return res;
}
int main(){
	#ifdef LOCAL
		freopen ("test.in", "r", stdin);
 	#endif
 	scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++){
 		a[i]=i;
  		calc2(i/block);
 	}
 	while(q--){
 		int type,l,r,x;
 		scanf("%d",&type);
        if(type==1){
 			scanf("%d%d%d",&l,&r,&x);
            up(l,r,x);
 		}else{
 			scanf("%d%d",&l,&r);
 			printf("%lld\n",get(l,r));
  		}
 	}
}


#include <bits/stdc++.h>
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
*/
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
using namespace std;
const ll maxn=1e5+12,inf=1e9,LOG=18,mod=1e9+9,block=350;
ll n,q,a[maxn],b[maxn],add[maxn/block],sum[maxn/block],all[maxn];
ll v[maxn/block][block],pre[maxn/block][block];
void calc1(int i){
	if(all[i]==0)
		return;
	for(int j=0;j<block;j++){
	    a[i*block+j]=all[i];
	    v[i][j]=all[i];
		pre[i][j]=all[i]*(j+1);
	}
	all[i]=0;
}
void calc2(int i){
	for(int j=0;j<block;j++)
		v[i][j]=a[i*block+j];
	sort(v[i],v[i]+block);
	pre[i][0]=v[i][0];
	for(int j=1;j<block;j++)
	    pre[i][j]=pre[i][j-1]+v[i][j];
}

void up(int l, int r,ll x){
	int bl=l/block;
    int br=r/block;
    if(bl==br){
		calc1(bl);
  		for(int i=l;i<=r;i++){
    		b[i]+=abs(a[i]-x);
    		sum[i/block]+=abs(a[i]-x);
    		a[i]=x;
    	}
    	calc2(bl);
    }else{
    	calc1(bl);
    	calc1(br);
    	for(int i=l;i<(bl+1)*block;i++){
    		b[i]+=abs(a[i]-x);
    		sum[i/block]+=abs(a[i]-x);
    		a[i]=x;
    	}
        for(int i=br*block;i<=r;i++){
    		b[i]+=abs(a[i]-x);
    		sum[i/block]+=abs(a[i]-x);
    		a[i]=x;
    	}
        calc2(bl);
    	calc2(br);
    	for(int i=bl+1;i<br;i++){

    		if(all[i]!=0){
    			add[i]+=abs(all[i]-x);
    			sum[i]+=abs(all[i]-x)*block;
    			all[i]=x;
    			continue;
    		}

    		int l=0,r=block-1;
    		while(l<=r){
    			int m=(l+r)/2;
    			if( v[i][m] < x )
    				l=m+1;
    			else
    				r=m-1;
    		}
    		//for(int j=0;j<block;j++)
    		//	cout<<v[i][j]<<" ";
    		//cout<<x<<" "<<l<<endl;
    		//	sum[i]+=abs(x-v[i][j]);
    		if(l==0){
    		    sum[i]+=pre[i][block-1]-x*block;
    		}else{
    			sum[i]+=x*l-pre[i][l-1];
    			sum[i]+=(pre[i][block-1]-pre[i][l-1])-x*(block-l);
    		}
    		all[i]=x;

        }
    }

}
ll get(int l,int r){
	int bl=l/block;
    int br=r/block;
    ll res=0;
    if(bl==br){
		calc1(bl);
  		for(int i=l;i<=r;i++)
    		res+=b[i]+add[i/block];
    	calc2(bl);
    }else{
    	calc1(bl);
    	calc1(br);
    	for(int i=l;i<(bl+1)*block;i++)
    		res+=b[i]+add[i/block];
    	for(int i=br*block;i<=r;i++)
    		res+=b[i]+add[i/block];
    	calc2(bl);
    	calc2(br);
    	for(int i=bl+1;i<br;i++)
    		res+=sum[i];
    }
	return res;
}
int main(){
	#ifdef LOCAL
		freopen ("test.in", "r", stdin);
 	#endif
 	scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++){
 		a[i]=i;
  		calc2(i/block);
 	}
 	while(q--){
 		int type,l,r,x;
 		scanf("%d",&type);
        if(type==1){
 			scanf("%d%d%d",&l,&r,&x);
            up(l,r,x);
 		}else{
 			scanf("%d%d",&l,&r);
 			printf("%lld\n",get(l,r));
  		}
 	}
}


#include <bits/stdc++.h>

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
using namespace std;
const ll maxn=1e5+12+300,inf=1e9,LOG=18,mod=1e9+7,block=316;
ll n,q,a[maxn],b[maxn],add[maxn/block],sum[maxn/block],all[maxn];
void calc1(int i){
	if(all[i]==0)
		return;
	for(int j=0;j<block;j++){
		a[i*block+j]=all[i];
	}
	all[i]=0;
}
void up(int l, int r,ll x){
	int bl=l/block;
    int br=r/block;
    if(bl==br){
		calc1(bl);
  		for(int i=l;i<=r;i++){
    		b[i]+=abs(a[i]-x);
    		sum[bl]+=abs(a[i]-x);
    		a[i]=x;
    	}
    }else{
    	calc1(bl);
    	calc1(br);
    	for(int i=l;i<(bl+1)*block;i++){
    		b[i]+=abs(a[i]-x);
    		sum[bl]+=abs(a[i]-x);
    		a[i]=x;
    	}
        for(int i=br*block;i<=r;i++){
    		b[i]+=abs(a[i]-x);
    		sum[br]+=abs(a[i]-x);
    		a[i]=x;
    	}
    	for(int i=bl+1;i<br;i++){

    		if(all[i]!=0){
    			add[i]+=abs(all[i]-x);
    			sum[i]+=abs(all[i]-x)*block;
    			all[i]=x;
    			continue;
    		}
    		for(int j=0;j<block;j++){
    			b[i*block+j]+=abs(a[i*block+j]-x);
    			sum[i]+=abs(a[i*block+j]-x);
    			a[i*block+j]=x;
    		}
    		all[i]=x;

        }
    }

}
ll get(int l,int r){
	int bl=l/block;
    int br=r/block;
    ll res=0;
    if(bl==br){
		calc1(bl);
  		for(int i=l;i<=r;i++)
    		res+=b[i]+add[bl];
    }else{
    	calc1(bl);
    	calc1(br);
    	for(int i=l;i<(bl+1)*block;i++)
    		res+=b[i]+add[bl];
    	for(int i=br*block;i<=r;i++)
    		res+=b[i]+add[br];
    	for(int i=bl+1;i<br;i++)
    		res+=sum[i];
    }
	return res;
}
int main(){
	#ifdef LOCAL
		freopen ("test.in", "r", stdin);
 	#endif
 	scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++)
 		a[i]=i;
  	while(q--){
 		int type,l,r,x;
 		scanf("%d",&type);
        if(type==1){
 			scanf("%d%d%d",&l,&r,&x);
            up(l,r,x);
 		}else{
 			scanf("%d%d",&l,&r);
 			printf("%lld\n",get(l,r));
  		}
 	}
}


#include <bits/stdc++.h>

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
using namespace std;
const ll maxn=1e5+12+300,inf=1e9,LOG=18,mod=1e9+7,block=316;
ll n,q,a[maxn],b[maxn],add[maxn/block],sum[maxn/block],all[maxn],upd[maxn/block];
ll v[maxn/block][block],pre[maxn/block][block];
void calc1(int i){
	if(all[i]==0)
		return;
	for(int j=0;j<block;j++){
		b[i*block+j]+=abs(upd[i]-a[i*block+j]);
		a[i*block+j]=all[i];
	}
	all[i]=0;
}
void calc2(int i){
	for(int j=0;j<block;j++)
		v[i][j]=a[i*block+j];
	sort(v[i],v[i]+block);
	pre[i][0]=v[i][0];
	for(int j=1;j<block;j++)
	    pre[i][j]=pre[i][j-1]+v[i][j];
}

void up(int l, int r,ll x){
	int bl=l/block;
    int br=r/block;
    if(bl==br){
		calc1(bl);
  		for(int i=l;i<=r;i++){
    		b[i]+=abs(a[i]-x);
    		sum[bl]+=abs(a[i]-x);
    		a[i]=x;
    	}
    	calc2(bl);
    }else{
    	calc1(bl);
    	calc1(br);
    	for(int i=l;i<(bl+1)*block;i++){
    		b[i]+=abs(a[i]-x);
    		sum[bl]+=abs(a[i]-x);
    		a[i]=x;
    	}
        for(int i=br*block;i<=r;i++){
    		b[i]+=abs(a[i]-x);
    		sum[br]+=abs(a[i]-x);
    		a[i]=x;
    	}
        calc2(bl);
    	calc2(br);
    	for(int i=bl+1;i<br;i++){

    		if(all[i]!=0){
    			add[i]+=abs(all[i]-x);
    			sum[i]+=abs(all[i]-x)*block;
    			all[i]=x;
    			continue;
    		}

    		int l=0,r=block-1;
    		while(l<=r){
    			int m=(l+r)/2;
    			if( v[i][m] <= x )
    				l=m+1;
    			else
    				r=m-1;
    		}

    		if(l==0){
    		    sum[i]+=pre[i][block-1]-x*block;
    		}else{
    			sum[i]+=x*l-pre[i][l-1];
    			sum[i]+=(pre[i][block-1]-pre[i][l-1])-x*(block-l);
    		}
    		upd[i]=x;
    		all[i]=x;

        }
    }

}
ll get(int l,int r){
	int bl=l/block;
    int br=r/block;
    ll res=0;
    if(bl==br){
		calc1(bl);
  		for(int i=l;i<=r;i++)
    		res+=b[i]+add[bl];
    }else{
    	calc1(bl);
    	calc1(br);
    	for(int i=l;i<(bl+1)*block;i++)
    		res+=b[i]+add[bl];
    	for(int i=br*block;i<=r;i++)
    		res+=b[i]+add[br];
    	for(int i=bl+1;i<br;i++)
    		res+=sum[i];
    }
	return res;
}
int main(){
	#ifdef LOCAL
		freopen ("test.in", "r", stdin);
 	#endif
 	scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++){
 		a[i]=i;
  		calc2(i/block);
 	}
 	while(q--){
 		int type,l,r,x;
 		scanf("%d",&type);
        if(type==1){
 			scanf("%d%d%d",&l,&r,&x);
            up(l,r,x);
 		}else{
 			scanf("%d%d",&l,&r);
 			printf("%lld\n",get(l,r));
  		}
 	}
}


#include<bits/stdc++.h>

using namespace std;

const long long MAXN = 1e5 + 7;

struct node
{
	int sum, col, lazy;

	node()
	{
		sum = 0;
		col = -2;
		lazy = 0;
	}

	node(int _col, int _sum)
	{
		col = _col;
		sum = _sum;
		lazy = 0;
	}
};

node temp, broken;

node merge(node l, node r)
{
	if(l.col == -2)
		return r;
	if(r.col == -2)
		return l;

	temp.lazy = 0;
	temp.col = (l.col == r.col) ? l.col : -1;
	temp.sum = l.sum + r.sum;

	return  temp;
}

struct  segment_tree
{
	node tr[4*MAXN];

	void push(int l, int r, int idx)
	{
		tr[idx].sum += tr[idx].lazy * (r - l + 1);

		if(l != r)
		{
			tr[2 * idx + 1].lazy += tr[idx].lazy;
			tr[2 * idx + 2].lazy += tr[idx].lazy;

			if(tr[idx].col != -1)
			{
				tr[2 * idx + 1].col = tr[idx].col;
				tr[2 * idx + 2].col = tr[idx].col;
			}
		}

		tr[idx].lazy = 0;
	}

	void init(int l, int r, int idx)
	{
		if(l == r)
		{
			tr[idx] = node(l, 0);
			return;
		}

		int mid = (l+r) >> 1;

		init(l, mid, 2 * idx + 1);
		init(mid + 1, r, 2 * idx + 2);

		tr[idx] = merge(tr[2 * idx + 1], tr[2 * idx + 2]);
	}

	void update(int qL, int qR, int nw_col, int l, int r, int idx)
	{
		push(l, r, idx);

		if(qL <= l && r <= qR && tr[idx].col != -1)
		{
			tr[idx].lazy += abs(nw_col - tr[idx].col);
			tr[idx].col = nw_col;
			push(l, r, idx);

			return;
		}

		if(qL > r && l > qR)
			return;

		int mid = (l + r) >> 1;

		update(qL, qR, nw_col, l, mid, 2 * idx + 1);
		update(qL, qR, nw_col, mid+1, r, 2 * idx + 2);
	}

	node query(int qL, int qR, int l, int r, int idx)
	{
		push(l, r, idx);

		if(qL <= l && r <= qR)
			return tr[idx];

		if(qL > r || l > qR)
			return broken;

		int mid = (l+r) >> 1;

		return merge(query(qL, qR, l, mid, 2 * idx +1), query(qL, qR, mid + 1, r, 2 * idx + 2));
	}
};

segment_tree st;

int main ()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	long long n, m;

	cin >> n >> m;

	st.init(1, n , 0);

	for(int i = 0; i < m; i++)
	{
		int type;

		cin >> type;

		if(type == 1)
		{
			int l, r, x;

			cin >> l >> r >> x;

			st.update(l, r, x, 1, n, 0);
		}
		else
		{
			int l, r;

			cin >> l >> r;

			cout << st.query(l, r, 1, n, 0).sum << "\n";
		}
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const long long MAXN = 1e5 + 7;

struct node
{
	int sum, col, lazy;

	node()
	{
		sum = 0;
		col = -2;
		lazy = 0;
	}

	node(int _col, int _sum)
	{
		col = _col;
		sum = _sum;
		lazy = 0;
	}
};

node temp, broken;

node merge(node l, node r)
{
	if(l.col == -2)
		return r;
	if(r.col == -2)
		return l;

	temp.lazy = 0;
	temp.col = (l.col == r.col) ? l.col : -1;
	temp.sum = l.sum + r.sum;

	return  temp;
}

struct  segment_tree
{
	node tr[4*MAXN];

	void push(int l, int r, int idx)
	{
		tr[idx].sum += tr[idx].lazy * (r - l + 1);

		if(l != r)
		{
			tr[2 * idx + 1].lazy += tr[idx].lazy;
			tr[2 * idx + 2].lazy += tr[idx].lazy;

			if(tr[idx].col != -1)
			{
				tr[2 * idx + 1].col = tr[idx].col;
				tr[2 * idx + 2].col = tr[idx].col;
			}
		}

		tr[idx].lazy = 0;
	}

	void init(int l, int r, int idx)
	{
		if(l == r)
		{
			tr[idx] = node(l, 0);
			return;
		}

		int mid = (l+r) >> 1;

		init(l, mid, 2 * idx + 1);
		init(mid + 1, r, 2 * idx + 2);

		tr[idx] = merge(tr[2 * idx + 1], tr[2 * idx + 2]);
	}

	void update(int qL, int qR, int nw_col, int l, int r, int idx)
	{
		push(l, r, idx);

		//cout << l << " " << r << endl;

		if(qL <= l && r <= qR && tr[idx].col != -1)
		{
			tr[idx].lazy += abs(nw_col - tr[idx].col);
			tr[idx].col = nw_col;
			push(l, r, idx);

			return;
		}

		if(qL > r || l > qR)
			return;

		int mid = (l + r) >> 1;

		update(qL, qR, nw_col, l, mid, 2 * idx + 1);
		update(qL, qR, nw_col, mid+1, r, 2 * idx + 2);

		tr[idx] = merge(tr[2 * idx + 1], tr[2*idx + 2]);
	}

	node query(int qL, int qR, int l, int r, int idx)
	{
		push(l, r, idx);

		//cout << tr[idx].sum << " " << idx << endl;
		//cout << qL << " " << qR << " " << l << " " << r << endl;

		if(qL <= l && r <= qR)
			return tr[idx];

		if(qL > r || l > qR)
			return broken;

		int mid = (l+r) >> 1;

		return merge(query(qL, qR, l, mid, 2 * idx +1), query(qL, qR, mid + 1, r, 2 * idx + 2));
	}
};

segment_tree st;

int main ()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	long long n, m;

	cin >> n >> m;

	st.init(1, n , 0);

	for(int i = 0; i < m; i++)
	{
		int type;

		cin >> type;

		if(type == 1)
		{
			int l, r, x;

			cin >> l >> r >> x;

			st.update(l, r, x, 1, n, 0);
		}
		else
		{
			int l, r;

			cin >> l >> r;

			cout << st.query(l, r, 1, n, 0).sum << "\n";
		}
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const long long MAXN = 1e5 + 7;

struct node
{
	long long sum, col, lazy;

	node()
	{
		sum = 0;
		col = -2;
		lazy = 0;
	}

	node(long long _col, long long _sum)
	{
		col = _col;
		sum = _sum;
		lazy = 0;
	}
};

node temp, broken;

node merge(node l, node r)
{
	if(l.col == -2)
		return r;
	if(r.col == -2)
		return l;

	temp.lazy = 0;
	temp.col = (l.col == r.col) ? l.col : -1;
	temp.sum = l.sum + r.sum;

	return  temp;
}

struct  segment_tree
{
	node tr[4*MAXN];

	void push(long long l, long long r, long long idx)
	{
		tr[idx].sum += tr[idx].lazy * (r - l + 1);

		if(l != r)
		{
			tr[2 * idx + 1].lazy += tr[idx].lazy;
			tr[2 * idx + 2].lazy += tr[idx].lazy;

			if(tr[idx].col != -1)
			{
				tr[2 * idx + 1].col = tr[idx].col;
				tr[2 * idx + 2].col = tr[idx].col;
			}
		}

		tr[idx].lazy = 0;
	}

	void init(long long l, long long r, long long idx)
	{
		if(l == r)
		{
			tr[idx] = node(l, 0);
			return;
		}

		long long mid = (l+r) >> 1;

		init(l, mid, 2 * idx + 1);
		init(mid + 1, r, 2 * idx + 2);

		tr[idx] = merge(tr[2 * idx + 1], tr[2 * idx + 2]);
	}

	void update(long long qL, long long qR, long long nw_col, long long l, long long r, long long idx)
	{
		push(l, r, idx);

		//cout << l << " " << r << endl;

		if(qL <= l && r <= qR && tr[idx].col != -1)
		{
			tr[idx].lazy += abs(nw_col - tr[idx].col);
			tr[idx].col = nw_col;
			push(l, r, idx);

			return;
		}

		if(qL > r || l > qR)
			return;

		long long mid = (l + r) >> 1;

		update(qL, qR, nw_col, l, mid, 2 * idx + 1);
		update(qL, qR, nw_col, mid+1, r, 2 * idx + 2);

		tr[idx] = merge(tr[2 * idx + 1], tr[2*idx + 2]);
	}

	node query(long long qL, long long qR, long long l, long long r, long long idx)
	{
		push(l, r, idx);

		//cout << tr[idx].sum << " " << idx << endl;
		//cout << qL << " " << qR << " " << l << " " << r << endl;

		if(qL <= l && r <= qR)
			return tr[idx];

		if(qL > r || l > qR)
			return broken;

		long long mid = (l+r) >> 1;

		return merge(query(qL, qR, l, mid, 2 * idx +1), query(qL, qR, mid + 1, r, 2 * idx + 2));
	}
};

segment_tree st;

int main ()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	long long n, m;

	cin >> n >> m;

	st.init(1, n , 0);

	for(long long i = 0; i < m; i++)
	{
		long long type;

		cin >> type;

		if(type == 1)
		{
			long long l, r, x;

			cin >> l >> r >> x;

			st.update(l, r, x, 1, n, 0);
		}
		else
		{
			long long l, r;

			cin >> l >> r;

			cout << st.query(l, r, 1, n, 0).sum << "\n";
		}
	}

	return 0;
}


#include <bits/stdc++.h>
#define mp std::make_pair

typedef long long ll;
typedef std::set<std::pair<ll, ll> > sp;
typedef std::pair<ll, ll> px;

struct elem
{
	ll co,cl;
}elem[100100];

struct sq
{
	ll tc,fc,cc,ac;
	sp s;
}bl[350];

ll Z;

class sqrtdec
{
	public: void update(ll l, ll r, ll x);
			ll query(ll l, ll r);
};

void sqrtdec::update(ll l, ll r, ll x)
{
	ll c_l = l/Z;
	ll c_r = r/Z;
	if(c_l == c_r)
	{
		if(bl[c_l].fc)
		{
			for(ll i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(ll i=l;i<=r;i++)
		{
			ll t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_l].tc += t;
			for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					ll u = it->first;
					ll v = it->second - 1;
					px e = *it;
					it++;
					bl[c_l].s.erase(e);
					if(v)
					bl[c_l].s.insert(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		bool flag = 0;
		for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
		{
			if(it->first == x)
			{
				ll u = it->first;
				ll v = it->second + (r-l+1);
				px e = *it;
				it++;
				bl[c_l].s.erase(e);
				if(v)
				bl[c_l].s.insert(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_l].s.insert(mp(x, r-l+1));
	}
	else
	{
		//LEFT HEAD
		if(bl[c_l].fc)
		{
			for(ll i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(ll i=l,j=(c_l+1)*Z;i<j;i++)
		{
			ll t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_l].tc += t;
			for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					ll u = it->first;
					ll v = it->second - 1;
					px e = *it;
					it++;
					bl[c_l].s.erase(e);
					if(v)
					bl[c_l].s.insert(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		bool flag = 0;
		for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
		{
			if(it->first == x)
			{
				ll u = it->first;
				ll v = it->second + (c_l+1)*Z-l;
				px e = *it;
				it++;
				bl[c_l].s.erase(e);
				if(v)
				bl[c_l].s.insert(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_l].s.insert(mp(x, (c_l+1)*Z-l));
		//RIGHT TAIL
		if(bl[c_r].fc)
		{
			for(ll i=c_r*Z,j=(c_r+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_r].fc - elem[i].co);
				elem[i].cl += (t + bl[c_r].ac);
				elem[i].co = bl[c_r].cc;
			}
			bl[c_r].fc = bl[c_r].cc = bl[c_r].ac = 0;
		}
		for(ll i=c_r*Z;i<=r;i++)
		{
			ll t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_r].tc += t;
			for(sp::iterator it=bl[c_r].s.begin();it != bl[c_r].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					ll u = it->first;
					ll v = it->second - 1;
					px e = *it;
					it++;
					bl[c_r].s.erase(e);
					if(v)
					bl[c_r].s.insert(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		flag = 0;
		for(sp::iterator it=bl[c_r].s.begin();it != bl[c_r].s.end();it++)
		{
			if(it->first == x)
			{
				ll u = it->first;
				ll v = it->second + r-(c_r*Z)+1;
				px e = *it;
				it++;
				bl[c_r].s.erase(e);
				if(v)
				bl[c_r].s.insert(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_r].s.insert(mp(x, r-(c_r*Z)+1));
		//MIDDLE
		for(ll i=c_l+1;i<c_r;i++)
		{
			for(sp::iterator it=bl[i].s.begin();it != bl[i].s.end(); )
			{
				ll u = it->first;
				ll v = it->second;
				bl[i].tc += v*fabs(x - u);
				px e = *it;
				it++;
				bl[i].s.erase(e);
			}
			bl[i].s.insert(mp(x, Z));
			if(bl[i].fc)
			{
				bl[i].ac += fabs(bl[i].cc - x);
				bl[i].cc = x;
			}
			else bl[i].fc = bl[i].cc = x;
		}
	}
}

ll sqrtdec::query(ll l, ll r)
{
	ll c_l = l/Z;
	ll c_r = r/Z;
	ll sum = 0;
	if(c_l == c_r)
	{
		if(bl[c_l].fc)
		{
			for(ll i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(ll i=l;i<=r;i++)
		sum += elem[i].cl;
	}
	else
	{
		//LEFT HEAD
		if(bl[c_l].fc)
		{
			for(ll i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(ll i=l,j=(c_l+1)*Z;i<j;i++)
		sum += elem[i].cl;
		//MIDDLE
		for(ll i=c_l+1;i<c_r;i++)
		sum += bl[i].tc;
		//RIGHT TAIL
		if(bl[c_r].fc)
		{
			for(ll i=c_r*Z,j=(c_r+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_r].fc - elem[i].co);
				elem[i].cl += (t + bl[c_r].ac);
				elem[i].co = bl[c_r].cc;
			}
			bl[c_r].fc = bl[c_r].cc = bl[c_r].ac = 0;
		}
		for(ll i=c_r*Z;i<=r;i++)
		sum += elem[i].cl;
	}
	return sum;
}

int main(void)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	ll n,m;
	std::cin>>n>>m;
	Z = floor(sqrt(n));
	for(ll i=1;i<=n;i++)
	{
		elem[i].co = i;
		elem[i].cl = 0;
		bl[i/Z].s.insert(mp(i, 1));
	}
	for(ll i=0;i<=Z;i++)
	bl[i].tc = bl[i].cc = bl[i].fc = bl[i].ac = 0;
	sqrtdec T;
	while(m--)
	{
		ll q;
		std::cin>>q;
		if(--q)
		{
			ll l,r;
			std::cin>>l>>r;
			std::cout<<T.query(l, r)<<"\n";
		}
		else
		{
			ll l,r,x;
			std::cin>>l>>r>>x;
			T.update(l, r, x);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define mp std::make_pair

typedef std::set<std::pair<int, int> > sp;
typedef std::pair<int, int> px;

struct elem
{
	int co,cl;
}elem[100100];

struct sq
{
	int tc,fc,cc,ac;
	sp s;
}bl[350];

int Z;

class sqrtdec
{
	public: void update(int l, int r, int x);
			int query(int l, int r);
};

void sqrtdec::update(int l, int r, int x)
{
	int c_l = l/Z;
	int c_r = r/Z;
	if(c_l == c_r)
	{
		if(bl[c_l].fc)
		{
			for(int i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(int i=l;i<=r;i++)
		{
			int t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_l].tc += t;
			for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					int u = it->first;
					int v = it->second - 1;
					px e = *it;
					it++;
					bl[c_l].s.erase(e);
					if(v)
					bl[c_l].s.insert(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		bool flag = 0;
		for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
		{
			if(it->first == x)
			{
				int u = it->first;
				int v = it->second + (r-l+1);
				px e = *it;
				it++;
				bl[c_l].s.erase(e);
				if(v)
				bl[c_l].s.insert(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_l].s.insert(mp(x, r-l+1));
	}
	else
	{
		//LEFT HEAD
		if(bl[c_l].fc)
		{
			for(int i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(int i=l,j=(c_l+1)*Z;i<j;i++)
		{
			int t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_l].tc += t;
			for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					int u = it->first;
					int v = it->second - 1;
					px e = *it;
					it++;
					bl[c_l].s.erase(e);
					if(v)
					bl[c_l].s.insert(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		bool flag = 0;
		for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
		{
			if(it->first == x)
			{
				int u = it->first;
				int v = it->second + (c_l+1)*Z-l;
				px e = *it;
				it++;
				bl[c_l].s.erase(e);
				if(v)
				bl[c_l].s.insert(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_l].s.insert(mp(x, (c_l+1)*Z-l));
		//RIGHT TAIL
		if(bl[c_r].fc)
		{
			for(int i=c_r*Z,j=(c_r+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_r].fc - elem[i].co);
				elem[i].cl += (t + bl[c_r].ac);
				elem[i].co = bl[c_r].cc;
			}
			bl[c_r].fc = bl[c_r].cc = bl[c_r].ac = 0;
		}
		for(int i=c_r*Z;i<=r;i++)
		{
			int t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_r].tc += t;
			for(sp::iterator it=bl[c_r].s.begin();it != bl[c_r].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					int u = it->first;
					int v = it->second - 1;
					px e = *it;
					it++;
					bl[c_r].s.erase(e);
					if(v)
					bl[c_r].s.insert(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		flag = 0;
		for(sp::iterator it=bl[c_r].s.begin();it != bl[c_r].s.end();it++)
		{
			if(it->first == x)
			{
				int u = it->first;
				int v = it->second + r-(c_r*Z)+1;
				px e = *it;
				it++;
				bl[c_r].s.erase(e);
				if(v)
				bl[c_r].s.insert(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_r].s.insert(mp(x, r-(c_r*Z)+1));
		//MIDDLE
		for(int i=c_l+1;i<c_r;i++)
		{
			for(sp::iterator it=bl[i].s.begin();it != bl[i].s.end(); )
			{
				int u = it->first;
				int v = it->second;
				bl[i].tc += v*fabs(x - u);
				px e = *it;
				it++;
				bl[i].s.erase(e);
			}
			bl[i].s.insert(mp(x, Z));
			if(bl[i].fc)
			{
				bl[i].ac += fabs(bl[i].cc - x);
				bl[i].cc = x;
			}
			else bl[i].fc = bl[i].cc = x;
		}
	}
}

int sqrtdec::query(int l, int r)
{
	int c_l = l/Z;
	int c_r = r/Z;
	int sum = 0;
	if(c_l == c_r)
	{
		if(bl[c_l].fc)
		{
			for(int i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(int i=l;i<=r;i++)
		sum += elem[i].cl;
	}
	else
	{
		//LEFT HEAD
		if(bl[c_l].fc)
		{
			for(int i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(int i=l,j=(c_l+1)*Z;i<j;i++)
		sum += elem[i].cl;
		//MIDDLE
		for(int i=c_l+1;i<c_r;i++)
		sum += bl[i].tc;
		//RIGHT TAIL
		if(bl[c_r].fc)
		{
			for(int i=c_r*Z,j=(c_r+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_r].fc - elem[i].co);
				elem[i].cl += (t + bl[c_r].ac);
				elem[i].co = bl[c_r].cc;
			}
			bl[c_r].fc = bl[c_r].cc = bl[c_r].ac = 0;
		}
		for(int i=c_r*Z;i<=r;i++)
		sum += elem[i].cl;
	}
	return sum;
}

int main(void)
{
	int n,m;
	std::cin>>n>>m;
	Z = floor(sqrt(n));
	for(int i=1;i<=n;i++)
	{
		elem[i].co = i;
		elem[i].cl = 0;
		bl[i/Z].s.insert(mp(i, 1));
	}
	for(int i=0;i<=Z;i++)
	bl[i].tc = bl[i].cc = bl[i].fc = bl[i].ac = 0;
	sqrtdec T;
	while(m--)
	{
		int q;
		std::cin>>q;
		if(--q)
		{
			int l,r;
			std::cin>>l>>r;
			std::cout<<T.query(l, r)<<"\n";
		}
		else
		{
			int l,r,x;
			std::cin>>l>>r>>x;
			T.update(l, r, x);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define mp std::make_pair

typedef std::set<std::pair<int, int> > sp;

struct elem
{
	int co,cl;
}elem[100100];

struct sq
{
	int tc,fc,cc,ac;
	sp s;
}bl[350];

int Z;

class sqrtdec
{
	public: void update(int l, int r, int x);
			int query(int l, int r);
};

void sqrtdec::update(int l, int r, int x)
{
	int c_l = l/Z;
	int c_r = r/Z;
	if(c_l == c_r)
	{
		if(bl[c_l].fc)
		{
			for(int i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(int i=l;i<=r;i++)
		{
			int t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_l].tc += t;
			for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					int u = it->first;
					int v = it->second - 1;
					bl[c_l].s.erase(it);
					if(v)
					bl[c_l].s.insert(mp(u, v));
				}
			}
			elem[i].co = x;
		}
		bool flag = 0;
		for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
		{
			if(it->first == x)
			{
				int u = it->first;
				int v = it->second + (r-l+1);
				bl[c_l].s.erase(it);
				if(v)
				bl[c_l].s.insert(mp(u, v));
				flag = 1;
			}
		}
		if(!flag)
		bl[c_l].s.insert(mp(x, r-l+1));
	}
	else
	{
		//LEFT HEAD
		if(bl[c_l].fc)
		{
			for(int i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(int i=l,j=(c_l+1)*Z;i<j;i++)
		{
			int t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_l].tc += t;
			for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					int u = it->first;
					int v = it->second - 1;
					bl[c_l].s.erase(it);
					if(v)
					bl[c_l].s.insert(mp(u, v));
				}
			}
			elem[i].co = x;
		}
		bool flag = 0;
		for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
		{
			if(it->first == x)
			{
				int u = it->first;
				int v = it->second + (c_l+1)*Z-l;
				bl[c_l].s.erase(it);
				if(v)
				bl[c_l].s.insert(mp(u, v));
				flag = 1;
			}
		}
		if(!flag)
		bl[c_l].s.insert(mp(x, (c_l+1)*Z-l));
		//RIGHT TAIL
		if(bl[c_r].fc)
		{
			for(int i=c_r*Z,j=(c_r+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_r].fc - elem[i].co);
				elem[i].cl += (t + bl[c_r].ac);
				elem[i].co = bl[c_r].cc;
			}
			bl[c_r].fc = bl[c_r].cc = bl[c_r].ac = 0;
		}
		for(int i=c_r*Z;i<=r;i++)
		{
			int t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_r].tc += t;
			for(sp::iterator it=bl[c_r].s.begin();it != bl[c_r].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					int u = it->first;
					int v = it->second - 1;
					bl[c_r].s.erase(it);
					if(v)
					bl[c_r].s.insert(mp(u, v));
				}
			}
			elem[i].co = x;
		}
		flag = 0;
		for(sp::iterator it=bl[c_r].s.begin();it != bl[c_r].s.end();it++)
		{
			if(it->first == x)
			{
				int u = it->first;
				int v = it->second + r-(c_r*Z)+1;
				bl[c_r].s.erase(it);
				if(v)
				bl[c_r].s.insert(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_r].s.insert(mp(x, r-(c_r*Z)+1));
		//MIDDLE
		for(int i=c_l+1;i<c_r;i++)
		{
			for(sp::iterator it=bl[i].s.begin();it != bl[i].s.end();it++)
			{
				int u = it->first;
				int v = it->second;
				bl[i].tc += v*fabs(x - u);
				bl[i].s.erase(it);
			}
			bl[i].s.insert(mp(x, Z));
			if(bl[i].fc)
			{
				bl[i].ac += fabs(bl[i].cc - x);
				bl[i].cc = x;
			}
			else bl[i].fc = bl[i].cc = x;
		}
	}
}

int sqrtdec::query(int l, int r)
{
	int c_l = l/Z;
	int c_r = r/Z;
	int sum = 0;
	if(c_l == c_r)
	{
		if(bl[c_l].fc)
		{
			for(int i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(int i=l;i<=r;i++)
		sum += elem[i].cl;
	}
	else
	{
		//LEFT HEAD
		if(bl[c_l].fc)
		{
			for(int i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(int i=l,j=(c_l+1)*Z;i<j;i++)
		sum += elem[i].cl;
		//MIDDLE
		for(int i=c_l+1;i<c_r;i++)
		sum += bl[i].tc;
		//RIGHT TAIL
		if(bl[c_r].fc)
		{
			for(int i=c_r*Z,j=(c_r+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_r].fc - elem[i].co);
				elem[i].cl += (t + bl[c_r].ac);
				elem[i].co = bl[c_r].cc;
			}
			bl[c_r].fc = bl[c_r].cc = bl[c_r].ac = 0;
		}
		for(int i=c_r*Z;i<=r;i++)
		sum += elem[i].cl;
	}
	return sum;
}

int main(void)
{
	int n,m;
	std::cin>>n>>m;
	Z = floor(sqrt(n));
	for(int i=1;i<=n;i++)
	{
		elem[i].co = i;
		elem[i].cl = 0;
		bl[i/Z].s.insert(mp(i, 1));
	}
	for(int i=0;i<=Z;i++)
	bl[i].tc = bl[i].cc = bl[i].fc = bl[i].ac = 0;
	sqrtdec T;
	while(m--)
	{
		int q;
		std::cin>>q;
		if(--q)
		{
			int l,r;
			std::cin>>l>>r;
			std::cout<<T.query(l, r)<<"\n";
		}
		else
		{
			int l,r,x;
			std::cin>>l>>r>>x;
			T.update(l, r, x);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define mp std::make_pair

typedef std::set<std::pair<int, int> > sp;
typedef std::pair<int, int> px;

struct elem
{
	int co,cl;
}elem[100100];

struct sq
{
	int tc,fc,cc,ac;
	sp s;
}bl[350];

int Z;

class sqrtdec
{
	public: void update(int l, int r, int x);
			int query(int l, int r);
};

void sqrtdec::update(int l, int r, int x)
{
	int c_l = l/Z;
	int c_r = r/Z;
	if(c_l == c_r)
	{
		if(bl[c_l].fc)
		{
			for(int i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(int i=l;i<=r;i++)
		{
			int t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_l].tc += t;
			for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					int u = it->first;
					int v = it->second - 1;
					bl[c_l].s.erase(it);
					if(v)
					bl[c_l].s.insert(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		bool flag = 0;
		for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
		{
			if(it->first == x)
			{
				int u = it->first;
				int v = it->second + (r-l+1);

				bl[c_l].s.erase(it);
				if(v)
				bl[c_l].s.insert(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_l].s.insert(mp(x, r-l+1));
	}
	else
	{
		//LEFT HEAD
		if(bl[c_l].fc)
		{
			for(int i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(int i=l,j=(c_l+1)*Z;i<j;i++)
		{
			int t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_l].tc += t;
			for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					int u = it->first;
					int v = it->second - 1;
					bl[c_l].s.erase(it);
					if(v)
					bl[c_l].s.insert(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		bool flag = 0;
		for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
		{
			if(it->first == x)
			{
				int u = it->first;
				int v = it->second + (c_l+1)*Z-l;
				bl[c_l].s.erase(it);
				if(v)
				bl[c_l].s.insert(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_l].s.insert(mp(x, (c_l+1)*Z-l));
		//RIGHT TAIL
		if(bl[c_r].fc)
		{
			for(int i=c_r*Z,j=(c_r+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_r].fc - elem[i].co);
				elem[i].cl += (t + bl[c_r].ac);
				elem[i].co = bl[c_r].cc;
			}
			bl[c_r].fc = bl[c_r].cc = bl[c_r].ac = 0;
		}
		for(int i=c_r*Z;i<=r;i++)
		{
			int t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_r].tc += t;
			for(sp::iterator it=bl[c_r].s.begin();it != bl[c_r].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					int u = it->first;
					int v = it->second - 1;
					bl[c_r].s.erase(it);
					if(v)
					bl[c_r].s.insert(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		flag = 0;
		for(sp::iterator it=bl[c_r].s.begin();it != bl[c_r].s.end();it++)
		{
			if(it->first == x)
			{
				int u = it->first;
				int v = it->second + r-(c_r*Z)+1;
				bl[c_r].s.erase(it);
				if(v)
				bl[c_r].s.insert(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_r].s.insert(mp(x, r-(c_r*Z)+1));
		//MIDDLE
		for(int i=c_l+1;i<c_r;i++)
		{
			for(sp::iterator it=bl[i].s.begin();it != bl[i].s.end();it++)
			{
				int u = it->first;
				int v = it->second;
				bl[i].tc += v*fabs(x - u);
				px e = *it;
				bl[i].s.erase(e);
			}
			bl[i].s.insert(mp(x, Z));
			if(bl[i].fc)
			{
				bl[i].ac += fabs(bl[i].cc - x);
				bl[i].cc = x;
			}
			else bl[i].fc = bl[i].cc = x;
		}
	}
}

int sqrtdec::query(int l, int r)
{
	int c_l = l/Z;
	int c_r = r/Z;
	int sum = 0;
	if(c_l == c_r)
	{
		if(bl[c_l].fc)
		{
			for(int i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(int i=l;i<=r;i++)
		sum += elem[i].cl;
	}
	else
	{
		//LEFT HEAD
		if(bl[c_l].fc)
		{
			for(int i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(int i=l,j=(c_l+1)*Z;i<j;i++)
		sum += elem[i].cl;
		//MIDDLE
		for(int i=c_l+1;i<c_r;i++)
		sum += bl[i].tc;
		//RIGHT TAIL
		if(bl[c_r].fc)
		{
			for(int i=c_r*Z,j=(c_r+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_r].fc - elem[i].co);
				elem[i].cl += (t + bl[c_r].ac);
				elem[i].co = bl[c_r].cc;
			}
			bl[c_r].fc = bl[c_r].cc = bl[c_r].ac = 0;
		}
		for(int i=c_r*Z;i<=r;i++)
		sum += elem[i].cl;
	}
	return sum;
}

int main(void)
{
	int n,m;
	std::cin>>n>>m;
	Z = floor(sqrt(n));
	for(int i=1;i<=n;i++)
	{
		elem[i].co = i;
		elem[i].cl = 0;
		bl[i/Z].s.insert(mp(i, 1));
	}
	for(int i=0;i<=Z;i++)
	bl[i].tc = bl[i].cc = bl[i].fc = bl[i].ac = 0;
	sqrtdec T;
	while(m--)
	{
		int q;
		std::cin>>q;
		if(--q)
		{
			int l,r;
			std::cin>>l>>r;
			std::cout<<T.query(l, r)<<"\n";
		}
		else
		{
			int l,r,x;
			std::cin>>l>>r>>x;
			T.update(l, r, x);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define mp std::make_pair

typedef long long ll;
typedef std::set<std::pair<ll, ll> > sp;
typedef std::pair<ll, ll> px;

struct elem
{
	ll co,cl;
}elem[100100];

struct sq
{
	ll tc,fc,cc,ac;
	sp s;
}bl[350];

ll Z;

class sqrtdec
{
	public: void update(ll l, ll r, ll x);
			ll query(ll l, ll r);
};

void sqrtdec::update(ll l, ll r, ll x)
{
	ll c_l = l/Z;
	ll c_r = r/Z;
	if(c_l == c_r)
	{
		if(bl[c_l].fc)
		{
			for(ll i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(ll i=l;i<=r;i++)
		{
			ll t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_l].tc += t;
			for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					ll u = it->first;
					ll v = it->second - 1;
					px e = *it;
					it++;
					bl[c_l].s.erase(e);
					if(v)
					bl[c_l].s.insert(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		bool flag = 0;
		for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
		{
			if(it->first == x)
			{
				ll u = it->first;
				ll v = it->second + (r-l+1);
				px e = *it;
				it++;
				bl[c_l].s.erase(e);
				if(v)
				bl[c_l].s.insert(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_l].s.insert(mp(x, r-l+1));
	}
	else
	{
		//LEFT HEAD
		if(bl[c_l].fc)
		{
			for(ll i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(ll i=l,j=(c_l+1)*Z;i<j;i++)
		{
			ll t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_l].tc += t;
			for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					ll u = it->first;
					ll v = it->second - 1;
					px e = *it;
					it++;
					bl[c_l].s.erase(e);
					if(v)
					bl[c_l].s.insert(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		bool flag = 0;
		for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
		{
			if(it->first == x)
			{
				ll u = it->first;
				ll v = it->second + (c_l+1)*Z-l;
				px e = *it;
				it++;
				bl[c_l].s.erase(e);
				if(v)
				bl[c_l].s.insert(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_l].s.insert(mp(x, (c_l+1)*Z-l));
		//RIGHT TAIL
		if(bl[c_r].fc)
		{
			for(ll i=c_r*Z,j=(c_r+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_r].fc - elem[i].co);
				elem[i].cl += (t + bl[c_r].ac);
				elem[i].co = bl[c_r].cc;
			}
			bl[c_r].fc = bl[c_r].cc = bl[c_r].ac = 0;
		}
		for(ll i=c_r*Z;i<=r;i++)
		{
			ll t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_r].tc += t;
			for(sp::iterator it=bl[c_r].s.begin();it != bl[c_r].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					ll u = it->first;
					ll v = it->second - 1;
					px e = *it;
					it++;
					bl[c_r].s.erase(e);
					if(v)
					bl[c_r].s.insert(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		flag = 0;
		for(sp::iterator it=bl[c_r].s.begin();it != bl[c_r].s.end();it++)
		{
			if(it->first == x)
			{
				ll u = it->first;
				ll v = it->second + r-(c_r*Z)+1;
				px e = *it;
				it++;
				bl[c_r].s.erase(e);
				if(v)
				bl[c_r].s.insert(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_r].s.insert(mp(x, r-(c_r*Z)+1));
		//MIDDLE
		for(ll i=c_l+1;i<c_r;i++)
		{
			for(sp::iterator it=bl[i].s.begin();it != bl[i].s.end(); )
			{
				ll u = it->first;
				ll v = it->second;
				bl[i].tc += v*fabs(x - u);
				px e = *it;
				it++;
				bl[i].s.erase(e);
			}
			bl[i].s.insert(mp(x, Z));
			if(bl[i].fc)
			{
				bl[i].ac += fabs(bl[i].cc - x);
				bl[i].cc = x;
			}
			else bl[i].fc = bl[i].cc = x;
		}
	}
}

ll sqrtdec::query(ll l, ll r)
{
	ll c_l = l/Z;
	ll c_r = r/Z;
	ll sum = 0;
	if(c_l == c_r)
	{
		if(bl[c_l].fc)
		{
			for(ll i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(ll i=l;i<=r;i++)
		sum += elem[i].cl;
	}
	else
	{
		//LEFT HEAD
		if(bl[c_l].fc)
		{
			for(ll i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(ll i=l,j=(c_l+1)*Z;i<j;i++)
		sum += elem[i].cl;
		//MIDDLE
		for(ll i=c_l+1;i<c_r;i++)
		sum += bl[i].tc;
		//RIGHT TAIL
		if(bl[c_r].fc)
		{
			for(ll i=c_r*Z,j=(c_r+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_r].fc - elem[i].co);
				elem[i].cl += (t + bl[c_r].ac);
				elem[i].co = bl[c_r].cc;
			}
			bl[c_r].fc = bl[c_r].cc = bl[c_r].ac = 0;
		}
		for(ll i=c_r*Z;i<=r;i++)
		sum += elem[i].cl;
	}
	return sum;
}

int main(void)
{
	ll n,m;
	std::cin>>n>>m;
	Z = floor(sqrt(n));
	for(ll i=1;i<=n;i++)
	{
		elem[i].co = i;
		elem[i].cl = 0;
		bl[i/Z].s.insert(mp(i, 1));
	}
	for(ll i=0;i<=Z;i++)
	bl[i].tc = bl[i].cc = bl[i].fc = bl[i].ac = 0;
	sqrtdec T;
	while(m--)
	{
		ll q;
		std::cin>>q;
		if(--q)
		{
			ll l,r;
			std::cin>>l>>r;
			std::cout<<T.query(l, r)<<"\n";
		}
		else
		{
			ll l,r,x;
			std::cin>>l>>r>>x;
			T.update(l, r, x);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define mp std::make_pair

typedef std::set<std::pair<int, int> > sp;

struct elem
{
	int co,cl;
}elem[100100];

struct sq
{
	int tc,fc,cc,ac;
	sp s;
}bl[350];

int Z;

class sqrtdec
{
	public: void update(int l, int r, int x);
			int query(int l, int r);
};

void sqrtdec::update(int l, int r, int x)
{
	int c_l = l/Z;
	int c_r = r/Z;
	if(c_l == c_r)
	{
		if(bl[c_l].fc)
		{
			for(int i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(int i=l;i<=r;i++)
		{
			int t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_l].tc += t;
			for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					int u = it->first;
					int v = it->second - 1;
					bl[c_l].s.erase(it);
					if(v)
					bl[c_l].s.insert(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		bool flag = 0;
		for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
		{
			if(it->first == x)
			{
				int u = it->first;
				int v = it->second + (r-l+1);
				bl[c_l].s.erase(it);
				if(v)
				bl[c_l].s.insert(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_l].s.insert(mp(x, r-l+1));
	}
	else
	{
		//LEFT HEAD
		if(bl[c_l].fc)
		{
			for(int i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(int i=l,j=(c_l+1)*Z;i<j;i++)
		{
			int t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_l].tc += t;
			for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					int u = it->first;
					int v = it->second - 1;
					bl[c_l].s.erase(it);
					if(v)
					bl[c_l].s.insert(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		bool flag = 0;
		for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
		{
			if(it->first == x)
			{
				int u = it->first;
				int v = it->second + (c_l+1)*Z-l;
				bl[c_l].s.erase(it);
				if(v)
				bl[c_l].s.insert(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_l].s.insert(mp(x, (c_l+1)*Z-l));
		//RIGHT TAIL
		if(bl[c_r].fc)
		{
			for(int i=c_r*Z,j=(c_r+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_r].fc - elem[i].co);
				elem[i].cl += (t + bl[c_r].ac);
				elem[i].co = bl[c_r].cc;
			}
			bl[c_r].fc = bl[c_r].cc = bl[c_r].ac = 0;
		}
		for(int i=c_r*Z;i<=r;i++)
		{
			int t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_r].tc += t;
			for(sp::iterator it=bl[c_r].s.begin();it != bl[c_r].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					int u = it->first;
					int v = it->second - 1;
					bl[c_r].s.erase(it);
					if(v)
					bl[c_r].s.insert(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		flag = 0;
		for(sp::iterator it=bl[c_r].s.begin();it != bl[c_r].s.end();it++)
		{
			if(it->first == x)
			{
				int u = it->first;
				int v = it->second + r-(c_r*Z)+1;
				bl[c_r].s.erase(it);
				if(v)
				bl[c_r].s.insert(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_r].s.insert(mp(x, r-(c_r*Z)+1));
		//MIDDLE
		for(int i=c_l+1;i<c_r;i++)
		{
			for(sp::iterator it=bl[i].s.begin();it != bl[i].s.end();it++)
			{
				int u = it->first;
				int v = it->second;
				bl[i].tc += v*fabs(x - u);
				bl[i].s.erase(it);
			}
			bl[i].s.insert(mp(x, Z));
			if(bl[i].fc)
			{
				bl[i].ac += fabs(bl[i].cc - x);
				bl[i].cc = x;
			}
			else bl[i].fc = bl[i].cc = x;
		}
	}
}

int sqrtdec::query(int l, int r)
{
	int c_l = l/Z;
	int c_r = r/Z;
	int sum = 0;
	if(c_l == c_r)
	{
		if(bl[c_l].fc)
		{
			for(int i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(int i=l;i<=r;i++)
		sum += elem[i].cl;
	}
	else
	{
		//LEFT HEAD
		if(bl[c_l].fc)
		{
			for(int i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(int i=l,j=(c_l+1)*Z;i<j;i++)
		sum += elem[i].cl;
		//MIDDLE
		for(int i=c_l+1;i<c_r;i++)
		sum += bl[i].tc;
		//RIGHT TAIL
		if(bl[c_r].fc)
		{
			for(int i=c_r*Z,j=(c_r+1)*Z;i<j;i++)
			{
				int t = fabs(bl[c_r].fc - elem[i].co);
				elem[i].cl += (t + bl[c_r].ac);
				elem[i].co = bl[c_r].cc;
			}
			bl[c_r].fc = bl[c_r].cc = bl[c_r].ac = 0;
		}
		for(int i=c_r*Z;i<=r;i++)
		sum += elem[i].cl;
	}
	return sum;
}

int main(void)
{
	int n,m;
	std::cin>>n>>m;
	Z = floor(sqrt(n));
	for(int i=1;i<=n;i++)
	{
		elem[i].co = i;
		elem[i].cl = 0;
		bl[i/Z].s.insert(mp(i, 1));
	}
	for(int i=0;i<=Z;i++)
	bl[i].tc = bl[i].cc = bl[i].fc = bl[i].ac = 0;
	sqrtdec T;
	while(m--)
	{
		int q;
		std::cin>>q;
		if(--q)
		{
			int l,r;
			std::cin>>l>>r;
			std::cout<<T.query(l, r)<<"\n";
		}
		else
		{
			int l,r,x;
			std::cin>>l>>r>>x;
			T.update(l, r, x);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#include <boost/functional/hash.hpp>
#define mp std::make_pair

typedef long long ll;
typedef std::unordered_set<std::pair<ll, ll>, boost::hash <std::pair <ll, ll> > > sp;
typedef std::pair<ll, ll> px;

struct emt
{
	ll co,cl;
}elem[100100];

struct sq
{
	ll tc,fc,cc,ac;
	sp s;
}bl[350];

ll Z;

class sqrtdec
{
	public: void update(ll l, ll r, ll x);
			ll query(ll l, ll r);
};

void sqrtdec::update(ll l, ll r, ll x)
{
	ll c_l = l/Z;
	ll c_r = r/Z;
	if(c_l == c_r)
	{
		if(bl[c_l].fc)
		{
			for(ll i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(ll i=l;i<=r;i++)
		{
			ll t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_l].tc += t;
			for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					ll u = it->first;
					ll v = it->second - 1;
					px e = *it;
					it++;
					bl[c_l].s.erase(e);
					if(v)
					bl[c_l].s.insert(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		bool flag = 0;
		for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
		{
			if(it->first == x)
			{
				ll u = it->first;
				ll v = it->second + (r-l+1);
				px e = *it;
				it++;
				bl[c_l].s.erase(e);
				if(v)
				bl[c_l].s.insert(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_l].s.insert(mp(x, r-l+1));
	}
	else
	{
		//LEFT HEAD
		if(bl[c_l].fc)
		{
			for(ll i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(ll i=l,j=(c_l+1)*Z;i<j;i++)
		{
			ll t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_l].tc += t;
			for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					ll u = it->first;
					ll v = it->second - 1;
					px e = *it;
					it++;
					bl[c_l].s.erase(e);
					if(v)
					bl[c_l].s.insert(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		bool flag = 0;
		for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++)
		{
			if(it->first == x)
			{
				ll u = it->first;
				ll v = it->second + (c_l+1)*Z-l;
				px e = *it;
				it++;
				bl[c_l].s.erase(e);
				if(v)
				bl[c_l].s.insert(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_l].s.insert(mp(x, (c_l+1)*Z-l));
		//RIGHT TAIL
		if(bl[c_r].fc)
		{
			for(ll i=c_r*Z,j=(c_r+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_r].fc - elem[i].co);
				elem[i].cl += (t + bl[c_r].ac);
				elem[i].co = bl[c_r].cc;
			}
			bl[c_r].fc = bl[c_r].cc = bl[c_r].ac = 0;
		}
		for(ll i=c_r*Z;i<=r;i++)
		{
			ll t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_r].tc += t;
			for(sp::iterator it=bl[c_r].s.begin();it != bl[c_r].s.end();it++)
			{
				if(it->first == elem[i].co)
				{
					ll u = it->first;
					ll v = it->second - 1;
					px e = *it;
					it++;
					bl[c_r].s.erase(e);
					if(v)
					bl[c_r].s.insert(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		flag = 0;
		for(sp::iterator it=bl[c_r].s.begin();it != bl[c_r].s.end();it++)
		{
			if(it->first == x)
			{
				ll u = it->first;
				ll v = it->second + r-(c_r*Z)+1;
				px e = *it;
				it++;
				bl[c_r].s.erase(e);
				if(v)
				bl[c_r].s.insert(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_r].s.insert(mp(x, r-(c_r*Z)+1));
		//MIDDLE
		for(ll i=c_l+1;i<c_r;i++)
		{
			for(sp::iterator it=bl[i].s.begin();it != bl[i].s.end(); )
			{
				ll u = it->first;
				ll v = it->second;
				bl[i].tc += v*fabs(x - u);
				px e = *it;
				it++;
				bl[i].s.erase(e);
			}
			bl[i].s.insert(mp(x, Z));
			if(bl[i].fc)
			{
				bl[i].ac += fabs(bl[i].cc - x);
				bl[i].cc = x;
			}
			else bl[i].fc = bl[i].cc = x;
		}
	}
}

ll sqrtdec::query(ll l, ll r)
{
	ll c_l = l/Z;
	ll c_r = r/Z;
	ll sum = 0;
	if(c_l == c_r)
	{
		if(bl[c_l].fc)
		{
			for(ll i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(ll i=l;i<=r;i++)
		sum += elem[i].cl;
	}
	else
	{
		//LEFT HEAD
		if(bl[c_l].fc)
		{
			for(ll i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(ll i=l,j=(c_l+1)*Z;i<j;i++)
		sum += elem[i].cl;
		//MIDDLE
		for(ll i=c_l+1;i<c_r;i++)
		sum += bl[i].tc;
		//RIGHT TAIL
		if(bl[c_r].fc)
		{
			for(ll i=c_r*Z,j=(c_r+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_r].fc - elem[i].co);
				elem[i].cl += (t + bl[c_r].ac);
				elem[i].co = bl[c_r].cc;
			}
			bl[c_r].fc = bl[c_r].cc = bl[c_r].ac = 0;
		}
		for(ll i=c_r*Z;i<=r;i++)
		sum += elem[i].cl;
	}
	return sum;
}

int main(void)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	ll n,m;
	std::cin>>n>>m;
	Z = floor(sqrt(n));
	for(ll i=1;i<=n;i++)
	{
		elem[i].co = i;
		elem[i].cl = 0;
		bl[i/Z].s.insert(mp(i, 1));
	}
	for(ll i=0;i<=Z;i++)
	bl[i].tc = bl[i].cc = bl[i].fc = bl[i].ac = 0;
	sqrtdec T;
	while(m--)
	{
		ll q;
		std::cin>>q;
		if(--q)
		{
			ll l,r;
			std::cin>>l>>r;
			std::cout<<T.query(l, r)<<"\n";
		}
		else
		{
			ll l,r,x;
			std::cin>>l>>r>>x;
			T.update(l, r, x);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define mp std::make_pair
#define pb push_back

typedef long long ll;
typedef std::vector<std::pair<ll, ll> > sp;
typedef std::pair<ll, ll> px;

struct elem
{
	ll co,cl;
}elem[100100];

struct sq
{
	ll tc,fc,cc,ac;
	sp s;
}bl[350];

ll Z;

class sqrtdec
{
	public: void update(ll l, ll r, ll x);
			ll query(ll l, ll r);
};

void sqrtdec::update(ll l, ll r, ll x)
{
	ll c_l = l/Z;
	ll c_r = r/Z;
	if(c_l == c_r)
	{
		if(bl[c_l].fc)
		{
			for(ll i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(ll i=l;i<=r;i++)
		{
			ll t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_l].tc += t;
			ll pos = 0;
			for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++,pos++)
			{
				if(it->first == elem[i].co)
				{
					ll u = it->first;
					ll v = it->second - 1;
					it++;
					bl[c_l].s.erase(bl[c_l].s.begin()+pos);
					if(v)
					bl[c_l].s.pb(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		bool flag = 0;
		ll pos = 0;
		for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++,pos++)
		{
			if(it->first == x)
			{
				ll u = it->first;
				ll v = it->second + (r-l+1);
				it++;
				bl[c_l].s.erase(bl[c_l].s.begin()+pos);
				if(v)
				bl[c_l].s.pb(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_l].s.pb(mp(x, r-l+1));
	}
	else
	{
		//LEFT HEAD
		if(bl[c_l].fc)
		{
			for(ll i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(ll i=l,j=(c_l+1)*Z;i<j;i++)
		{
			ll t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_l].tc += t;
			ll pos = 0;
			for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++,pos++)
			{
				if(it->first == elem[i].co)
				{
					ll u = it->first;
					ll v = it->second - 1;
					it++;
					bl[c_l].s.erase(bl[c_l].s.begin()+pos);
					if(v)
					bl[c_l].s.pb(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		bool flag = 0;
		ll pos = 0;
		for(sp::iterator it=bl[c_l].s.begin();it != bl[c_l].s.end();it++,pos++)
		{
			if(it->first == x)
			{
				ll u = it->first;
				ll v = it->second + (c_l+1)*Z-l;
				px e = *it;
				it++;
				bl[c_l].s.erase(bl[c_l].s.begin()+pos);
				if(v)
				bl[c_l].s.pb(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_l].s.pb(mp(x, (c_l+1)*Z-l));
		//RIGHT TAIL
		if(bl[c_r].fc)
		{
			for(ll i=c_r*Z,j=(c_r+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_r].fc - elem[i].co);
				elem[i].cl += (t + bl[c_r].ac);
				elem[i].co = bl[c_r].cc;
			}
			bl[c_r].fc = bl[c_r].cc = bl[c_r].ac = 0;
		}
		for(ll i=c_r*Z;i<=r;i++)
		{
			ll t = fabs(x - elem[i].co);
			elem[i].cl += t;
			bl[c_r].tc += t;
			ll pos = 0;
			for(sp::iterator it=bl[c_r].s.begin();it != bl[c_r].s.end();it++,pos++)
			{
				if(it->first == elem[i].co)
				{
					ll u = it->first;
					ll v = it->second - 1;
					it++;
					bl[c_r].s.erase(bl[c_r].s.begin()+pos);
					if(v)
					bl[c_r].s.pb(mp(u, v));
					break;
				}
			}
			elem[i].co = x;
		}
		flag = 0;
		pos = 0;
		for(sp::iterator it=bl[c_r].s.begin();it != bl[c_r].s.end();it++,pos++)
		{
			if(it->first == x)
			{
				ll u = it->first;
				ll v = it->second + r-(c_r*Z)+1;
				it++;
				bl[c_r].s.erase(bl[c_r].s.begin()+pos);
				if(v)
				bl[c_r].s.pb(mp(u, v));
				flag = 1;
				break;
			}
		}
		if(!flag)
		bl[c_r].s.pb(mp(x, r-(c_r*Z)+1));
		//MIDDLE
		for(ll i=c_l+1;i<c_r;i++)
		{
			for(sp::iterator it=bl[i].s.begin();it != bl[i].s.end();)
			{
				ll u = it->first;
				ll v = it->second;
				bl[i].tc += v*fabs(x - u);
				it++;
			}
			bl[i].s.clear();
			bl[i].s.pb(mp(x, Z));
			if(bl[i].fc)
			{
				bl[i].ac += fabs(bl[i].cc - x);
				bl[i].cc = x;
			}
			else bl[i].fc = bl[i].cc = x;
		}
	}
}

ll sqrtdec::query(ll l, ll r)
{
	ll c_l = l/Z;
	ll c_r = r/Z;
	ll sum = 0;
	if(c_l == c_r)
	{
		if(bl[c_l].fc)
		{
			for(ll i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(ll i=l;i<=r;i++)
		sum += elem[i].cl;
	}
	else
	{
		//LEFT HEAD
		if(bl[c_l].fc)
		{
			for(ll i=c_l*Z,j=(c_l+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_l].fc - elem[i].co);
				elem[i].cl += (t + bl[c_l].ac);
				elem[i].co = bl[c_l].cc;
			}
			bl[c_l].fc = bl[c_l].cc = bl[c_l].ac = 0;
		}
		for(ll i=l,j=(c_l+1)*Z;i<j;i++)
		sum += elem[i].cl;
		//MIDDLE
		for(ll i=c_l+1;i<c_r;i++)
		sum += bl[i].tc;
		//RIGHT TAIL
		if(bl[c_r].fc)
		{
			for(ll i=c_r*Z,j=(c_r+1)*Z;i<j;i++)
			{
				ll t = fabs(bl[c_r].fc - elem[i].co);
				elem[i].cl += (t + bl[c_r].ac);
				elem[i].co = bl[c_r].cc;
			}
			bl[c_r].fc = bl[c_r].cc = bl[c_r].ac = 0;
		}
		for(ll i=c_r*Z;i<=r;i++)
		sum += elem[i].cl;
	}
	return sum;
}

int main(void)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	ll n,m;
	std::cin>>n>>m;
	Z = floor(sqrt(n));
	for(ll i=1;i<=n;i++)
	{
		elem[i].co = i;
		elem[i].cl = 0;
		bl[i/Z].s.pb(mp(i, 1));
	}
	for(ll i=0;i<=Z;i++)
	bl[i].tc = bl[i].cc = bl[i].fc = bl[i].ac = 0;
	sqrtdec T;
	while(m--)
	{
		ll q;
		std::cin>>q;
		if(--q)
		{
			ll l,r;
			std::cin>>l>>r;
			std::cout<<T.query(l, r)<<"\n";
		}
		else
		{
			ll l,r,x;
			std::cin>>l>>r>>x;
			T.update(l, r, x);
		}
	}
	return 0;
}


#include <iostream>
#include <set>
#include <algorithm>

using namespace std;

const int NMAX = 1e5;

int N, M;

int ABS(int x)
{
    return max(x, -x);
}

struct compactInt {
    int l, r, c;

    bool operator < (const compactInt other) const {
        return l < other.l;
    }
};

set < compactInt > s;

///AINT

struct Aint {

    long long v[4 * NMAX];
    long long lazy[4 * NMAX];

    void Update(int node, int l, int r, int st, int dr, int val)
    {
        ///push lazy
        if(lazy[node]) {
            v[node] += 1LL * lazy[node] * (r - l + 1);
            if(l != r) {
                lazy[(node << 1)] += lazy[node];
                lazy[(node << 1) + 1] += lazy[node];
            }
            lazy[node] = 0;
        }

        ///non overlap
        if(dr < l || r < st)
            return ;

        ///full overlap
        if(st <= l && r <= dr) {
            v[node] += 1LL * val * (r - l + 1);
            if(l != r) {
                lazy[(node << 1)] += val;
                lazy[(node << 1) + 1] += val;
            }
            return ;
        }

        ///recurse
        int mid = (l + r) >> 1;

        Update((node << 1), l, mid, st, dr, val);
        Update((node << 1) + 1, mid + 1, r, st, dr, val);

        v[node] = v[(node << 1)] + v[(node << 1) + 1];
    }

    long long Query(int node, int l, int r, int st, int dr)
    {
        ///push lazy
        if(lazy[node]) {
            v[node] += 1LL * lazy[node] * (r - l + 1);
            if(l != r) {
                lazy[(node << 1)] += lazy[node];
                lazy[(node << 1) + 1] += lazy[node];
            }
            lazy[node] = 0;
        }

        ///non overlap
        if(dr < l || r < st)
            return 0;

        ///full overlap
        if(st <= l && r <= dr) {
            return v[node];
        }

        ///recurse
        int mid = (l + r) >> 1;

        long long a1 = Query((node << 1), l, mid, st, dr);
        long long a2 = Query((node << 1) + 1, mid + 1, r, st, dr);

        return a1 + a2;
    }
};

Aint aint;

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

    cin >> N >> M;

    for(int i = 1; i <= N; i++) {
        s.insert({i, i, i});
    }

    for(int i = 1; i <= M; i++) {
        int t;
        cin >> t;

        if(t == 1) {
            int st, dr, nc;
            cin >> st >> dr >> nc;

            int currentPos = st;

            auto it = --s.upper_bound({currentPos, -1, -1});

            while(currentPos <= dr) {

                compactInt curr = *it;

                auto nxt = ++it;

                s.erase(--it);

                if(curr.l < currentPos) {
                    ///sparg intervalul la stanga
                    s.insert({curr.l, currentPos - 1, curr.c});
                }

                if(curr.r <= dr) {
                    ///transform tot intervalul
                    s.insert({curr.l, curr.r, nc});

                    aint.Update(1, 1, N, curr.l, curr.r, ABS(nc - curr.c));
                } else {

                    ///sparg intervalul la dreapta
                    s.insert({dr + 1, curr.r, curr.c});

                    s.insert({curr.l, dr, nc});

                    aint.Update(1, 1, N, curr.l, dr, ABS(nc - curr.c));
                }

                currentPos = curr.r + 1;

                it = nxt;
            }

        } else {
            int st, dr;
            cin >> st >> dr;
            cout << aint.Query(1, 1, N, st, dr) << '\n';
        }
    }

    return 0;
}


#include <iostream>
#include <set>
#include <algorithm>

using namespace std;

const int NMAX = 1e5;

int N, M;

inline int ABS(int x)
{
    return max(x, -x);
}

struct compactInt {
    int l, r, c;

    bool operator < (const compactInt other) const {
        return l < other.l;
    }
};

set < compactInt > s;

///AINT

struct Aint {

    long long v[4 * NMAX + 2];
    long long lazy[4 * NMAX + 2];

    void Update(int node, int l, int r, int st, int dr, int val)
    {
        ///push lazy
        if(lazy[node]) {
            v[node] += 1LL * lazy[node] * (r - l + 1);
            if(l != r) {
                lazy[2 * node] += lazy[node];
                lazy[2 * node + 1] += lazy[node];
            }
            lazy[node] = 0;
        }

        ///non overlap
        if(dr < l || r < st)
            return ;

        ///full overlap
        if(st <= l && r <= dr) {
            v[node] += 1LL * val * (r - l + 1);
            if(l != r) {
                lazy[2 * node] += val;
                lazy[2 * node + 1] += val;
            }
            return ;
        }

        ///recurse
        int mid = (l + r) >> 1;

        Update(2 * node, l, mid, st, dr, val);
        Update(2 * node + 1, mid + 1, r, st, dr, val);

        v[node] = v[2 * node] + v[2 * node + 1];
    }

    long long Query(int node, int l, int r, int st, int dr)
    {
        ///push lazy
        if(lazy[node]) {
            v[node] += 1LL * lazy[node] * (r - l + 1);
            if(l != r) {
                lazy[2 * node] += lazy[node];
                lazy[2 * node + 1] += lazy[node];
            }
            lazy[node] = 0;
        }

        ///non overlap
        if(dr < l || r < st)
            return 0;

        ///full overlap
        if(st <= l && r <= dr) {
            return v[node];
        }

        ///recurse
        int mid = (l + r) >> 1;

        long long a1 = Query(2 * node, l, mid, st, dr);
        long long a2 = Query(2 * node + 1, mid + 1, r, st, dr);

        return a1 + a2;
    }
};

Aint aint;

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

    cin >> N >> M;

    for(int i = 1; i <= N; i++) {
        s.insert({i, i, i});
    }

    for(int i = 1; i <= M; i++) {
        int t;
        cin >> t;

        if(t == 1) {
            int st, dr, nc;
            cin >> st >> dr >> nc;

            int currentPos = st;

            while(currentPos <= dr) {
                auto it = --s.upper_bound({currentPos, -1, -1});
                compactInt curr = *it;

                s.erase(it);

                if(curr.l < currentPos) {
                    ///sparg intervalul la stanga
                    compactInt newL = {curr.l, currentPos - 1, curr.c};
                    s.insert(newL);
                }

                if(curr.r <= dr) {
                    ///transform tot intervalul
                    aint.Update(1, 1, N, curr.l, curr.r, ABS(nc - curr.c));
                } else {

                    ///sparg intervalul la dreapta
                    compactInt newR = {dr + 1, curr.r, curr.c};
                    s.insert(newR);

                    aint.Update(1, 1, N, curr.l, dr, ABS(nc - curr.c));
                }

                currentPos = curr.r + 1;
            }

            s.insert({st, dr, nc});

        } else {
            int st, dr;
            cin >> st >> dr;
            cout << aint.Query(1, 1, N, st, dr) << '\n';
        }
    }

    return 0;
}


#include <iostream>
#include <set>
#include <algorithm>

using namespace std;

const int NMAX = 1e5;

int N, M;

inline int ABS(int x)
{
    return max(x, -x);
}

struct compactInt {
    int l, r, c;

    bool operator < (const compactInt other) const {
        return l < other.l;
    }
};

set < compactInt > s;

///AINT

struct Aint {

    long long v[4 * NMAX + 2];
    long long lazy[4 * NMAX + 2];

    void Update(int node, int l, int r, int st, int dr, int val)
    {
        ///push lazy
        if(lazy[node]) {
            v[node] += 1LL * lazy[node] * (r - l + 1);
            if(l != r) {
                lazy[2 * node] += lazy[node];
                lazy[2 * node + 1] += lazy[node];
            }
            lazy[node] = 0;
        }

        ///non overlap
        if(dr < l || r < st)
            return ;

        ///full overlap
        if(st <= l && r <= dr) {
            v[node] += 1LL * val * (r - l + 1);
            if(l != r) {
                lazy[2 * node] += val;
                lazy[2 * node + 1] += val;
            }
            return ;
        }

        ///recurse
        int mid = (l + r) >> 1;

        Update(2 * node, l, mid, st, dr, val);
        Update(2 * node + 1, mid + 1, r, st, dr, val);

        v[node] = v[2 * node] + v[2 * node + 1];
    }

    long long Query(int node, int l, int r, int st, int dr)
    {
        ///push lazy
        if(lazy[node]) {
            v[node] += 1LL * lazy[node] * (r - l + 1);
            if(l != r) {
                lazy[2 * node] += lazy[node];
                lazy[2 * node + 1] += lazy[node];
            }
            lazy[node] = 0;
        }

        ///non overlap
        if(dr < l || r < st)
            return 0;

        ///full overlap
        if(st <= l && r <= dr) {
            return v[node];
        }

        ///recurse
        int mid = (l + r) >> 1;

        long long a1 = Query(2 * node, l, mid, st, dr);
        long long a2 = Query(2 * node + 1, mid + 1, r, st, dr);

        return a1 + a2;
    }
};

Aint aint;

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

    cin >> N >> M;

    for(int i = 1; i <= N; i++) {
        s.insert({i, i, i});
    }

    for(int i = 1; i <= M; i++) {
        int t;
        cin >> t;

        if(t == 1) {
            int st, dr, nc;
            cin >> st >> dr >> nc;

            int currentPos = st;

            while(currentPos <= dr) {
                auto it = --s.upper_bound({currentPos, -1, -1});
                compactInt curr = *it;

                s.erase(it);

                if(curr.l < currentPos) {
                    ///sparg intervalul la stanga
                    compactInt newL = {curr.l, currentPos - 1, curr.c};
                    s.insert(newL);
                }

                if(curr.r <= dr) {
                    ///transform tot intervalul
                    aint.Update(1, 1, N, max(curr.l, currentPos), curr.r, ABS(nc - curr.c));
                } else {

                    ///sparg intervalul la dreapta
                    compactInt newR = {dr + 1, curr.r, curr.c};
                    s.insert(newR);

                    aint.Update(1, 1, N, max(curr.l, currentPos), dr, ABS(nc - curr.c));
                }

                currentPos = curr.r + 1;
            }

            s.insert({st, dr, nc});

        } else {
            int st, dr;
            cin >> st >> dr;
            cout << aint.Query(1, 1, N, st, dr) << '\n';
        }
    }

    return 0;
}


#include <iostream>
#include <set>
#include <algorithm>

using namespace std;

const int NMAX = 1e5;

int N, M;

int ABS(int x)
{
    return max(x, -x);
}

struct compactInt {
    int l, r, c;

    bool operator < (const compactInt other) const {
        return l < other.l;
    }
};

set < compactInt > s;

///AINT

struct Aint {

    long long v[5 * NMAX];
    long long lazy[5 * NMAX];

    void Update(int node, int l, int r, int st, int dr, int val)
    {
        ///push lazy
        if(lazy[node]) {
            v[node] += 1LL * lazy[node] * (r - l + 1);
            if(l != r) {
                lazy[(node << 1)] += lazy[node];
                lazy[(node << 1) + 1] += lazy[node];
            }
            lazy[node] = 0;
        }

        ///non overlap
        if(dr < l || r < st)
            return ;

        ///full overlap
        if(st <= l && r <= dr) {
            v[node] += 1LL * val * (r - l + 1);
            if(l != r) {
                lazy[(node << 1)] += val;
                lazy[(node << 1) + 1] += val;
            }
            return ;
        }

        ///recurse
        int mid = (l + r) >> 1;

        Update((node << 1), l, mid, st, dr, val);
        Update((node << 1) + 1, mid + 1, r, st, dr, val);

        v[node] = v[(node << 1)] + v[(node << 1) + 1];
    }

    long long Query(int node, int l, int r, int st, int dr)
    {
        ///push lazy
        if(lazy[node]) {
            v[node] += 1LL * lazy[node] * (r - l + 1);
            if(l != r) {
                lazy[(node << 1)] += lazy[node];
                lazy[(node << 1) + 1] += lazy[node];
            }
            lazy[node] = 0;
        }

        ///non overlap
        if(dr < l || r < st)
            return 0;

        ///full overlap
        if(st <= l && r <= dr) {
            return v[node];
        }

        ///recurse
        int mid = (l + r) >> 1;

        long long a1 = Query((node << 1), l, mid, st, dr);
        long long a2 = Query((node << 1) + 1, mid + 1, r, st, dr);

        return a1 + a2;
    }
};

Aint aint;

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

    cin >> N >> M;

    for(int i = 1; i <= N; i++) {
        s.insert({i, i, i});
    }

    for(int i = 1; i <= M; i++) {
        int t;
        cin >> t;

        if(t == 1) {
            int st, dr, nc;
            cin >> st >> dr >> nc;

            int currentPos = st;

            while(currentPos <= dr) {
                auto it = --s.upper_bound({currentPos, -1, -1});
                compactInt curr = *it;

                s.erase(it);

                if(curr.l < currentPos) {
                    ///sparg intervalul la stanga
                    s.insert({curr.l, currentPos - 1, curr.c});
                }

                if(curr.r <= dr) {
                    ///transform tot intervalul
                    s.insert({curr.l, curr.r, nc});

                    aint.Update(1, 1, N, curr.l, curr.r, ABS(nc - curr.c));
                } else {

                    ///sparg intervalul la dreapta
                    s.insert({dr + 1, curr.r, curr.c});

                    s.insert({curr.l, dr, nc});

                    aint.Update(1, 1, N, curr.l, dr, ABS(nc - curr.c));
                }

                currentPos = curr.r + 1;
            }

        } else {
            int st, dr;
            cin >> st >> dr;
            cout << aint.Query(1, 1, N, st, dr) << '\n';
        }
    }

    return 0;
}


#include <iostream>
#include <set>
#include <algorithm>

using namespace std;

const int NMAX = 1e5;

int N, M;

inline int ABS(int x)
{
    return max(x, -x);
}

struct compactInt {
    int l, r, c;

    bool operator < (const compactInt other) const {
        return l < other.l;
    }
};

set < compactInt > s;

///AINT

struct Aint {

    long long v[4 * NMAX + 2];
    long long lazy[4 * NMAX + 2];

    void Update(int node, int l, int r, int st, int dr, int val)
    {
        ///push lazy
        if(lazy[node]) {
            v[node] += 1LL * lazy[node] * (r - l + 1);
            if(l != r) {
                lazy[2 * node] += lazy[node];
                lazy[2 * node + 1] += lazy[node];
            }
            lazy[node] = 0;
        }

        ///non overlap
        if(dr < l || r < st)
            return ;

        ///full overlap
        if(st <= l && r <= dr) {
            v[node] += 1LL * val * (r - l + 1);
            if(l != r) {
                lazy[2 * node] += val;
                lazy[2 * node + 1] += val;
            }
            return ;
        }

        ///recurse
        int mid = (l + r) >> 1;

        Update(2 * node, l, mid, st, dr, val);
        Update(2 * node + 1, mid + 1, r, st, dr, val);

        v[node] = v[2 * node] + v[2 * node + 1];
    }

    long long Query(int node, int l, int r, int st, int dr)
    {
        ///push lazy
        if(lazy[node]) {
            v[node] += 1LL * lazy[node] * (r - l + 1);
            if(l != r) {
                lazy[2 * node] += lazy[node];
                lazy[2 * node + 1] += lazy[node];
            }
            lazy[node] = 0;
        }

        ///non overlap
        if(dr < l || r < st)
            return 0;

        ///full overlap
        if(st <= l && r <= dr) {
            return v[node];
        }

        ///recurse
        int mid = (l + r) >> 1;

        long long a1 = Query(2 * node, l, mid, st, dr);
        long long a2 = Query(2 * node + 1, mid + 1, r, st, dr);

        return a1 + a2;
    }
};

Aint aint;

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

    cin >> N >> M;

    for(int i = 1; i <= N; i++) {
        s.insert({i, i, i});
    }

    for(int i = 1; i <= M; i++) {
        int t;
        cin >> t;

        if(t == 1) {
            int st, dr, nc;
            cin >> st >> dr >> nc;

            int currentPos = st;

            while(currentPos <= dr) {
                auto it = --s.upper_bound({currentPos, -1, -1});
                compactInt curr = *it;

                s.erase(it);

                if(curr.l < currentPos) {
                    ///sparg intervalul la stanga
                    compactInt newL = {curr.l, currentPos - 1, curr.c};
                    s.insert(newL);
                }

                if(curr.r <= dr) {
                    ///transform tot intervalul
                    compactInt middle = {curr.l, curr.r, nc};
                    s.insert(middle);

                    aint.Update(1, 1, N, curr.l, curr.r, ABS(nc - curr.c));
                } else {

                    ///sparg intervalul la dreapta
                    compactInt newR = {dr + 1, curr.r, curr.c};
                    s.insert(newR);

                    compactInt middle = {curr.l, dr, nc};
                    s.insert(middle);

                    aint.Update(1, 1, N, curr.l, dr, ABS(nc - curr.c));
                }

                currentPos = curr.r + 1;
            }

        } else {
            int st, dr;
            cin >> st >> dr;
            cout << aint.Query(1, 1, N, st, dr) << '\n';
        }
    }

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define x first
#define y second
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI (atan(1)*4)
#define mp make_pair
using namespace std;
const int maxn=1e5+7,lim=4*maxn;

unsigned ll lazy[lim],segtree[lim],arr[maxn],val[lim],n,m;
void pushlazy(int cur,int lc,int rc,int l,int mid,int r){
	lazy[lc]+=lazy[cur];
	lazy[rc]+=lazy[cur];
	val[lc]=val[lc]+(mid-l+1)*lazy[cur];
	val[rc]=val[rc]+(r-mid)*lazy[cur];
	lazy[cur]=0;
}

void update2(int cur,int l,int r,int ql,int qr,ll key){
	if(l>qr || r<ql)
		return;
	if(l>=ql && r<=qr){
		val[cur]=val[cur]+(r-l+1)*key;
		lazy[cur]+=key;
		return;
	}
	int lc=2*cur,rc=lc+1,mid=(l+r)/2;
	if(lazy[cur]!=0)
		pushlazy(cur,lc,rc,l,mid,r);
	update2(lc,l,mid,ql,qr,key);
	update2(rc,mid+1,r,ql,qr,key);
	val[cur]=val[lc]+val[rc];
}

ll query(int cur,int l,int r,int ql,int qr){
	if(l>qr || r<ql)
		return 0LL;
	if(l>=ql && r<=qr){
		return val[cur];
	}
	int lc=2*cur,rc=lc+1,mid=(l+r)/2;
	if(lazy[cur]!=0)
		pushlazy(cur,lc,rc,l,mid,r);
	return (query(lc,l,mid,ql,qr)+query(rc,mid+1,r,ql,qr));
}

void build(int cur,int l,int r){
	if(l==r){
		segtree[cur]=arr[l];
		return;
	}
	int lc=2*cur,rc=lc+1,mid=(l+r)/2;
	build(lc,l,mid);
	build(rc,mid+1,r);
	if(segtree[lc]==-1 || segtree[rc]==-1 || segtree[lc]!=segtree[rc])
		segtree[cur]=-1;
	else
		segtree[cur]=segtree[lc];
}

void update1(int cur,int l,int r,int ql,int qr,ll key){
	if(l>qr || r<ql)
		return;
	if(l>=ql && r<=qr && segtree[cur]!=-1){
		ll temp;
		if(key>=segtree[cur])
			temp=key-segtree[cur];
		else
			temp=segtree[cur]-key;
		update2(1,1,n,l,r,temp);
		segtree[cur]=key;
		return;
	}
	int lc=2*cur,rc=lc+1,mid=(l+r)/2;
	update1(lc,l,mid,ql,qr,key);
	update1(rc,mid+1,r,ql,qr,key);
	if(segtree[lc]==-1 || segtree[rc]==-1 || segtree[lc]!=segtree[rc])
		segtree[cur]=-1;
	else
		segtree[cur]=segtree[lc];
}

int main()
{
	fastread;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		arr[i]=i;
	build(1,1,n);
	int t,l,r,x;
	while(m--){
		cin>>t;
		if(t==2){
			cin>>l>>r;
			cout<<query(1,1,n,l,r)<<'\n';
		}else{
			cin>>l>>r>>x;
			update1(1,1,n,l,r,x);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define x first
#define y second
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI (atan(1)*4)
#define mp make_pair
using namespace std;
const int maxn=1e5+7,lim=4*maxn;

ll lazy[lim],segtree[lim],arr[maxn],val[maxn],n,m;
void pushlazy(int cur,int lc,int rc,int l,int mid,int r){
	lazy[lc]+=lazy[cur];
	lazy[rc]+=lazy[cur];
	val[lc]=val[lc]+(mid-l+1)*lazy[cur];
	val[rc]=val[rc]+(r-mid)*lazy[cur];
	lazy[cur]=0;
}

void update2(int cur,int l,int r,int ql,int qr,ll key){
	if(l>qr || r<ql)
		return;
	if(l>=ql && r<=qr){
		val[cur]=val[cur]+(r-l+1)*key;
		lazy[cur]+=key;
		return;
	}
	int lc=2*cur,rc=lc+1,mid=(l+r)/2;
	if(lazy[cur]!=0)
		pushlazy(cur,lc,rc,l,mid,r);
	update2(lc,l,mid,ql,qr,key);
	update2(rc,mid+1,r,ql,qr,key);
	val[cur]=val[lc]+val[rc];
}

ll query(int cur,int l,int r,int ql,int qr){
	if(l>qr || r<ql)
		return 0LL;
	if(l>=ql && r<=qr){
		return val[cur];

	}
	int lc=2*cur,rc=lc+1,mid=(l+r)/2;
	if(lazy[cur]!=0)
		pushlazy(cur,lc,rc,l,mid,r);
	return (query(lc,l,mid,ql,qr)+query(rc,mid+1,r,ql,qr));
}

void build(int cur,int l,int r){
	if(l==r){
		segtree[cur]=arr[l];
		return;
	}
	int lc=2*cur,rc=lc+1,mid=(l+r)/2;
	build(lc,l,mid);
	build(rc,mid+1,r);
	if(segtree[lc]==-1 || segtree[rc]==-1 || segtree[lc]!=segtree[rc])
		segtree[cur]=-1;
	else
		segtree[cur]=segtree[lc];
}

void update1(int cur,int l,int r,int ql,int qr,ll key){
	if(l>qr || r<ql)
		return;
	if(l>=ql && r<=qr && segtree[cur]!=-1){
		update2(1,1,n,l,r,abs(key-segtree[cur]));
		segtree[cur]=key;
		return;
	}
	int lc=2*cur,rc=lc+1,mid=(l+r)/2;
	update1(lc,l,mid,ql,qr,key);
	update1(rc,mid+1,r,ql,qr,key);
	if(segtree[lc]==-1 || segtree[rc]==-1 || segtree[lc]!=segtree[rc])
		segtree[cur]=-1;
	else
		segtree[cur]=segtree[lc];
}

int main()
{
	fastread;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		arr[i]=i;
	build(1,1,n);
	int t,l,r,x;
	while(m--){
		cin>>t;
		if(t==2){
			cin>>l>>r;
			cout<<query(1,1,n,l,r)<<'\n';
		}else{
			cin>>l>>r>>x;
			update1(1,1,n,l,r,x);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define x first
#define y second
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI (atan(1)*4)
#define mp make_pair
using namespace std;
const int maxn=1e5+7,lim=4*maxn;

ll lazy[lim],segtree[lim],arr[maxn],val[lim],n,m;
void pushlazy(int cur,int lc,int rc,int l,int mid,int r){
	lazy[lc]+=lazy[cur];
	lazy[rc]+=lazy[cur];
	val[lc]=val[lc]+(mid-l+1)*lazy[cur];
	val[rc]=val[rc]+(r-mid)*lazy[cur];
	lazy[cur]=0;
}

void update2(int cur,int l,int r,int ql,int qr,ll key){
	if(l>qr || r<ql)
		return;
	if(l>=ql && r<=qr){
		val[cur]=val[cur]+(r-l+1)*key;
		lazy[cur]+=key;
		return;
	}
	int lc=2*cur,rc=lc+1,mid=(l+r)/2;
	if(lazy[cur]!=0)
		pushlazy(cur,lc,rc,l,mid,r);
	update2(lc,l,mid,ql,qr,key);
	update2(rc,mid+1,r,ql,qr,key);
	val[cur]=val[lc]+val[rc];
}

ll query(int cur,int l,int r,int ql,int qr){
	if(l>qr || r<ql)
		return 0LL;
	if(l>=ql && r<=qr){
		return val[cur];
	}
	int lc=2*cur,rc=lc+1,mid=(l+r)/2;
	if(lazy[cur]!=0)
		pushlazy(cur,lc,rc,l,mid,r);
	return (query(lc,l,mid,ql,qr)+query(rc,mid+1,r,ql,qr));
}

void build(int cur,int l,int r){
	if(l==r){
		segtree[cur]=arr[l];
		return;
	}
	int lc=2*cur,rc=lc+1,mid=(l+r)/2;
	build(lc,l,mid);
	build(rc,mid+1,r);
	if(segtree[lc]==-1 || segtree[rc]==-1 || segtree[lc]!=segtree[rc])
		segtree[cur]=-1;
	else
		segtree[cur]=segtree[lc];
}

void update1(int cur,int l,int r,int ql,int qr,ll key){
	if(l>qr || r<ql)
		return;
	if(l>=ql && r<=qr && segtree[cur]!=-1){
		update2(1,1,n,l,r,abs(key-segtree[cur]));
		segtree[cur]=key;
		return;
	}
	int lc=2*cur,rc=lc+1,mid=(l+r)/2;
	update1(lc,l,mid,ql,qr,key);
	update1(rc,mid+1,r,ql,qr,key);
	if(segtree[lc]==-1 || segtree[rc]==-1 || segtree[lc]!=segtree[rc])
		segtree[cur]=-1;
	else
		segtree[cur]=segtree[lc];
}

int main()
{
	fastread;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		arr[i]=i;
	build(1,1,n);
	int t,l,r,x;
	while(m--){
		cin>>t;
		if(t==2){
			cin>>l>>r;
			cout<<query(1,1,n,l,r)<<'\n';
		}else{
			cin>>l>>r>>x;
			update1(1,1,n,l,r,x);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define x first
#define y second
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI (atan(1)*4)
#define mp make_pair
using namespace std;
const int maxn=1e5+7,lim=4*maxn;

ll lazy[lim],segtree[lim],arr[maxn],val[lim],n,m,chg[lim];
void pushlazy(int cur,int lc,int rc,int l,int mid,int r){
	lazy[lc]+=lazy[cur];
	lazy[rc]+=lazy[cur];
	val[lc]=val[lc]+(mid-l+1)*lazy[cur];
	val[rc]=val[rc]+(r-mid)*lazy[cur];
	lazy[cur]=0;
}

void update2(int cur,int l,int r,int ql,int qr,ll key){
	if(l>qr || r<ql)
		return;
	if(l>=ql && r<=qr){
		val[cur]=val[cur]+(r-l+1)*key;
		lazy[cur]+=key;
		return;
	}
	int lc=2*cur,rc=lc+1,mid=(l+r)/2;
	if(lazy[cur]!=0)
		pushlazy(cur,lc,rc,l,mid,r);
	update2(lc,l,mid,ql,qr,key);
	update2(rc,mid+1,r,ql,qr,key);
	val[cur]=val[lc]+val[rc];
}

ll query(int cur,int l,int r,int ql,int qr){
	if(l>qr || r<ql)
		return 0LL;
	if(l>=ql && r<=qr){
		return val[cur];
	}
	int lc=2*cur,rc=lc+1,mid=(l+r)/2;
	if(lazy[cur]!=0)
		pushlazy(cur,lc,rc,l,mid,r);
	return (query(lc,l,mid,ql,qr)+query(rc,mid+1,r,ql,qr));
}

void build(int cur,int l,int r){
	if(l==r){
		segtree[cur]=arr[l];
		return;
	}
	int lc=2*cur,rc=lc+1,mid=(l+r)/2;
	build(lc,l,mid);
	build(rc,mid+1,r);
	if(segtree[lc]==-1 || segtree[rc]==-1 || segtree[lc]!=segtree[rc])
		segtree[cur]=-1;
	else
		segtree[cur]=segtree[lc];
}

void update1(int cur,int l,int r,int ql,int qr,ll key){
	if(l>qr || r<ql)
		return;
	if(l>=ql && r<=qr && segtree[cur]!=-1){
		ll temp;
		if(key>=segtree[cur])
			temp=key-segtree[cur];
		else
			temp=segtree[cur]-key;
		update2(1,1,n,l,r,temp);
		segtree[cur]=key;
		chg[cur]=key;
		return;
	}
	int lc=2*cur,rc=lc+1,mid=(l+r)/2;
	if(chg[cur]!=0){
		segtree[lc]=chg[cur];
		segtree[rc]=chg[cur];
		chg[lc]=chg[cur];
		chg[rc]=chg[cur];
		chg[cur]=0;
	}
	update1(lc,l,mid,ql,qr,key);
	update1(rc,mid+1,r,ql,qr,key);
	if(segtree[lc]==-1 || segtree[rc]==-1 || segtree[lc]!=segtree[rc])
		segtree[cur]=-1;
	else
		segtree[cur]=segtree[lc];
}

int main()
{
	fastread;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		arr[i]=i;
	build(1,1,n);
	ll t,l,r,x;
	while(m--){
		cin>>t;
		if(t==2){
			cin>>l>>r;
			cout<<query(1,1,n,l,r)<<'\n';
		}else{
			cin>>l>>r>>x;
			update1(1,1,n,l,r,x);
			// cout<<"check"<<query(1,1,n,1,n)<<'\n';
		}
	}
	return 0;
}


/*  ***  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 ) ;
				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 ] = 1 ;
			}
			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 } ;
	}
	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' ;
		}
	}
}


/*  ***  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 ++ } ;
				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 ] = 1 ;
			}
			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' ;
		}
	}
}