fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = 2e5+1, P = 26;
  4. int prefix[N][P], trials[N], m, n, t;
  5.  
  6. int main() {
  7. cin.tie(nullptr)->sync_with_stdio(false), cin >> t;
  8. for (string s; t--; cout << '\n', fill(trials,trials+n+1,0)) {
  9. cin >> n >> m >> s, trials[n] = 1;
  10. for (int i = 0; i < n; ++i) {
  11. const auto prev = prefix[i], pres = prefix[i+1];
  12. copy(prev,prev+P,pres), ++pres[s[i]-'a']; }
  13. for (int p; m--; ++trials[p])
  14. cin >> p;
  15. for (int k = 0; k < P; ++k) {
  16. long long count = 0;
  17. for (int p = 1; p <= n; ++p)
  18. count += 1ll*prefix[p][k]*trials[p];
  19. cout << count << ' '; } }
  20. return 0; }
  21.  
Success #stdin #stdout 0.01s 5580KB
stdin
3
4 2
abca
1 3
10 5
codeforces
2 8 3 2 9
26 10
qwertyuioplkjhgfdsazxcvbnm
20 10 1 2 3 5 10 5 9 4
stdout
4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 9 4 5 3 0 0 0 0 0 0 0 0 9 0 0 3 1 0 0 0 0 0 0 0 
2 1 1 2 9 2 2 2 5 2 2 2 1 1 5 4 11 8 2 7 5 1 10 1 5 2