#include<bits/stdc++.h>
#define LL long long
#define N 100005
using namespace std;
int n,m,T,M,bl,a[N],b[N],s[320][N],f[320][N],tag[320],Max[320],L[320],R[320];
inline int gf(int x,int y){return f[x][y]==y?y:f[x][y]=gf(x,f[x][y]);}
struct FastIO{
	static const int S=1048576;
	char buf[S],*L,*R;int stk[20],Top;~FastIO(){clear();}
	inline char nc(){return L==R&&(R=(L=buf)+fread(buf,1,S,stdin),L==R)?EOF:*L++;}inline void clear(){fwrite(buf,1,Top,stdout);Top=0;}
	inline void pc(char ch){Top==S&&(clear(),0);buf[Top++]=ch;}inline void endl(){pc('\n');}
	FastIO& operator >> (char&ch){while(ch=nc(),ch==' '||ch=='\n');return *this;}
	template<typename T>FastIO& operator >> (T&ret){
		ret=0;int f=1;char ch=nc();while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=nc();}
		while(ch>='0'&&ch<='9'){ret=ret*10+ch-'0';ch=nc();}ret*=f;return *this;
	}
	FastIO& operator >> (char* s){int Len=0;char ch=nc();while(ch!='\n'){*(s+Len)=ch;Len++;ch=nc();}}
	template<typename T>FastIO& operator << (T x){
		if(x<0){pc('-');x=-x;}do{stk[++stk[0]]=x%10;x/=10;}while(x);
		while(stk[0]) pc('0'+stk[stk[0]--]);return *this;
	}
	FastIO& operator << (char ch){pc(ch);return *this;}
	FastIO& operator << (string str){int Len=str.size()-1;for(stk[0]=0;Len>=0;Len--) stk[++stk[0]]=str[Len];while(stk[0]) pc(stk[stk[0]--]);return *this;}
}fin,fout;
int main(){
//	freopen("data.in","r",stdin);
	fin>>n>>m,bl=sqrt(n);for(register int i=1;i<=n;i++) fin>>a[i],M=max(M,a[i]);for(register int i=1;i<=n;i++)
	{int B=(i-1)/bl+1;b[i]=B,s[B][a[i]]++;if(!L[B]) L[B]=i;R[B]=i;Max[B]=max(Max[B],a[i]);}T=(n-1)/bl+1;
	for(register int i=1;i<=T;i++) for(register int j=1;j<=M;j++) f[i][j]=j;for(register int i=1;i<=m;i++){
		int op,l,r,x;fin>>op>>l>>r>>x;if(op==1){
			int lb=b[l],rb=b[r];if(lb==rb){
				if(Max[lb]+tag[lb]<=x) continue;for(register int j=l;j<=r;j++) a[j]=gf(lb,a[j])-tag[lb],(a[j]>x)&&(a[j]-=x),a[j]+=tag[lb];
				for(register int j=L[lb];j<l;j++) a[j]=gf(lb,a[j]);for(register int j=r+1;j<=R[lb];j++) a[j]=gf(lb,a[j]);
				Max[lb]=0;for(register int j=L[lb];j<=R[lb];j++) f[lb][a[j]]=0,Max[lb]=max(Max[lb],a[j]);
				for(register int j=L[lb];j<=R[lb];j++) if(!f[lb][a[j]]) f[lb][a[j]]=a[j],s[lb][a[j]]=1;else s[lb][a[j]]++;continue;
			}
			if(L[lb]!=l) lb++;if(R[rb]!=r) rb--;for(register int j=lb;j<=rb;j++){
				if(Max[j]+tag[j]<=x) continue;if(Max[j]-tag[j]>=2*x){for(register int k=1+tag[j];k<=x+tag[j];k++) f[j][k]=k+x,s[j][k+x]+=s[j][k],s[j][k]=0;tag[j]+=x;}else{
					for(register int k=x+1+tag[j];k<=Max[j];k++) f[j][k]=k-x,s[j][k-x]+=s[j][k],s[j][k]=0;
					Max[j]-=x;for(register int k=x+tag[j];k>Max[j];k--) if(s[j][k]){Max[j]=k;break;}
				}
			}
			if(L[lb]!=l){
				lb--;if(Max[lb]+tag[lb]<=x) continue;for(register int j=l;j<=R[lb];j++) a[j]=gf(lb,a[j])-tag[lb],(a[j]>x)&&(a[j]-=x),a[j]+=tag[lb];
				for(register int j=L[lb];j<l;j++) a[j]=gf(lb,a[j]);Max[lb]=0;for(register int j=L[lb];j<=R[lb];j++) f[lb][a[j]]=0,Max[lb]=max(Max[lb],a[j]);
				for(register int j=L[lb];j<=R[lb];j++) if(!f[lb][a[j]]) f[lb][a[j]]=a[j],s[lb][a[j]]=1;else s[lb][a[j]]++;
			}
			if(R[rb]!=r){
				rb++;if(Max[rb]+tag[rb]<=x) continue;for(register int j=L[rb];j<=r;j++) a[j]=gf(rb,a[j])-tag[rb],(a[j]>x)&&(a[j]-=x),a[j]+=tag[rb];
				for(register int j=r+1;j<=R[rb];j++) a[j]=gf(rb,a[j]);Max[rb]=0;for(register int j=L[rb];j<=R[rb];j++) f[rb][a[j]]=0,Max[rb]=max(Max[rb],a[j]);
				for(register int j=L[rb];j<=R[rb];j++) if(!f[rb][a[j]]) f[rb][a[j]]=a[j],s[rb][a[j]]=1;else s[rb][a[j]]++;
			}
		}
		else{
			int lb=b[l],rb=b[r],ans=0;if(lb==rb){for(register int j=l;j<=r;j++) if(gf(lb,a[j])-tag[lb]==x) ans++;fout<<ans<<'\n';continue;}
			if(L[lb]!=l) lb++;if(R[rb]!=r) rb--;for(register int j=lb;j<=rb;j++) ans+=s[j][x+tag[j]];
			if(L[lb]!=l){lb--;for(register int j=l;j<=R[lb];j++) if(gf(lb,a[j])-tag[lb]==x) ans++;}
			if(R[rb]!=r){rb++;for(register int j=L[rb];j<=r;j++) if(gf(rb,a[j])-tag[rb]==x) ans++;}fout<<ans<<'\n';
		}
	}
	return 0;
}