#include <bits/stdc++.h>
using namespace std;
#define bolt_io ios_base::sync_with_stdio(0), cin.tie(0)
const int N = 6e5 + 5;
int n, q, uc, n_, ic, st[4 * N], a[N], b[N];
vector<tuple<char, int, int>> vp;
map<int, int> mp;
void f1(int sti, int ll, int rr, int ix, int v)
{
if (ll == rr)
st[sti] += v;
else
{
int m = (ll + rr) >> 1;
if (ix <= m)
f1(2 * sti + 1, ll, m, ix, v);
else
f1(2 * sti + 2, m + 1, rr, ix, v);
st[sti] += v;
}
}
int f2(int sti, int ll, int rr, int lq, int rq)
{
if (rq < ll || rr < lq)
return 0;
else if (lq <= ll && rr <= rq)
return st[sti];
else
{
int m = (ll + rr) >> 1;
return f2(2 * sti + 1, ll, m, lq, rq) + f2(2 * sti + 2, m + 1, rr, lq, rq);
}
}
signed main()
{
bolt_io;
cin >> n >> q;
for (int i = 0; i < n; i++)
cin >> a[ic], ic++;
vp.resize(q);
for (int i = 0; i < q; i++)
{
char ch;
int x, y;
cin >> ch >> x >> y;
vp[i] = {ch, x, y};
if (ch == '!')
a[ic] = y, ic++;
else
a[ic] = x, a[ic + 1] = y, ic += 2;
}
for (int i = 0; i < n; i++)
b[i] = a[i];
sort(a, a + ic);
mp[a[0]] = 0;
for (int i = 1; i < ic; i++)
if (a[i] != a[i - 1])
mp[a[i]] = mp[a[i - 1]] + 1;
uc = mp.size();
n_ = 1 << (__lg(uc) + 1);
if ((uc & (uc - 1)) == 0)
n_ >>= 1;
for (int i = 0; i < n; i++)
f1(0, 0, n_ - 1, mp[b[i]], +1);
for (tuple<char, int, int> entry : vp)
{
if (get<0>(entry) == '!')
{
f1(0, 0, n_ - 1, mp[b[get<1>(entry)] - 1], -1);
b[get<1>(entry) - 1] = get<2>(entry);
f1(0, 0, n_ - 1, mp[b[get<1>(entry) - 1]], +1);
}
else
{
cout << f2(0, 0, n_ - 1, mp[get<1>(entry)], mp[get<2>(entry)]) << ' ';
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIGJvbHRfaW8gaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKSwgY2luLnRpZSgwKQoKY29uc3QgaW50IE4gPSA2ZTUgKyA1OwppbnQgbiwgcSwgdWMsIG5fLCBpYywgc3RbNCAqIE5dLCBhW05dLCBiW05dOwp2ZWN0b3I8dHVwbGU8Y2hhciwgaW50LCBpbnQ+PiB2cDsKbWFwPGludCwgaW50PiBtcDsKCnZvaWQgZjEoaW50IHN0aSwgaW50IGxsLCBpbnQgcnIsIGludCBpeCwgaW50IHYpCnsKICAgIGlmIChsbCA9PSBycikKICAgICAgICBzdFtzdGldICs9IHY7CiAgICBlbHNlCiAgICB7CiAgICAgICAgaW50IG0gPSAobGwgKyBycikgPj4gMTsKICAgICAgICBpZiAoaXggPD0gbSkKICAgICAgICAgICAgZjEoMiAqIHN0aSArIDEsIGxsLCBtLCBpeCwgdik7CiAgICAgICAgZWxzZQogICAgICAgICAgICBmMSgyICogc3RpICsgMiwgbSArIDEsIHJyLCBpeCwgdik7CgogICAgICAgIHN0W3N0aV0gKz0gdjsKICAgIH0KfQoKaW50IGYyKGludCBzdGksIGludCBsbCwgaW50IHJyLCBpbnQgbHEsIGludCBycSkKewogICAgaWYgKHJxIDwgbGwgfHwgcnIgPCBscSkKICAgICAgICByZXR1cm4gMDsKICAgIGVsc2UgaWYgKGxxIDw9IGxsICYmIHJyIDw9IHJxKQogICAgICAgIHJldHVybiBzdFtzdGldOwogICAgZWxzZQogICAgewogICAgICAgIGludCBtID0gKGxsICsgcnIpID4+IDE7CiAgICAgICAgcmV0dXJuIGYyKDIgKiBzdGkgKyAxLCBsbCwgbSwgbHEsIHJxKSArIGYyKDIgKiBzdGkgKyAyLCBtICsgMSwgcnIsIGxxLCBycSk7CiAgICB9Cn0KCnNpZ25lZCBtYWluKCkKewogICAgYm9sdF9pbzsKICAgIGNpbiA+PiBuID4+IHE7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykKICAgICAgICBjaW4gPj4gYVtpY10sIGljKys7CgogICAgdnAucmVzaXplKHEpOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBxOyBpKyspCiAgICB7CiAgICAgICAgY2hhciBjaDsKICAgICAgICBpbnQgeCwgeTsKICAgICAgICBjaW4gPj4gY2ggPj4geCA+PiB5OwogICAgICAgIHZwW2ldID0ge2NoLCB4LCB5fTsKCiAgICAgICAgaWYgKGNoID09ICchJykKICAgICAgICAgICAgYVtpY10gPSB5LCBpYysrOwogICAgICAgIGVsc2UKICAgICAgICAgICAgYVtpY10gPSB4LCBhW2ljICsgMV0gPSB5LCBpYyArPSAyOwogICAgfQoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKQogICAgICAgIGJbaV0gPSBhW2ldOwoKICAgIHNvcnQoYSwgYSArIGljKTsKICAgIG1wW2FbMF1dID0gMDsKCiAgICBmb3IgKGludCBpID0gMTsgaSA8IGljOyBpKyspCiAgICAgICAgaWYgKGFbaV0gIT0gYVtpIC0gMV0pCiAgICAgICAgICAgIG1wW2FbaV1dID0gbXBbYVtpIC0gMV1dICsgMTsKCiAgICB1YyA9IG1wLnNpemUoKTsKICAgIG5fID0gMSA8PCAoX19sZyh1YykgKyAxKTsKICAgIGlmICgodWMgJiAodWMgLSAxKSkgPT0gMCkKICAgICAgICBuXyA+Pj0gMTsKCiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykKICAgICAgICBmMSgwLCAwLCBuXyAtIDEsIG1wW2JbaV1dLCArMSk7CgogICAgZm9yICh0dXBsZTxjaGFyLCBpbnQsIGludD4gZW50cnkgOiB2cCkKICAgIHsKICAgICAgICBpZiAoZ2V0PDA+KGVudHJ5KSA9PSAnIScpCiAgICAgICAgewogICAgICAgICAgICBmMSgwLCAwLCBuXyAtIDEsIG1wW2JbZ2V0PDE+KGVudHJ5KV0gLSAxXSwgLTEpOwogICAgICAgICAgICBiW2dldDwxPihlbnRyeSkgLSAxXSA9IGdldDwyPihlbnRyeSk7CiAgICAgICAgICAgIGYxKDAsIDAsIG5fIC0gMSwgbXBbYltnZXQ8MT4oZW50cnkpIC0gMV1dLCArMSk7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIGNvdXQgPDwgZjIoMCwgMCwgbl8gLSAxLCBtcFtnZXQ8MT4oZW50cnkpXSwgbXBbZ2V0PDI+KGVudHJ5KV0pIDw8ICcgJzsKICAgICAgICB9CiAgICB9CgogICAgcmV0dXJuIDA7Cn0=