#include <iostream>
#include <vector>
#include <utility>
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
using orderStaticTree =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define saleh ios_base::sync_with_stdio(false); cin.tie(nullptr);
const int MX = 2e5 + 100;
int n, q;
vector<orderStaticTree<pair<int, int>>> bit(MX);
void add(int ind, int val, int id) {
for (; ind <= n; ind += (ind & (-ind))) {
bit[ind].insert({val, id});
}
}
void remo(int ind, int val, int id) {
for (; ind <= n; ind += (ind & (-ind))) {
bit[ind].erase({val, id});
}
}
int range(int mini, int maxi) {
int ind = n;
int ans = 0;
for (; ind > 0; ind -= (ind & (-ind))) {
ans += bit[ind].order_of_key({maxi + 1, 0}) - bit[ind].order_of_key({mini, 0});
}
return ans;
}
int main() {
saleh;
cin >> n >> q;
vector<int> v(n + 1);
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
for (int i = 1; i <= n; i++) {
add(i, v[i], i);
}
while (q--) {
char op;
cin >> op;
if (op == '?') {
int mini, maxi;
cin >> mini >> maxi;
cout << range(mini, maxi) << endl;
} else {
int ind, val;
cin >> ind >> val;
remo(ind, v[ind], ind);
add(ind, val, ind);
v[ind] = val;
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8dXRpbGl0eT4KI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNpbmNsdWRlIDxleHQvcGJfZHMvYXNzb2NfY29udGFpbmVyLmhwcD4KdXNpbmcgbmFtZXNwYWNlIF9fZ251X3BiZHM7Cgp0ZW1wbGF0ZSA8Y2xhc3MgVD4KdXNpbmcgb3JkZXJTdGF0aWNUcmVlID0KICAgIHRyZWU8VCwgbnVsbF90eXBlLCBsZXNzPFQ+LCByYl90cmVlX3RhZywgdHJlZV9vcm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gKGludCBpID0gMTsgaSA8PSBuOyBpKyspIHsKICAgICAgICBhZGQoaSwgdltpXSwgaSk7CiAgICB9CgogICAgd2hpbGUgKHEtLSkgewogICAgICAgIGNoYXIgb3A7CiAgICAgICAgY2luID4+IG9wOwoKICAgICAgICBpZiAob3AgPT0gJz8nKSB7CiAgICAgICAgICAgIGludCBtaW5pLCBtYXhpOwogICAgICAgICAgICBjaW4gPj4gbWluaSA+PiBtYXhpOwogICAgICAgICAgICBjb3V0IDw8IHJhbmdlKG1pbmksIG1heGkpIDw8IGVuZGw7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaW50IGluZCwgdmFsOwogICAgICAgICAgICBjaW4gPj4gaW5kID4+IHZhbDsKICAgICAgICAgICAgcmVtbyhpbmQsIHZbaW5kXSwgaW5kKTsKICAgICAgICAgICAgYWRkKGluZCwgdmFsLCBpbmQpOwogICAgICAgICAgICB2W2luZF0gPSB2YWw7CiAgICAgICAgfQogICAgfQoKICAgIHJldHVybiAwOwp9Cg==