#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx") 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define mp make_pair
#define pb push_back
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define j0 j5743892
#define j1 j542893
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
                         
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;                                                                    
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> _tree;

template<class T> T abs(T x) { re x > 0 ? x : -x; }
template<class T> T gcd(T a, T b) { re a ? gcd (b % a, a) : b; }
template<class T> T sqr(T a) { re a * a; }
template<class T> T sgn(T a) { re a > 0 ? 1 : (a < 0 ? -1 : 0); }

#define filename ""
const double pi = acos(-1.);
const int N = 2e5 + 10;
const int inf = 1e9 + 10;
const int mod = 1e9 + 7;
          
int a[100001];
double x;
int n, m;

int main()
{
	int l, r, q, ans;
	scanf("%d%d",&n,&m);
	for(int i = 0; i < n; ++i)
		scanf("%d", a + i);
	for(int i = 0; i < m; i++){	
		scanf("%d%d%d%f", &q, &l, &r, &x);
		if(q == 1)
			for(int j = l - 1; j < r; j++)
				a[j] -= (a[j] > x ? x : 0);
		else{
			ans = 0;
			for(int j = l - 1; j < r; j++)
				 a[j]== x ? ++ans : 0;
			printf("%d\n",ans);
			}
	}
}