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. Perform the Combo CodeForces - 1311C(字符串反转+树状数组)

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

  2. Codeforces 1311C Perform the Combo

    这里我使用的是动态规划的方法,先对一串字符串计算它的前缀和. 核心代码 for(int i=0;i<len;i++) {if (i>0)for(int q=0;q<26;q++){ ...

  3. CF1311C Perform the Combo 题解

    题目:Link 暴力 - 前缀和 一道比较有趣的前缀和练习题 可以看出,题目有多次求 1∼pi1\sim p_i1∼pi​ 上每个字母的数量.我们可以很轻松的用前缀和解决,只是需要多开一维记录字母 设 ...

  4. CF1311C. Perform the Combo题解

    description: 给定一个长度为 nnn 小写字母字符串 sss.(这里默认下标从 111 开始) 给定一个长度为 mmm 的数列 pip_ipi​. 对于每一个 pip_ipi​,表示你要统 ...

  5. 集训队每周一赛2020-03-06(思维+暴力)

    第二次周赛 A 我是A题 CodeForces 1305 题解 B 我是B题 计蒜客 A1530 题解 C 我是C题 HDU 2673 题解 D 我是D题 CodeForces 304B 题解 E 我 ...

  6. Codeforce 1042 D. Petya and Array(树状数组、前缀和)

    题目链接 省赛选拔学长说是CF的原题,赛后得知学长是用树状数组写的,补了一个树状数组的代码. 题意 NNN个数,问一共有多少个连续区间满足区间和小于 MMM 思路 记录每个数的前缀和sortsorts ...

  7. Codeforce 水题报告(2)

    又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...

  8. Subsequence Hate CodeForces - 1363B(前缀和+dp)

    Shubham has a binary string s. A binary string is a string containing only characters "0" ...

  9. 【CodeForces - 675C】Money Transfers(思维,前缀和)

    题干: There are n banks in the city where Vasya lives, they are located in a circle, such that any two ...

最新文章

  1. 边结点结构体的定义及使用
  2. MYSQL备份与恢复精华篇
  3. python import gc_Python 2.6 GC似乎可以清理对象,但不会释放内存
  4. [基础题] 3、设计一个交通工具抽象类,提供抽象方法--驾驶
  5. Spring Cloud(F版)搭建高可用服务注册中心
  6. 测试之道--阿里巴巴八年测试专家倾情奉献
  7. Android 8.0 学习(17)---Android8.0中对指纹的新要求
  8. Eclipse / Intellij Idea配置Git+Maven+Jetty开发环境
  9. 程序员的职业素养---编码
  10. R. Shankar《Principles of Quantum Mechanics (2nd)》(山卡《量子力学原理(第二版)》)双语目录
  11. 分布式web系统架构图及应用架构图
  12. 如何bat修改dns
  13. 【UnityAR相关】Unity Vuforia扫图片成模型具体步骤
  14. Redis缓存穿透、击穿、雪崩、概念及解决办法
  15. i3 7100黑苹果_黑苹果系统是否好用?
  16. 【micropython】滑动平均滤波
  17. 如何考评一名前端工程师?
  18. 解决java发邮件错误javax.net.ssl.SSLHandshakeException: No appropriate protocol
  19. 【Apache Mina2.0开发之一】搭建Apache Mina框架并实现Server与Client端的简单消息传递!
  20. 【网络表示学习】BiNE

热门文章

  1. Android23版本以上删除HttpClient的解决办法
  2. 教你实现splash欢迎页面延迟跳转的6种方法
  3. 搭搭机器人科技活动中心怎么样_搭搭乐乐机器人怎么样?感受科技创收力量
  4. poj1942(求组合数)
  5. java B2B2C Springcloud多租户电子商城系统-集成项目简介
  6. IDEA git修改远程仓库地址
  7. iOS新上线注意事项
  8. D-Link登录时密码错误输入三次而无法登录问题的处理
  9. 绝对经典的滑动门特效代码
  10. c语言斐波那契数列_神奇的数列——斐波那契数列