多半没人调就是了
#include<bits/stdc++.h>
using namespace std;
namespace fast_IO {
#define IOSIZE 100000
char ibuf[IOSIZE], obuf[IOSIZE], *p1 = ibuf, *p2 = ibuf, *p3 = obuf;
#define getchar() ((p1==p2)and(p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin),p1==p2)?(EOF):(*p1++))
#define putchar(x) ((p3==obuf+IOSIZE)&&(fwrite(obuf,p3-obuf,1,stdout),p3=obuf),*p3++=x)
#define isdigit(ch) (ch>47&&ch<58)
#define isspace(ch) (ch<33)
template<typename T> inline T read() { T s = 0; int w = 1; char ch; while (ch = getchar(), !isdigit(ch) and (ch != EOF)) if (ch == '-') w = -1; if (ch == EOF) return false; while (isdigit(ch)) s = s * 10 + ch - 48, ch = getchar(); return s * w; }
template<typename T> inline bool read(T &s) { s = 0; int w = 1; char ch; while (ch = getchar(), !isdigit(ch) and (ch != EOF)) if (ch == '-') w = -1; if (ch == EOF) return false; while (isdigit(ch)) s = s * 10 + ch - 48, ch = getchar(); return s *= w, true; }
template<typename T> inline void print(T x) { if (x < 0) putchar('-'), x = -x; if (x > 9) print(x / 10); putchar(x % 10 + 48); }
inline bool read(char &s) { while (s = getchar(), isspace(s)); return true; }
inline bool read(char *s) { char ch; while (ch = getchar(), isspace(ch)); if (ch == EOF) return false; while (!isspace(ch)) *s++ = ch, ch = getchar(); *s = '\000'; return true; }
inline void print(char x) { putchar(x); }
inline void print(char *x) { while (*x) putchar(*x++); }
inline void print(const char *x) { for (int i = 0; x[i]; i++) putchar(x[i]); }
inline bool read(std::string& s) { s = ""; char ch; while (ch = getchar(), isspace(ch)); if (ch == EOF) return false; while (!isspace(ch)) s += ch, ch = getchar(); return true; }
inline void print(std::string x) { for (int i = 0, n = x.size(); i < n; i++) putchar(x[i]); }
inline bool read(bool &b) { char ch; while(ch=getchar(), isspace(ch)); b=ch^48; return true; }
inline void print(bool b) { putchar(b+48); }
template<typename T, typename... T1> inline int read(T& a, T1&... other) { return read(a) + read(other...); }
template<typename T, typename... T1> inline void print(T a, T1... other) { print(a), print(other...); }
struct Fast_IO { ~Fast_IO() { fwrite(obuf, p3 - obuf, 1, stdout); } } io;
template<typename T> Fast_IO& operator >> (Fast_IO &io, T &b) { return read(b), io; }
template<typename T> Fast_IO& operator << (Fast_IO &io, T b) { return print(b), io; }
#define cout io
#define cin io
#define endl '\n'
} using namespace fast_IO;
const int N=1e6+10;
int n,m,e[N],pos[N],bll[N],blr[N],l[N],r[N],x[N],op[N],ans[N],loc;
string s;
struct Block
{
int l,r,fa[N],siz[N],root[N],val[N],maxx,add;
inline int find(int u) {return u==fa[u]?u:fa[u]=find(fa[u]);}
inline void unit(int u,int v)
{
if (root[v]) fa[root[u]]=root[v];
else root[v]=root[u],val[root[v]]=v;
siz[v]+=siz[u];
root[u]=siz[u]=0;
return ;
}
inline void Break()
{
for (register int i=l;i<=r;i++)
{
e[i]=val[find(i)];
root[e[i]]=0,siz[e[i]]=0;
e[i]-=add;
}
for (register int i=l;i<=r;i++) fa[i]=0;
add=0;
return ;
}
inline void rebuild()
{
maxx=0;
for (register int i=l;i<=r;i++)
{
if (!root[e[i]])
{
root[e[i]]=i;
fa[i]=i;
val[i]=e[i];
}
else fa[i]=root[e[i]];
siz[e[i]]++;
maxx=max(maxx,e[i]);
}
return ;
}
inline void update_all(int w)
{
if (maxx-add>=2*w)
{
for (register int i=add+1;i<=add+w;i++) if (root[i]) unit(i,i+w);
add+=w;
}
else
{
for (register int i=maxx;i>add+w;i--) if (root[i]) unit(i,i-w);
maxx=min(maxx,add+w);
}
return ;
}
inline int query_all(int u) {return (u+add>5e5)?0:siz[u+add];}
inline void update_part(int l,int r,int w)
{
Break();
for (register int i=l;i<=r;i++) if (e[i]>w) e[i]-=w;
rebuild();
return ;
}
inline int query_part(int l,int r,int w)
{
register int sum=0;
for (register int i=l;i<=r;i++) if (val[find(i)]-add==w) sum++;
return sum;
}
}blo;
inline void init()
{
for (register int i=1;i<=n;i++) pos[i]=(i-1)/loc+1;
for (register int i=1;i<=pos[n];i++) bll[i]=(i-1)*loc+1,blr[i]=i*loc;
blr[pos[n]]=n;
return ;
}
signed main()
{
cin>>n>>m;loc=pow(n,2.0/3.0);
for (register int i=1;i<=n;i++) cin>>e[i];
for (register int i=1;i<=m;i++) cin>>op[i]>>l[i]>>r[i]>>x[i];
init();
for (register int i=1;i<=pos[n];i++)
{
blo.l=bll[i],blo.r=blr[i];blo.rebuild();
for (register int j=1;j<=m;j++)
{
if (op[j]==1)
{
if (l[j]<=blo.l and r[j]>=blo.r) blo.update_all(x[j]);
else blo.update_part(max(l[j],blo.l),min(r[j],blo.r),x[j]);
}
else
{
if (l[j]<=blo.l and r[j]>=blo.r) ans[j]+=blo.query_all(x[j]);
else ans[j]+=blo.query_part(max(l[j],blo.l),min(r[j],blo.r),x[j]);
}
}
blo.Break();
}
for (register int i=1;i<=m;i++) if (op[i]==2) cout<<ans[i]<<endl;
return (0-0);
}