#define __AVX__ 1
#define __AVX2__ 1
#define __SSE__ 1
#define __SSE2__ 1
#define __SSE2_MATH__ 1
#define __SSE3__ 1
#define __SSE4_1__ 1
#define __SSE4_2__ 1
#define __SSE_MATH__ 1
#define __SSSE3__ 1

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")

#include <immintrin.h>
#include <emmintrin.h>
#include <bits/stdc++.h>
using namespace std;
// Using Fread to make it run faster

const int MAX_SIZE = 1 << 15;
char *l, *r, buf[ MAX_SIZE ];
inline int gc() {
    if( l == r )
        if( l == ( r = ( l = buf ) + fread( buf, 1, MAX_SIZE, stdin ) ) ) return -1;
    return *l++; 
}
inline void read( int &x ) {
    char c = gc();
    x = 0;
    for(; c < 48 || c > 57; c = gc() );
    for( x = 0; c > 47 && c < 58; c = gc() )
        x = ( x << 3 ) + ( x << 1 ) + ( c ^ 48 );
    return;
}

#define I_int int 
char F[ 200 ] ;
inline void write( I_int x ) {
    I_int tmp = x > 0 ? x : -x ;
    if( x < 0 ) putchar( '-' ) ;
    int cnt = 0 ;
        while( tmp > 0 ) {
            F[ cnt ++ ] = tmp % 10 + '0' ;
            tmp /= 10 ;
        }
        while( cnt > 0 ) 
	   	putchar( F[ -- cnt ] ) ;
	putchar('\n');
}
#undef I_int

//Ending
__m256i block[100000];
int *a;
void sub(int l, int r, int val) {
	__m256i chk = _mm256_set1_epi32(val);
	while((l & 7) && l < r)
		if(a[l] > val)
			a[l++] -= val;
	if(l == r)
		return;
	while(r & 7)
		if(a[r] > val)
			a[--r] -= val;
	if(l == r)
		return;
	for(l >>= 3, r >>= 3; l < r; ++l)
		block[l] = _mm256_sub_epi32(block[l], _mm256_and_si256(_mm256_cmpgt_epi32(block[l], chk), chk));
}
int ask(int l, int r, int val) {
	__m256i ans = _mm256_set1_epi32(0);
	__m256i chk = _mm256_set1_epi32(val);
	__m256i one = _mm256_set1_epi32(1);
	int cnt = 0;
	while((l & 7) && l < r)
		cnt += a[l++] == val;
	if(l == r)
		return cnt;
	while(r & 7)
		cnt += a[--r] == val;
	if(l == r)
		return cnt;
	for(l >>= 3, r >>= 3; l < r; l++)
		ans = _mm256_add_epi32(ans, _mm256_and_si256(_mm256_cmpeq_epi32(block[l], chk), one));
	for(int i = 0; i < 8; i++)
		cnt += ((int *) & ans)[i];
	return cnt;
}
int main() {
	a = (int *) & block;
	int n, m;
	read(n);
	read(m);
	for(int i = 0; i < n; i++)
		read(a[i]);
	while(m--) {
		int opt, l, r, x;
		read(opt);
		read(l);
		read(r);
		read(x);
		l--;
		if(opt == 1) {
			sub(l, r, x);
		} else {
			write(ask(l, r, x));
		}
	}
}