CF624div3-C. Perform the Combo
题目
AC代码
#include <iostream> #include <algorithm> #include <stdio.h> #include <set> #include <cstring> #include <string> #include <cmath> using namespace std; typedef unsigned long long ll; ll T,N,M; int cnt[256]; int pos[1000010]; int cnt2[1000010]; char str[1000010]; void fun(){ for(ll i = 0;i<N;i++){ cnt[str[i]-'a']++; if(pos[i]){ cnt2[0]+=pos[i]; cnt2[i+1]-=pos[i]; } } for(ll i = 1;i<N;i++) cnt2[i] += cnt2[i-1]; for(ll i = 0;i<N;i++) cnt[str[i]-'a'] += cnt2[i]; for(int i = 0;i<26;i++) printf("%d ",cnt[i]); puts(""); } int main(){ cin>>T; while(T--){ scanf("%lld %lld",&N,&M); memset(cnt,0,sizeof cnt); memset(cnt2,0,sizeof(int)*N+10); memset(pos,0,sizeof(int)*N+10); scanf("%s",str); int tmp; for(ll i = 1;i<=M;i++){ scanf("%d",&tmp); pos[tmp-1] +=1; } fun(); } return 0; }