fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5.  
  6. int main() {
  7. int t;
  8. cin>>t;
  9. while(t--)
  10. {
  11. string s;
  12. long n,m;
  13. cin>>n>>m;
  14. cin>>s;
  15. int *p=new int[m];
  16. for(int i=0;i<m;i++)
  17. {
  18. cin>>p[i];
  19. --p[i];
  20. }
  21. int *arr=new int[26];
  22. for(int i=0;i<26;i++)
  23. {
  24. arr[i]=0;
  25. }
  26. for(int i=0;i<m;i++)
  27. {
  28. for(int j=0;j<=p[i];j++)
  29. {
  30. if(p[i]==n-1 )
  31. {
  32. break;
  33. }
  34. arr[s[j]-97]++;
  35. }
  36. }
  37. for(int i=0;i<26;i++)
  38. {
  39. arr[s[i]-97]++;
  40. }
  41.  
  42. for(int i=0;i<26;i++)
  43. {
  44. cout<<arr[i]<<" ";
  45. }
  46. cout<<endl;
  47. }
  48. return 0;
  49. }
Success #stdin #stdout 0s 4272KB
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