fork download
  1. #include <functional>
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <numeric>
  5. #include <stdio.h>
  6. #include <cstring>
  7. #include <vector>
  8. #include <cctype>
  9. #include <math.h>
  10. #include <time.h>
  11. #include <queue>
  12. #include <stack>
  13. #include <set>
  14. #include <map>
  15.  
  16. using namespace std;
  17.  
  18. #define all(p) (p).begin(), (p).end()
  19. #define fi first
  20. #define se second
  21.  
  22. #define TASKNAME ""
  23. //#define DEBUG
  24.  
  25. typedef long long ll;
  26.  
  27. const int N = 111111;
  28. const int INF = int(1e9), mod = INF + 7;
  29.  
  30. string s;
  31. vector <int> f[26];
  32. int cnt[26], q[5];
  33.  
  34. void solve(int tt) {
  35.  
  36. cin >> s;
  37. int n = s.length();
  38.  
  39. for (int i = 0; i < 26; ++i)
  40. f[i].assign(n, 0);
  41.  
  42. for (int let = 0; let < 26; ++let) {
  43.  
  44. for (int i = 0; i < n; ++i) {
  45.  
  46. f[let][i] = (s[i] - 'A' == let);
  47. if (i > 0) f[let][i] += f[let][i - 1];
  48. }
  49.  
  50. }
  51.  
  52. cin >> q[tt];
  53. while(q[tt] --> 0) {
  54.  
  55. char type; int l, r;
  56. cin >> type >> l >> r;
  57.  
  58. if (type == 's') {
  59.  
  60. for (int i = l; i <= r; ++i)
  61. cnt[s[i] - 'A']++;
  62.  
  63. int it = 0, it1 = l;
  64.  
  65. while(it < 26) {
  66.  
  67. if (cnt[it] == 0) it++;
  68. else {
  69. s[it1] = it + 'A';
  70. --cnt[it];
  71. ++it1;
  72. }
  73.  
  74. }
  75.  
  76. for (int let = 0; let < 26; ++let) {
  77.  
  78. for (int i = l; i <= r; ++i) {
  79.  
  80. f[let][i] = (s[i] - 'A' == let);
  81. if (i > 0) f[let][i] += f[let][i - 1];
  82. }
  83.  
  84. }
  85.  
  86. } else {
  87.  
  88. for (int let = 0; let < 26; ++let) {
  89.  
  90. printf("%d%c", f[let][r] - (l > 0 ? f[let][l - 1] : 0), let == 25 ? '\n' : ' ');
  91.  
  92. }
  93.  
  94. }
  95.  
  96. }
  97. }
  98.  
  99. int main() {
  100.  
  101. int t;
  102. cin >> t;
  103.  
  104. for (int tt = 1; tt <= t; ++tt) {
  105.  
  106. printf("Case #%d:\n", tt);
  107. solve(tt);
  108.  
  109. }
  110.  
  111.  
  112. return 0;
  113. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Standard output is empty