#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 0x7fffffff
#define faster ios::sync_with_stdio(0);cin.tie(0) inline ll read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} /********************************************************************/ const int maxn = +;
int n, m;
ll a[maxn], b[maxn];
int num, block;
ll minn[maxn], belong[maxn];
ll sum[maxn]; void makeblock(){
block = sqrt(n);
if(n%block) num = n/block+;
else num = n/block;
for(int i = ;i <= n;i++){
belong[i] = (i-)/block + ;
b[i] = a[i];
}
for(int i = ;i <= num;i++){
ll l = (i-)*block+, r = min(i*block, n);
for(int j = l;j <= r;j++){
b[j] = a[j];
}
sort(b+l, b+r+);
minn[i] = b[l];
sum[i] = ;
for(int j = l;j <= r;j++){
if(b[j] == minn[i])
sum[i]++;
else break;
}
}
return;
} //单点更新
void update(int x, int v){
a[x] = v;
int pos = belong[x];
ll l = (pos - )*block + ;
ll r = (pos*block, n);
for(ll i = l;i <= r;i++)
b[i] = a[i];
sort(b+l, b+r+);
minn[pos] = b[l];
sum[pos] = ;
for(int i = l;i <= r;i++){
if(b[i] == minn[pos])
sum[pos]++;
else break;
}
return;
} //区间查询
int ask(int l, int r){
ll ans = inf;
if(belong[l] == belong[r]){
for(int i = l;i <= r;i++){
ans = min(ans, a[i]);
}
}
else {
for(int i = l;i <= belong[l]*block;i++){
ans = min(ans, a[i]);
}
for(int i = belong[r-]*block+;i <= r;i++){
ans = min(ans, a[i]);
}
}
for(int i = belong[l]+;i < belong[r];i++){
ans = min(ans, minn[i]);
}
return ans;
} int ask1(int l, int r, int len){
ll ans = ;
if(belong[l] == belong[r]){
for(int i = l;i <= r;i++){
if(a[i] == len)
ans++;
}
}
else {
for(int i = l;i <= belong[l]*block;i++){
if(a[i] == len)
ans++;
}
for(int i = belong[r-]*block+;i <= r;i++){
if(a[i] == len)
ans++;
}
}
for(int i = belong[l]+;i < belong[r];i++){
if(minn[i] == len){
ans += sum[i];
}
}
return ans;
} int Find(int pos, int len){
if(minn[pos] < len)
return ;
ll l = (pos - )*block+;
ll r = min(pos*block, n);
int ans = ;
for(int i = l;i <= r;i++){
if(b[i] <= len)
ans++;
else break;
}
return ans;
} int deal(int l, int r, int len){
int ans = ;
if(belong[l] == belong[r]){
for(int i = l;i <= r;i++){
if(a[i] <= len) ans++;
}
}
else{
for(int i = l;i <= belong[l]*block;i++){
if(a[i] <= len) ans++;
}
for(int i = belong[r-]*block+;i <= r;i++){
if(a[i] <= len) ans++;
}
}
for(int i = belong[l]+;i < belong[r];i++){
ans += Find(i, len);
}
return ans;
} int main(){
n = read(); m = read();
for(int i = ;i <= n;i++){
a[i] = read();
}
makeblock();
while(m--){
int op, x, y, v;
op = read();
if(op == ){
x = read(); v = read();
update(x, v);
}
else if(op == ){
x = read(); y = read();
int tmp = ask(x, y);
int tmp1 = ask1(x, y, tmp);
printf("%d %d\n", tmp, tmp1);
}
else if(op == ){
x = read(); y = read(); v = read();
int tmp = deal(x, y, v);
printf("%d\n", tmp);
}
}
return ;
}