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 ...
随机推荐
- 宠物小精灵之收服(等级考试4级 2021-03 T1)
题目: 此题目可转化为 01背包问题 dp[ i ] [ j ] [ l ] 表示i个精灵球.j点体力.l 个精灵时最多收复精灵的个数. 注意事项:开三维数组一定要贴着给的数据开,本题中开dp[100 ...
- IDEA启动报错 NoClassDefFound
很仔细的看了项目,发现jar包都齐全,没有问题,找了几天,都没有发现什么问题. 最后,想到可能是启动配置的问题,内存的问题 加了上面的配置-Xss2058k,设定程序启动时占用内存大小,正常启动
- springcloud 08 Hystrix图形化DashBoard
#1.构建一个服务监控模块 ##1.1创建模块cloud-consumer-hystrix-dashboard9001 ##1.2pom文件依赖 <dependencies> <!- ...
- STM32F4寄存器初始化系列:GPIO
1 static void GPIO_Init(void) 2 { 3 4 //sound 5 GPIO_Set(GPIOB,PIN4,GPIO_MODE_OUT,GPIO_OTYPE_PP,GPIO ...
- C++梳理
1.基础篇 1.C++ 中的四种智能指针 为什么要使⽤智能指针:智能指针其作⽤是管理⼀个指针,避免程序员申请的空间在函数结束时忘记释放,造成内存泄漏这种情况的发⽣.使⽤智能指针可以很⼤程度上的避免这个 ...
- CF1638E Colorful Operations
\(\text{Solution}\) \(\text{code}\) #include <cstdio> #include <iostream> #include <s ...
- 流量加密之:MSF流量加密
流量加密之:MSF流量加密 目录 流量加密之:MSF流量加密 1 背景 2 生成SSL证书 3 使用MSF生成带证书的后门 4 验证流量 1 背景 在MSF中生成shell,并上线运行时.都是通过ht ...
- js(最新)手机号码 正则验证 - 代码篇
现在手机号码,除了以11+.12+开头的没有,别的好像都有了! 代码如下: 方法一: function checkPhone(){ var phone = $(".phone"). ...
- 计网学习笔记二 Link Layer Service
在上一周的计网学习了network和Internet的总论.在这一周开始的未来几讲将集中在链路层link layer,并且会有相应的计网lab完成.在这一讲中,我们主要关注链路层提供的服务. 课程资料 ...
- ubuntu 启动脚本变化
ubuntu-16.10 开始不再使用initd管理系统,改用systemd- 快速看了 systemd 的使用方法,发现改动有点大, 包括用 systemctl 命令来替换了 service 和 c ...