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
#include <bits/stdc++.h>
using namespace std;

unsigned long long int calculate(string &s, int n, int cur, const string &sub, map<string, int> &used) {
    if(cur == n) {
        unsigned long long int result = used[sub]++;
//        if(result == 1)
//            cout << sub << "\n";
        return result == 1;
    }
    return calculate(s, n, cur+1, sub+s[cur], used) + calculate(s, n, cur+1, sub, used);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    string s;
    int n, q;           //length and queries
    cin >> n >> q >> s;
    while(true) {
        q--;
        map<string, int> used;
        cout << calculate(s, n, 0, "", used) << "\n";         //subtract empty set

        if(q == -1)
            break;
        int i;
        char c;
        cin >> i >> c;
        s[i-1] = c;
    }
    return 0;
}