C - Perform the Combo
C - Perform the Combo



思路:当读到这个题的时候,第一反应就是枚举,但是,无线超时,没办法,那就变,利用前缀和,减少时间。
代码:
#include<iostream>
#include<string>
#include<algorithm>
#define MAX 200005
using namespace std;
long long str[MAX];
long long b[28];
char s[MAX]; int main(){
int t,n, m;
scanf("%d", &t);
while (t--){
memset(str, 0, sizeof str);
memset(b, 0, sizeof b);
scanf("%d%d", &n, &m);
scanf("%s", s + 1);
for (int i = 1; i <= m; ++i){
long long a;
scanf("%lld", &a);
str[a] ++;
}
for (int i = n - 1; i >= 1; i--)
str[i] += str[i + 1];
for (int i = 1; i <= n; ++i){
b[s[i] - 'a'] += str[i] + 1;
}
for (int i = 0; i < 26; ++i) {
printf("%lld ", b[i]);
}
printf("\n");
}
return 0;
}
C - Perform the Combo的更多相关文章
- 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 ...
- codeforce 1311 C. Perform the Combo 前缀和
You want to perform the combo on your opponent in one popular fighting game. The combo is the string ...
- [CF1311C] Perform the Combo
Solution 前缀和搞一下即可 #include <bits/stdc++.h> using namespace std; #define int long long const in ...
- 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 ...
- Codeforces Round #624 (Div. 3)(题解)
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...
- Codeforces Round #624 (Div. 3)(题解)
A. Add Odd or Subtract Even 思路: 相同直接为0,如果两数相差为偶数就为2,奇数就为1 #include<iostream> #include<algor ...
- Codeforces #624 div3 C
You want to perform the combo on your opponent in one popular fighting game. The combo is the string ...
- jquery Combo Select 下拉框可选可输入插件
Combo Select 是一款友好的 jQuery 下拉框插件,在 PC 浏览器上它能模拟一个简单漂亮的下拉框,在 iPad 等移动设备上又能回退到原生样式.Combo Select 能够对选项进行 ...
- [转]Extjs combo数据绑定与获取
原文地址:http://www.cnblogs.com/loveme123/archive/2012/05/10/2494466.html 1. 配置combo: { ...
- CDN的combo技术能把多个资源文件合并引用,减少请求次数
CDN的combo技术能把多个资源文件合并引用,减少请求次数.比如淘宝的写法: <link rel="stylesheet" href="//g.alicdn.co ...
随机推荐
- LeetCode 周赛 332,在套路里摸爬滚打~
本文已收录到 AndroidFamily,技术和职场问题,请关注公众号 [彭旭锐] 提问. 大家好,今天是 3T 选手小彭. 上周是 LeetCode 第 332 场周赛,你参加了吗?算法解题思维需要 ...
- STM32F0库函数初始化系列:进入STOP模式,外部中断唤醒
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0); EXTI_InitStructure.EXTI_Line=EXTI_Line ...
- JavaScript是怎样实现继承的?
一.是什么 继承(inheritance)是面向对象软件技术当中的一个概念. 如果一个类别B"继承自"另一个类别A,就把这个B称为"A的子类",而把A称为&qu ...
- Solon2 之基础:一、常用应用配置说明
约定参考: //资源路径约定(不用配置:也不能配置) resources/app.yml( 或 app.properties ) #为应用配置文件 resources/WEB-INF/static/ ...
- PostgreSQL事务隔离级别
一.概念 并发控制是多个事务在并发运行时,数据库保证事务一致性(Consistency)和隔离性(Isolation)的一种机制.PostgreSQL使用了多版本并发控制技术的一种变体:快照隔离San ...
- pip换源和制作虚拟环境操作步骤讲解
目录 一.pip换源及虚拟环境 二.虚拟环境 一.pip换源及虚拟环境 我们Python的强大之处就是有非常多的牛逼的第三方模块,后面的程序员只需要下载第三方模块,然后站在大佬们的肩膀上开发,第三方开 ...
- PACS系统各个功能介绍--九五小庞
PACS系统是HIS系统的重要组成部分,医生可在电脑上查看患者的医学影像报告. ■ 支持心电DICOM,心电图浏览和处理(显示格式.纸速.增益.滤波.测量等). ■ 支持MPR.CPR.MIP.SSD ...
- Vue项目安装less和less-loader
第一步: 查看webpack和webpack-cli是否安装打开cmd,通过命令查看 webpack -v webpack-cli -v 如果没有安装,要先进行安装 可以通过 npm view web ...
- Min_25 Sieve 学习笔记
这个东西不是人想的. 解决问题:积性函数前缀和. 适用条件:可以快速计算 \(f(p)\) 的前缀和,\(f(p^k)\) 可以被表示成若干完全积性函数的线性组合(指对应项可以快速组合出来). 时空复 ...
- Git上手教程
不说费话,直接上链接 廖雪峰老师的GIT教程