Untitled

mail@pastecode.io avatar
unknown
c_cpp
7 days ago
1.3 kB
1
Indexable
Never
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
 
const int Maxn = 100005;
const int Maxl = 26;
 
int t;
string s;
int freq[Maxn][Maxl];
int q;
int tk[Maxl], pnt;
 
int main()
{
    scanf("%d", &t);
    for (int tc = 1; tc <= t; tc++) {
        printf("Case #%d:\n", tc);
        getline(cin, s); getline(cin, s);
        for (int i = 1; i <= s.length(); i++) {
            for (int j = 0; j < Maxl; j++) freq[i][j] = freq[i - 1][j];
            freq[i][s[i - 1] - 'A']++;
        }
        scanf("%d", &q);
        while (q--) {
            char com; int l, r; scanf(" %c %d %d", &com, &l, &r); l++; r++;
            if (com == 's') {
                for (int i = 0; i < Maxl; i++)
                    tk[i] = freq[r][i] - freq[l - 1][i];
                pnt = 0;
                for (int i = l; i <= r; i++) {
                    while (!tk[pnt]) pnt++;
                    for (int j = 0; j < Maxl; j++) freq[i][j] = freq[i - 1][j];
                    freq[i][pnt]++;
                    tk[pnt]--;
                }
            } else
                for (int i = 0; i < Maxl; i++)
                    printf("%d%c", freq[r][i] - freq[l - 1][i], i + 1 < Maxl? ' ': '\n');
        }
    }
    return 0;
}
Leave a Comment