/////////////////////// All Is Well /////////////////////////
#include <bits/stdc++.h>
#define FOR(i, s, e) for(int i=s; i<e; i++)
#define loop(i, n) for(int i=0; i<n; i++)
#define CIN ios_base::sync_with_stdio(0); cin.tie(0)
#define getint(n) scanf("%d", &n)
#define pb(a) push_back(a)
#define ll long long int
#define ull unsigned long long int
#define dd double
#define SZ(a) int(a.size())
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define mem(a, v) memset(a, v, sizeof(a))
#define all(v) v.begin(), v.end()
#define pi acos(-1.0)
#define pf printf
#define sf scanf
#define mp make_pair
#define paii pair<int, int>
#define padd pair<dd, dd>
#define pall pair<ll, ll>
#define fr first
#define sc second
#define CASE(n) printf("Case %d: ",++n)
#define CASE_COUT cout<<"Case "<<++cas<<": "
#define inf 1000000000
#define EPS 1e-9
using namespace std;
//8 way moves
//int fx[]={0,0,1,-1,1,1,-1,-1};
//int fy[]={1,-1,0,0,1,-1,1,-1};
//knight moves
//int fx[]={-2,-2,-1,-1,1,1,2,2};
//int fy[]={-1,1,-2,2,-2,2,-1,1};
//Bit operation
int SET(int n,int pos)
{
return n=n | (1<<pos);
}
int RESET(int n,int pos)
{
return n=n & ~(1<<pos);
}
int CHECK(int n,int pos)
{
return (bool) (n & (1<<pos));
}
int bigMod(int n,int power,int MOD)
{
if(power==0)
return 1;
if(power%2==0)
{
int ret=bigMod(n,power/2,MOD);
return ((ret%MOD)*(ret%MOD))%MOD;
}
else return ((n%MOD)*(bigMod(n,power-1,MOD)%MOD))%MOD;
}
int modInverse(int n,int MOD)
{
return bigMod(n,MOD-2,MOD);
}
int POW(int x, int y)
{
int res= 1;
for ( ; y ; )
{
if ( (y&1) )
{
res*= x;
}
x*=x;
y>>=1;
}
return res;
}
int inverse(int x)
{
dd p=((dd)1.0)/x;
return (p)+EPS;
}
int gcd(int a, int b)
{
while(b) b^=a^=b^=a%=b;
return a;
}
int nC2(int n)
{
return n*(n-1)/2;
}
int MOD(int n,int mod)
{
if(n>=0)
return n%mod;
else if(-n==mod)
return 0;
else
return mod+(n%mod);
}
const int mx=100005;
int data[mx];
vector< paii >tree[350];
int getid(int i,int blck)
{
return i/blck;
}
void init(int blck,int n)
{
int cnt=0;
for(int i=0; i<=blck; i++)
{
int p=0;
for(int j=0; j<blck; j++)
{
if(cnt>=n)
break;
tree[i].pb(mp(data[cnt],cnt));
cnt++;
p++;
}
if(p)
sort(all(tree[i]));
}
}
void update(int ind,int x,int blck)
{
int blckid=getid(ind,blck);
for(int i=0; i<tree[blckid].size(); i++)
{
if(tree[blckid][i].sc==ind)
{
tree[blckid][i].fr=x;
break;
}
}
sort(all(tree[blckid]));
}
int BS(int left,int right,int x,int blckid)
{
int mid=(left+right)/2;
int ans=right;
while(left<=right)
{
if(tree[blckid][mid].fr<x)
{
left=mid+1;
}
else
{
right=mid-1;
ans=mid;
}
}
return ans;
}
int query(int left,int right,int x,int blck)
{
int leftid=getid(left,blck);
int rightid=getid(right,blck);
if(leftid==rightid)
{
int cnt=0;
for(int i=0; i<tree[leftid].size(); i++)
{
if(tree[leftid][i].sc>=left && tree[rightid][i].sc<=right && tree[leftid][i].fr<=x)
cnt++;
}
return cnt;
}
if(leftid+1==rightid)
{
int cnt=0;
for(int i=0; i<tree[leftid].size(); i++)
{
if(tree[leftid][i].sc>=left && tree[leftid][i].fr<=x)
cnt++;
}
for(int i=0; i<tree[rightid].size(); i++)
{
if(tree[rightid][i].sc<=right && tree[rightid][i].fr<=x)
cnt++;
}
return cnt;
}
int cnt=0;
for(int i=0; i<tree[leftid].size(); i++)
{
if(tree[leftid][i].sc>=left && tree[leftid][i].fr<=x)
cnt++;
}
for(int i=leftid+1;i<rightid;i++)
{
int pp=BS(0,blck-1,x,i);
if(tree[i][pp].fr==x || pp==blck-1)
pp++;
cnt+=pp;
}
for(int i=0; i<tree[rightid].size(); i++)
{
if( tree[rightid][i].sc<=right && tree[rightid][i].fr<=x)
cnt++;
}
return cnt;
}
int main()
{
int t,cas=0;
int n,q;
sf("%d %d",&n,&q);
int blck=sqrt(n);
loop(i,n)
{
getint(data[i]);
}
init(blck,n);
// for(int i=0;i<blck;i++)
// {
// for(int j=0;j<tree[i].size();j++)
// cout<<tree[i][j].fr<<" ";
// cout<<endl;
// }
while(q--)
{
getchar();
char cc;
int p,qq,x;
sf("%c",&cc);
if(cc=='M')
{
sf("%d %d",&p,&x);
update(p-1,x,blck);
}
else
{
sf("%d %d %d",&p,&qq,&x);
pf("%d\n",query(p-1,qq-1,x,blck));
}
}
return 0;
}
Ly8vLy8vLy8vLy8vLy8vLy8vLy8vLy8gQWxsIElzIFdlbGwgLy8vLy8vLy8vLy8vLy8vLy8vLy8vLy8vLwoKI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgojZGVmaW5lIEZPUihpLCBzLCBlKSBmb3IoaW50IGk9czsgaTxlOyBpKyspCiNkZWZpbmUgbG9vcChpLCBuKSBmb3IoaW50IGk9MDsgaTxuOyBpKyspCiNkZWZpbmUgQ0lOICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsgY2luLnRpZSgwKQojZGVmaW5lIGdldGludChuKSBzY2FuZigiJWQiLCAmbikKI2RlZmluZSBwYihhKSBwdXNoX2JhY2soYSkKI2RlZmluZSBsbCBsb25nIGxvbmcgaW50CiNkZWZpbmUgdWxsIHVuc2lnbmVkIGxvbmcgbG9uZyBpbnQKI2RlZmluZSBkZCBkb3VibGUKI2RlZmluZSBTWihhKSBpbnQoYS5zaXplKCkpCiNkZWZpbmUgcmVhZCgpIGZyZW9wZW4oImlucHV0LnR4dCIsICJyIiwgc3RkaW4pCiNkZWZpbmUgd3JpdGUoKSBmcmVvcGVuKCJvdXRwdXQudHh0IiwgInciLCBzdGRvdXQpCiNkZWZpbmUgbWVtKGEsIHYpIG1lbXNldChhLCB2LCBzaXplb2YoYSkpCiNkZWZpbmUgYWxsKHYpIHYuYmVnaW4oKSwgdi5lbmQoKQojZGVmaW5lIHBpIGFjb3MoLTEuMCkKI2Rl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ChyZXQlTU9EKSoocmV0JU1PRCkpJU1PRDsKICAgIH0KICAgIGVsc2UgcmV0dXJuICgobiVNT0QpKihiaWdNb2Qobixwb3dlci0xLE1PRCklTU9EKSklTU9EOwp9CgppbnQgbW9kSW52ZXJzZShpbnQgbixpbnQgTU9EKQp7CiAgICByZXR1cm4gYmlnTW9kKG4sTU9ELTIsTU9EKTsKfQoKaW50IFBPVyhpbnQgeCwgaW50IHkpCnsKICAgIGludCByZXM9IDE7CiAgICBmb3IgKCA7IHkgOyApCiAgICB7CiAgICAgICAgaWYgKCAoeSYxKSApCiAgICAgICAgewogICAgICAgICAgICByZXMqPSB4OwogICAgICAgIH0KICAgICAgICB4Kj14OwogICAgICAgIHk+Pj0xOwogICAgfQogICAgcmV0dXJuIHJlczsKfQoKaW50IGludmVyc2UoaW50IHgpCnsKICAgIGRkIHA9KChkZCkxLjApL3g7CiAgICByZXR1cm4gKHApK0VQUzsKfQoKaW50IGdjZChpbnQgYSwgaW50IGIpCnsKICAgIHdoaWxlKGIpIGJePWFePWJePWElPWI7CiAgICByZXR1cm4gYTsKfQoKaW50IG5DMihpbnQgbikKewogICAgcmV0dXJuIG4qKG4tMSkvMjsKfQoKaW50IE1PRChpbnQgbixpbnQgbW9kKQp7CiAgICBpZihuPj0wKQogICAgICAgIHJldHVybiBuJW1vZDsKICAgIGVsc2UgaWYoLW49PW1vZCkKICAgICAgICByZXR1cm4gMDsKICAgIGVsc2UKICAgICAgICByZXR1cm4gbW9kKyhuJW1vZCk7Cn0KCmNvbnN0IGludCBteD0xMDAwMDU7CgppbnQgZGF0YVtteF07Cgp2ZWN0b3I8IHBhaWkgPnRyZWVbMzUwXTsKCgppbnQgZ2V0aWQoaW50IGksaW50IGJsY2spCnsKICAgIHJldHVybiBpL2JsY2s7Cn0KCnZvaWQgaW5pdChpbnQgYmxjayxpbnQgbikKewogICAgaW50IGNudD0wOwogICAgZm9yKGludCBpPTA7IGk8PWJsY2s7IGkrKykKICAgIHsKICAgICAgICBpbnQgcD0wOwogICAgICAgIGZvcihpbnQgaj0wOyBqPGJsY2s7IGorKykKICAgICAgICB7CiAgICAgICAgICAgIGlmKGNudD49bikKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB0cmVlW2ldLnBiKG1wKGRhdGFbY250XSxjbnQpKTsKICAgICAgICAgICAgY250Kys7CiAgICAgICAgICAgIHArKzsKICAgICAgICB9CiAgICAgICAgaWYocCkKICAgICAgICAgICAgc29ydChhbGwodHJlZVtpXSkpOwogICAgfQp9Cgp2b2lkIHVwZGF0ZShpbnQgaW5kLGludCB4LGludCBibGNrKQp7CiAgICBpbnQgYmxja2lkPWdldGlkKGluZCxibGNrKTsKICAgIGZvcihpbnQgaT0wOyBpPHRyZWVbYmxja2lkXS5zaXplKCk7IGkrKykKICAgIHsKICAgICAgICBpZih0cmVlW2JsY2tpZF1baV0uc2M9PWluZCkKICAgICAgICB7CiAgICAgICAgICAgIHRyZWVbYmxja2lkXVtpXS5mcj14OwogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICB9CiAgICBzb3J0KGFsbCh0cmVlW2JsY2tpZF0pKTsKfQoKaW50IEJTKGludCBsZWZ0LGludCByaWdodCxpbnQgeCxpbnQgYmxja2lkKQp7CiAgICBpbnQgbWlkPShsZWZ0K3JpZ2h0KS8yOwogICAgaW50IGFucz1yaWdodDsKICAgIHdoaWxlKGxlZnQ8PXJpZ2h0KQogICAgewogICAgICAgIGlmKHRyZWVbYmxja2lkXVttaWRdLmZyPHgpCiAgICAgICAgewogICAgICAgICAgICBsZWZ0PW1pZCsxOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICByaWdodD1taWQtMTsKICAgICAgICAgICAgYW5zPW1pZDsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gYW5zOwp9CgppbnQgcXVlcnkoaW50IGxlZnQsaW50IHJpZ2h0LGludCB4LGludCBibGNrKQp7CiAgICBpbnQgbGVmdGlkPWdldGlkKGxlZnQsYmxjayk7CiAgICBpbnQgcmlnaHRpZD1nZXRpZChyaWdodCxibGNrKTsKICAgIGlmKGxlZnRpZD09cmlnaHRpZCkKICAgIHsKICAgICAgICBpbnQgY250PTA7CiAgICAgICAgZm9yKGludCBpPTA7IGk8dHJlZVtsZWZ0aWRdLnNpemUoKTsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgaWYodHJlZVtsZWZ0aWRdW2ldLnNjPj1sZWZ0ICYmIHRyZWVbcmlnaHRpZF1baV0uc2M8PXJpZ2h0ICYmIHRyZWVbbGVmdGlkXVtpXS5mcjw9eCkKICAgICAgICAgICAgICAgIGNudCsrOwogICAgICAgIH0KICAgICAgICByZXR1cm4gY250OwogICAgfQogICAgaWYobGVmdGlkKzE9PXJpZ2h0aWQpCiAgICB7CiAgICAgICAgaW50IGNudD0wOwogICAgICAgIGZvcihpbnQgaT0wOyBpPHRyZWVbbGVmdGlkXS5zaXplKCk7IGkrKykKICAgICAgICB7CiAgICAgICAgICAgIGlmKHRyZWVbbGVmdGlkXVtpXS5zYz49bGVmdCAmJiAgdHJlZVtsZWZ0aWRdW2ldLmZyPD14KQogICAgICAgICAgICAgICAgY250Kys7CiAgICAgICAgfQogICAgICAgIGZvcihpbnQgaT0wOyBpPHRyZWVbcmlnaHRpZF0uc2l6ZSgpOyBpKyspCiAgICAgICAgewogICAgICAgICAgICBpZih0cmVlW3JpZ2h0aWRdW2ldLnNjPD1yaWdodCAmJiB0cmVlW3JpZ2h0aWRdW2ldLmZyPD14KQogICAgICAgICAgICAgICAgY250Kys7CiAgICAgICAgfQogICAgICAgIHJldHVybiBjbnQ7CiAgICB9CiAgICBpbnQgY250PTA7CiAgICBmb3IoaW50IGk9MDsgaTx0cmVlW2xlZnRpZF0uc2l6ZSgpOyBpKyspCiAgICB7CiAgICAgICAgaWYodHJlZVtsZWZ0aWRdW2ldLnNjPj1sZWZ0ICYmIHRyZWVbbGVmdGlkXVtpXS5mcjw9eCkKICAgICAgICAgICAgY250Kys7CiAgICB9CgogICAgZm9yKGludCBpPWxlZnRpZCsxO2k8cmlnaHRpZDtpKyspCiAgICB7CiAgICAgICAgaW50IHBwPUJTKDAsYmxjay0xLHgsaSk7CiAgICAgICAgaWYodHJlZVtpXVtwcF0uZnI9PXggfHwgcHA9PWJsY2stMSkKICAgICAgICAgICAgcHArKzsKICAgICAgICBjbnQrPXBwOwogICAgfQoKICAgIGZvcihpbnQgaT0wOyBpPHRyZWVbcmlnaHRpZF0uc2l6ZSgpOyBpKyspCiAgICB7CiAgICAgICAgaWYoIHRyZWVbcmlnaHRpZF1baV0uc2M8PXJpZ2h0ICYmIHRyZWVbcmlnaHRpZF1baV0uZnI8PXgpCiAgICAgICAgICAgIGNudCsrOwogICAgfQogICAgcmV0dXJuIGNudDsKfQoKaW50IG1haW4oKQp7CiAgICBpbnQgdCxjYXM9MDsKICAgIGludCBuLHE7CiAgICBzZigiJWQgJWQiLCZuLCZxKTsKICAgIGludCBibGNrPXNxcnQobik7CiAgICBsb29wKGksbikKICAgIHsKICAgICAgICBnZXRpbnQoZGF0YVtpXSk7CiAgICB9CgogICAgaW5pdChibGNrLG4pOwovLyAgICBmb3IoaW50IGk9MDtpPGJsY2s7aSsrKQovLyAgICB7Ci8vICAgICAgICBmb3IoaW50IGo9MDtqPHRyZWVbaV0uc2l6ZSgpO2orKykKLy8gICAgICAgICAgICBjb3V0PDx0cmVlW2ldW2pdLmZyPDwiICI7Ci8vICAgICAgICBjb3V0PDxlbmRsOwovLyAgICB9CiAgICB3aGlsZShxLS0pCiAgICB7CiAgICAgICAgZ2V0Y2hhcigpOwogICAgICAgIGNoYXIgY2M7CiAgICAgICAgaW50IHAscXEseDsKICAgICAgICBzZigiJWMiLCZjYyk7CiAgICAgICAgaWYoY2M9PSdNJykKICAgICAgICB7CiAgICAgICAgICAgIHNmKCIlZCAlZCIsJnAsJngpOwogICAgICAgICAgICB1cGRhdGUocC0xLHgsYmxjayk7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIHNmKCIlZCAlZCAlZCIsJnAsJnFxLCZ4KTsKICAgICAgICAgICAgcGYoIiVkXG4iLHF1ZXJ5KHAtMSxxcS0xLHgsYmxjaykpOwogICAgICAgIH0KICAgIH0KCiAgICByZXR1cm4gIDA7Cgp9Cg==