#include using namespace std; #include using mint = atcoder::modint998244353; #include #define rep(i, l, r) for (int i = (l); i < (r); i++) #define ll long long #define all(x) (x).begin(), (x).end() #define siz(x) (int)x.size() #define debug(x) cout << #x << " : " << endl; for (auto u : x) cout << u << " "; cout << endl template bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } const int inf = 1e9; const ll INF = 4e18; int main() { int N, Q; cin >> N >> Q; string S; cin >> S; int M = 20; //21以上になったら詰むんじゃないか? vector> ans(N, vector(M + 1, 0)); ll sum = 0; auto update = [&](int l) -> void { rep(k, 0, M + 1) sum -= ans[l][k]; ans[l][0] = 1; vector app(10, false), ok(10, true); vector seen(10, 0); for (int r = l + 1; r <= min(N, l + M); r++) { if (ans[l][r - l - 1] == 0) { ans[l][r - l] = 0; continue; } //面倒だなあ int c = S[r - 1] - '0'; ans[l][r - l] = ok[c]; rep(k, 0, 10) { if (app[k]) { if (seen[k] >> c & 1) ok[k] = false; else seen[k] |= (1 << c); } } app[c] = true; } rep(k, 0, M + 1) sum += ans[l][k]; }; rep(i, 0, N) update(i); // rep(i, 0, N) { // rep(j, 0, M + 1) cout << ans[i][j] << " "; // cout << endl; // } while(Q--) { int i; char c; cin >> i >> c; i--; S[i] = c; for (int l = max(0, i - 20); l <= i; l++) update(l); cout << sum - N - N - (N - 1) << "\n"; } }