fork(2) download
  1. #include<bits/stdc++.h>
  2. using namespace std ;
  3.  
  4. #define ll long long
  5. #define rep(i,a,n) for ( int i = a ; i <= n ; i++ )
  6. #define REP(i,a,n) for ( int i = a ; i >= n ; i-- )
  7.  
  8. typedef pair<int,int> ii ;
  9. typedef vector<int> vi ;
  10.  
  11. const int N = 2e5+5 ;
  12. const int INF = 1e9 ;
  13.  
  14. int t,n,w,b,m ;
  15. int ans[27],a[N] ;
  16.  
  17. string s ;
  18. vector<vi> G ;
  19.  
  20. signed main()
  21. {
  22. cin >> t ;
  23. while(t--){
  24. cin >> n >> m ;
  25. cin >> s;
  26. rep(i,0,26) ans[i] = 0 ;
  27. rep(i,1,m) cin >> a[i] ;
  28. sort(a+1,a+m+1) ;
  29. rep(i,0,n-1) ans[s[i]-'a']++;
  30. int cnt = a[m] , cur=1 ;
  31. int i = m-1 ;
  32. while(i>=1){
  33. if ( a[i] < cnt )
  34. {
  35. REP(j,cnt-1,a[i]) ans[s[j]-'a'] += cur ;
  36. cnt = a[i] ;
  37. }
  38. cur++ ;
  39. i-- ;
  40. }
  41. REP(j,a[1]-1,0) ans[s[j]-'a'] += cur ;
  42. rep(i,0,25) cout << ans[i] << " " ;
  43. cout << endl ;
  44. }
  45. }
  46.  
  47.  
  48.  
  49.  
Success #stdin #stdout 0s 4488KB
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