Codeforces #624 div3 C
You want to perform the combo on your opponent in one popular fighting game. The combo is the string ss consisting of nn lowercase Latin letters. To perform the combo, you have to press all buttons in the order they appear in ss. I.e. if s=s="abca" then you have to press 'a', then 'b', 'c' and 'a' again.
You know that you will spend mm wrong tries to perform the combo and during the ii-th try you will make a mistake right after pipi-th button (1≤pi<n1≤pi<n) (i.e. you will press first pipi buttons right and start performing the combo from the beginning). It is guaranteed that during the m+1m+1-th try you press all buttons right and finally perform the combo.
I.e. if s=s="abca", m=2m=2 and p=[1,3]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 tt independent test cases.
The first line of the input contains one integer tt (1≤t≤1041≤t≤104) — the number of test cases.
Then tt test cases follow.
The first line of each test case contains two integers nn and mm (2≤n≤2⋅1052≤n≤2⋅105, 1≤m≤2⋅1051≤m≤2⋅105) — the length of ss and the number of tries correspondingly.
The second line of each test case contains the string ss consisting of nn lowercase Latin letters.
The third line of each test case contains mm integers p1,p2,…,pmp1,p2,…,pm (1≤pi<n1≤pi<n) — the number of characters pressed right during the ii-th try.
It is guaranteed that the sum of nn and the sum of mm both does not exceed 2⋅1052⋅105 (∑n≤2⋅105∑n≤2⋅105, ∑m≤2⋅105∑m≤2⋅105).
It is guaranteed that the answer for each letter does not exceed 2⋅1092⋅109.
For each test case, print the answer — 2626 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'.
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
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
这题数字可能比较大,直接遍历必然超时,我们记录每个错误的位置,在该位置之前的每个字母必然+1,倒序求一个前缀和就行了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define ll long long
const int N=1e6+10;
using namespace std;
typedef pair<int,int>PII;
int t;
int n,m;
string s;
int a[N];
int d[N];
int ans[N];
int main(){
ios::sync_with_stdio(false);
cin>>t;
while(t--){
cin>>n>>m>>s; memset(a,0,N); memset(ans,0,N);
for(int i=0;i<m;i++){
int q;
cin>>q;
a[--q]++;
}
for(int i=n-2;i>=0;i--){
a[i]+=a[i+1];
}
for(int i=0;i<n;i++){
ans[s[i]-'a']+=1+a[i];
}
for(int i=0;i<26;i++) cout<<ans[i]<<" ";
cout<<endl;
}
return 0;
}
Codeforces #624 div3 C的更多相关文章
- Codeforces #550 (Div3) - G.Two Merged Sequences(dp / 贪心)
Problem Codeforces #550 (Div3) - G.Two Merged Sequences Time Limit: 2000 mSec Problem Description T ...
- codeforces #579(div3)
codeforces #579(div3) A. Circle of Students 题意: 给定一个n个学生的编号,学生编号1~n,如果他们能够在不改变顺序的情况下按编号(无论是正序还是逆序,但不 ...
- CODEFORCES ROUND#624 DIV3
这次比赛从名字就可以看出非常水,然鹅因为第一次打codeforces不太熟悉操作只来的及做签到题(还错了一次) A,B,C都是签到题考点思维就不写了 D题 https://codeforces.ml/ ...
- CodeForces 1029E div3
题目链接 第一道场上自己做出来的E题...虽然是div3,而且是原题... 当时做完ABC,D题没有思路就去怼E了,然后发现貌似原题? 事实上就是原题... 给个原题链接... [HNOI2003]消 ...
- [Codeforces #615 div3]1294E Obtain a Permutation
Before the Beginniing 本文为 Clouder 原创文章,原文链接为Click,转载时请将本段放在文章开头显眼处.如进行了二次创作,请明确标明. 由本人转载于博客园. 题意分析 C ...
- Codeforces 624
B. Making a String time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Twist the Permutation 数列的轮换题 Codeforces 776 div3
这是一道比较经典的将数列中的数字轮换的题目,我们先看题干: 题干分析:先浅浅地分析一下题目是要我们干什么,我们会默认有一个已经升序排序地1~n的排列,然后我们会给定一个新排列是在原有排列的基础上进行o ...
- 记一次神奇的codeforces
今天有一场codeforces的div3,时间挺合适,于是就想打.结果发现rating超过1600就不能报名.虽然shzr好久不打CF了而且很菜,但是毕竟还是到了1600的,于是和ZUTTER_一起用 ...
- CodeForces Round #527 (Div3) B. Teams Forming
http://codeforces.com/contest/1092/problem/B There are nn students in a university. The number of st ...
随机推荐
- 有关Servlet的面试题
CGI(Common Gateway Interface),通用网管接口 通用网管接口,简称CGI,是一种根据请求信息动态产生回应内容的技术.通过CGI,web服务器可以根据请求的不同,启动不同的外部 ...
- python学习笔记 | wordcloud安装指南
问题: 直接在命令行输入: pip install wordcloud 不出意外,直接报错,显示缺失vc*****.bat,意思是缺失vc版本,这个安装方式基本可以扔掉. 解决: http://t.c ...
- 【Java】集合框架(List Set Map)
文章目录 集合框架 List(列表) ArrayList 案例 Set HashSet 案例 iterator(迭代器) Map HashMap 案例 集合总结 参考资料 重新搞一波 复习巩固 简单记 ...
- MyBatis初级实战之三:springboot集成druid
OpenWrite版: 欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kuber ...
- Oracle Rac to Rac One Node
=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2020.01.14 20:05:12 =~=~=~=~=~=~=~=~=~=~=~= [oracle@rac01 ~]$ srvc ...
- h5-video,视频在微信里变形、有黑边
如这种情况: 微信可谓是video标签的重灾区,如果你兼容了安卓的微信,那么在其他浏览器一般也没问题了除了个别(IE:你们看我干吗?). 解决方案: <video src="video ...
- ALV中layout布局控制详解
参数的结构为SLIS_LAYOUT_ALV.结构中比较常用的字段如下: no_colhead 隐藏列标题 值为X或空 no_hotspot headings不作为热 ...
- uni-app调用wifi接口
微信小程序条件渲染 在小程序app.json中添加 需要先获取位置信息 "permission": { "scope.userLocation": { &quo ...
- torch.optim.SGD()各参数的解释
看pytorch中文文档摘抄的笔记. class torch.optim.SGD(params, lr=, momentum=0, dampening=0, weight_decay=0, neste ...
- Bitter.Core系列二:Bitter ORM NETCORE ORM 全网最粗暴简单易用高性能的 NETCore ORM 之数据库连接
Bitter.Core NETCore 相当的简单易用,下面附上使用示例: 数据中连接:请在你的NETCORE 项目中 创建:Bitter.json 配置文件,然后追加如下配置内容: MSSQL 连接 ...