fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int t, n, m, p[300000], kl;
  4. string s;
  5. int main() {
  6. ios::sync_with_stdio(false);
  7. cin.tie(0);
  8. cout.tie(0);
  9. cin >> t;
  10. while(t--){
  11. cin >> n >> m;
  12. cin >> s;
  13. kl = m;
  14. map<char, int> a;
  15. for(int i = 0; i < m; i++){
  16. cin >> p[i];
  17. }
  18. sort(p, p + m, greater<>());
  19. for(int i = 0; i < m; i++){
  20. for(int j = 0; j < p[m]; j++) a[s[j]]++;
  21. }
  22. for(auto i : a){
  23. cout << i.second << " ";
  24. }
  25. cout << endl;
  26. }
  27. }
  28.  
Success #stdin #stdout 0s 4380KB
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