You want to perform the combo on your opponent in one popular fighting game. The combo is the string s consisting of n lowercase Latin letters. To perform the combo, you have to press all buttons in the order they appear in s. I.e. if s=“abca” then you have to press ‘a’, then ‘b’, ‘c’ and ‘a’ again.

You know that you will spend m wrong tries to perform the combo and during the i-th try you will make a mistake right after pi-th button (1≤pi<n) (i.e. you will press first pi buttons right and start performing the combo from the beginning). It is guaranteed that during the m+1-th try you press all buttons right and finally perform the combo.

I.e. if s=“abca”, m=2 and p=[1,3] then the sequence of pressed buttons will be ‘a’ (here you’re making a mistake and start performing the combo from the beginning), ‘a’, ‘b’, ‘c’, (here you’re making a mistake and start performing the combo from the beginning), ‘a’ (note that at this point you will not perform the combo because of the mistake), ‘b’, ‘c’, ‘a’.

Your task is to calculate for each button (letter) the number of times you’ll press it.

You have to answer t independent test cases.

Input

The first line of the input contains one integer t (1≤t≤104) — the number of test cases.

Then t test cases follow.

The first line of each test case contains two integers n and m (2≤n≤2⋅105, 1≤m≤2⋅105) — the length of s and the number of tries correspondingly.

The second line of each test case contains the string s consisting of n lowercase Latin letters.

The third line of each test case contains m integers p1,p2,…,pm (1≤pi<n) — the number of characters pressed right during the i-th try.

It is guaranteed that the sum of n and the sum of m both does not exceed 2⋅105 (∑n≤2⋅105, ∑m≤2⋅105).

It is guaranteed that the answer for each letter does not exceed 2⋅109.

Output

For each test case, print the answer — 26 integers: the number of times you press the button ‘a’, the number of times you press the button ‘b’, …, the number of times you press the button ‘z’.

Example

inputCopy

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

outputCopy

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

Note

The first test case is described in the problem statement. Wrong tries are “a”, “abc” and the final try is “abca”. The number of times you press ‘a’ is 4, ‘b’ is 2 and ‘c’ is 2.

In the second test case, there are five wrong tries: “co”, “codeforc”, “cod”, “co”, “codeforce” and the final try is “codeforces”. The number of times you press ‘c’ is 9, ‘d’ is 4, ‘e’ is 5, ‘f’ is 3, ‘o’ is 9, ‘r’ is 3 and ‘s’ is 1.

就是个坠和的过程,可以用差分写

#include <bits/stdc++.h>
using namespace std;
int a[205000];
int b[27];
string s;
int main()
{
int t;
cin >> t;
while (t--)
{
int m, n, k;
cin >> n >> m;
cin >> s;
memset(a, 0, sizeof(a));
memset(b,0,sizeof(b));
for (int i = 1; i <= m; i++)
{
cin >> k;
a[k - 1] ++;
}
int cnt = 1;
b[s[s.size() - 1] - 'a']++;
for (int i = s.size() - 2; i >= 0; --i)
{
cnt+=a[i];
b[s[i] - 'a'] += cnt;
}
for(int i=0;i<26;i++)
cout<<b[i]<<" ";
puts("");
}
}

codeforce 1311 C. Perform the Combo 前缀和的更多相关文章

  1. Codeforces Round #624 (Div. 3) C. Perform the Combo(前缀和)

    You want to perform the combo on your opponent in one popular fighting game. The combo is the string ...

  2. [CF1311C] Perform the Combo

    Solution 前缀和搞一下即可 #include <bits/stdc++.h> using namespace std; #define int long long const in ...

  3. codeforce 1311 D. Three Integers

    In one move, you can add +1 or −1 to any of these integers (i.e. increase or decrease any number by ...

  4. Codeforces Round #624 (Div. 3)(题解)

    Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...

  5. Codeforces Round #624 (Div. 3)(题解)

    A. Add Odd or Subtract Even 思路: 相同直接为0,如果两数相差为偶数就为2,奇数就为1 #include<iostream> #include<algor ...

  6. Codeforces #624 div3 C

    You want to perform the combo on your opponent in one popular fighting game. The combo is the string ...

  7. Codeforces补题2020.2.28(Round624 Div 3)

    A.Add Odd or Subtract Even 签到题~ #include<bits/stdc++.h> using namespace std; int T; int a,b; i ...

  8. F. Moving Points 解析(思維、離散化、BIT、前綴和)

    Codeforce 1311 F. Moving Points 解析(思維.離散化.BIT.前綴和) 今天我們來看看CF1311F 題目連結 題目 略,請直接看原題. 前言 最近寫1900的題目更容易 ...

  9. codeforce 1189C Candies! ----前缀和

    题目大意:给你一个数组每个数不大于9,然后给你m个区间,每个区间的长度都是2的k次方(k=0 1 2.....)  有一种操作是把奇数位和偶数位相加  用和来代替之前的两个数,如果和大于等于10就要膜 ...

随机推荐

  1. Linux系统安装Dos系统(虚拟机里装)

    结合以下两篇优秀的文章就能完成任务. 1.https://www.jb51.net/os/609411.html 2.http://blog.51cto.com/6241809/1687361 所需要 ...

  2. hadoop(八)集群namenode启动ssh免密登录(完全分布式五)|10

    前置章节:hadoop集群配置同步(hadoop完全分布式四)|10 启动namenode之前: 1. 先查看有无节点启动,执行jps查看,有的话停掉 [shaozhiqi@hadoop102 ~]$ ...

  3. 自己模拟的ftl 用法:

    基类 public class Ftl_object_data_model { //三种基本属性 private boolean canRead=true;//是否能读取 ;//长度 private ...

  4. java的图形化界面 文本区JTextArea的程序例子

    package java1;     //使用时这个改成你的包名即可//文本区 JTextArea import javax.swing.*;import java.awt.*;import java ...

  5. 作为python开发者,这几个PyCharm 技巧你必须掌握!

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. PS:如有需要Python学习资料的小伙伴可以加点击下方链接自行获取htt ...

  6. A - Engines Atcoder 4900

    题目大意:n个点,任意几个点组合后得到的点距离原点的最远距离. 题解:极角排序:https://blog.csdn.net/qq_39942341/article/details/79840394 利 ...

  7. Python - 关于带参数的装饰器的理解

    [原创]转载请注明作者Johnthegreat和本文链接 关于装饰器的理解,特别像<盗梦空间>中的进入梦境和从梦境出来的过程,一层一层的深入梦境,然后又一层一层的返回,被带入梦境的是被装饰 ...

  8. [linux][MongoDB] mongodb学习(一):MongoDB安装、管理工具、

    参考原文:http://www.cnblogs.com/kaituorensheng/p/5118226.html linux安装完美实现! 1. mongoDB安装.启动.关闭 1.1 下载安装包 ...

  9. SpringBoot与单元测试JUnit的结合

    有些人认为,写单元测试就是在浪费时间 ,写完代码,依然还是能够进行测试的.但是,还是建议写单元测试的,可以让你的条理更加清晰,而且当某个功能出现问题时,可能通过单元测试很容易的定位和解决问题.本文主要 ...

  10. python 工具链 多版本管理工具 pyenv

    理解Shims pyenv会在系统的PATH最前面插入一个shims目录: $(pyenv root)/shims:/usr/local/bin:/usr/bin:/bin 通过一个rehashing ...