1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

constexpr int MOD = 998244353;

int solve(string s)
{
    set<string> one;
    set<string> two;

    for (size_t i = 0; i < s.size(); ++i)
    {
        set<string> nxt_one = one;
        set<string> nxt_two = two;

        for (auto const& x : two)
        {
            nxt_two.insert(x + s[i]);
        }

        string nxt{ s[i] };

        if (one.find(nxt) == one.end())
            nxt_one.insert(nxt);
        else
            nxt_two.insert(nxt);

        for (auto const& x : one)
        {
            nxt = x + s[i];

            if (one.find(nxt) == one.end())
                nxt_one.insert(nxt);
            else
                nxt_two.insert(nxt);
        }

        one = move(nxt_one);
        two = move(nxt_two);
    }

    return two.size();
}

int main()
{
    int n, q, p;
    string s;
    char z;
    cin >> n >> q >> s;

    int res = solve(s);

    cout << res << endl;

    for (int qq = 0; qq < q; ++qq)
    {
        cin >> p >> z;

        if (s[p - 1] != z)
        {
            s[p - 1] = z;

            res = solve(s);
        }

        cout << res << endl;
    }

    return 0;
}