1311C - Perform the Combo - CodeForces Solution


brute force *1300

Please click on ads to support us..

Python Code:

t = int(input())
for _ in range(t):
    n, m = map(int, input().split())
    s = input()
    p = list(map(int, input().split()))
    mp = [0] * n
    for value in p:
        mp[value - 1] += 1
    for i in range(n - 1, 0, -1):
        mp[i - 1] += mp[i]
    occ = [0] * 26
    for i in range(len(s)):
        occ[ord(s[i]) - ord('a')] += mp[i]
        occ[ord(s[i]) - ord('a')] += 1
    print(' '.join(list(map(str, occ))))
			 	 	     

C++ Code:

/*                                                    !_
                                                      |*~=-.,
                                                      |_,-'`
                                                      |
                                                      |
                                                     /^\
                       !_                           /   \
                       |*`~-.,                     /,    \
                       |.-~^`                     /#"     \
                       |                        _/##_   _  \_
                  _   _|  _   _   _            [ ]_[ ]_[ ]_[ ]
                 [ ]_[ ]_[ ]_[ ]_[ ]            |_=_-=_ - =_|
               !_ |_=_ =-_-_  = =_|           !_ |=_= -    |
               |*`--,_- _        |            |*`~-.,= []  |
               |.-'|=     []     |   !_       |_.-"`_-     |
               |   |_=- -        |   |*`~-.,  |  |=_-      |
             /^\  |=_= -        |   |_,-~`  /^\ |_ - =[]  |
          _  /   \_|_=- _   _   _|  _|  _   /   \|=_-      |
         [ ]/,    \[ ]_[ ]_[ ]_[ ]_[ ]_[ ]_/,    \[ ]=-    |
          |/#"     \_=-___=__=__- =-_ -=_ /#"     \| _ []  |
         _/##_   _  \_-_ =  _____       _/##_   _  \_ -    |\
        [ ]_[ ]_[ ]_[ ]=_0~{_ _ _}~0   [ ]_[ ]_[ ]_[ ]=-   | \
        |_=__-_=-_  =_|-=_ |  ,  |     |_=-___-_ =-__|_    |  \
         | _- =-     |-_   | ((* |      |= _=       | -    |___\
         |= -_=      |=  _ |  `  |      |_-=_       |=_    |/+\|
         | =_  -     |_ = _ `-.-`       | =_ = =    |=_-   ||+||
         |-_=- _     |=_   =            |=_= -_     |  =   ||+||
         |=_- /+\    | -=               |_=- /+\    |=_    |^^^|
         |=_ |+|+|   |= -  -_,--,_      |_= |+|+|   |  -_  |=  |
         |  -|+|+|   |-_=  / |  | \     |=_ |+|+|   |-=_   |_-/
         |=_=|+|+|   | =_= | |  | |     |_- |+|+|   |_ =   |=/
         | _ ^^^^^   |= -  | |  <&>     |=_=^^^^^   |_=-   |/
         |=_ =       | =_-_| |  | |     |   =_      | -_   |
         |_=-_       |=_=  | |  | |     |=_=        |=-    |
    ^^^^^^^^^^`^`^^`^`^`^^^""""""""^`^^``^^`^^`^^`^`^``^`^``^``^^
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int,int>
#define gcd __gcd
#define S string 
#define inf INT_MAX
#define minf INT_MIN
#define lmax LLONG_MAX
#define  pb push_back
#define ff first
#define ss second
#define FAST ios_base::sync_with_stdio(false);
#define FAST_INPUT cin.tie(0);
#define FAST_OUTPUT cout.tie(0);
#define w(t)  int t; cin>>t; while(t--)
#define f(i,a,n) for(long long int i=a;i<n;i++)
#define g(i,a,n) for(long long int i=a;i>=n;i--)
#define odd(n) (n&1)
#define endl "\n"
#define all(x) x.begin(),x.end()
#define yes()  cout<<"YES"<<endl 
#define no()   cout<<"NO"<<endl
#define no1() cout<<-1<<endl
const int N=1e6+10;
#define Mod 1000000007
#define mod 998244353
ll factorial(ll n)
{
    ll answer=1;
    while(n--)
    {
        answer*=n+1;
        answer%=Mod;
    }
    return answer;
}
ll power(ll a,ll b)
{
    if(b==0)
    return 1;
    ll res=power(a,b/2);
    if(odd(b))
    {
         return (a*res%Mod*res%Mod)%Mod;
    }
    else 
    {
        return (res%Mod*res%Mod)%Mod;
    }
}
ll modulo_inverse(ll n)
{
    return power(n,Mod-2);
}
ll ncr(ll n,ll r)
{
     if (r==0 || n==0)
     {
         return 1;
     }
    ll fac[n+1];
    fac[0]=1;
    f(i,1,n+1)
    {
        fac[i]=(fac[i-1]*i)%Mod;
    }
    
    return (fac[n]*modulo_inverse(fac[r])%Mod*modulo_inverse(fac[n-r])%Mod)%Mod;
}
void dis(vll v)
{
    f(i,0,v.size())
    {
         cout<<v[i]<<" ";
    }
}
ll digits(ll n)
{
    ll ct=0;
    while(n)
    {
        ct++;
        n/=10;
    }
    return ct;
}
ll b_digits(ll n)
{
    ll ct=0;
    while(n)
    {
        ct++;
        n/=2;
    }
    return ct;
}

int main()
{
	int t;
    cin>>t;
    while(t--)
    {
         ll n,k;
         cin>>n>>k;
         string s;
         cin>>s;
         vll v;
         map<ll,ll> m;
         f(i,0,k)
         {
            ll x;
            cin>>x;
            v.pb(x);
         }
         f(i,0,n)
         {
            m[s[i]-'a']++;
         }
         ll a[n][26];
         f(i,0,n)
         {
             f(j,0,26)
             {
                a[i][j]=0;
             }
         }
         a[0][s[0]-'a']++;
         f(i,1,n)
         {
             a[i][s[i]-'a']++;
             f(j,0,26)
             {
                 a[i][j]+=a[i-1][j];
             }
         }
         ll arr[26]={0};
         f(i,0,k)
         {
             f(j,0,26)
             {
                arr[j]+=(a[v[i]-1][j]);
             }
         }
         f(i,0,26)
         {
             cout<<arr[i]+m[i]<<" ";
         }
         cout<<endl;
         
    }
}


Comments

Submit
0 Comments
More Questions

1706C - Qpwoeirut And The City
1697A - Parkway Walk
1505B - DMCA
478B - Random Teams
1705C - Mark and His Unfinished Essay
1401C - Mere Array
1613B - Absent Remainder
1536B - Prinzessin der Verurteilung
1699B - Almost Ternary Matrix
1545A - AquaMoon and Strange Sort
538B - Quasi Binary
424A - Squats
1703A - YES or YES
494A - Treasure
48B - Land Lot
835A - Key races
1622C - Set or Decrease
1682A - Palindromic Indices
903C - Boxes Packing
887A - Div 64
755B - PolandBall and Game
808B - Average Sleep Time
1515E - Phoenix and Computers
1552B - Running for Gold
994A - Fingerprints
1221C - Perfect Team
1709C - Recover an RBS
378A - Playing with Dice
248B - Chilly Willy
1709B - Also Try Minecraft