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 ...
随机推荐
- 【DS】1.1
1.概念: 数据项:最小单位 数据对象:相同性质的数据元素集合 数据结构:关系 集合 同样的数据元素可组成不同的数据结构不同数据元素也可以组成相同的数据结构 2.三要素: 逻辑结构:集合(不考)线性结 ...
- 学习Java Day13
今天学习了对象与类,类是构造对象的模板或蓝图.由类构造对象的过程称为创建类的实例.类与类之间的关系有依赖,聚合,继承. 然后学习了如何构造对象.
- 解决VS2019 DevExpress工具不显示问题
一.序言 环境:NetFramework4.5,vs2019社区板 ,DevExpress 14.2.3 项目类型:winfrom 二.解决 找到DevExpress安装路径下的Bin\Framewo ...
- Java基础语法:注释、数据类型、字节
Java基础语法:注释.数据类型.字节 注释 单行注释:// 多行注释:/* 注释 */ 文档注释:/** 注释 */ 数据类型分为两大类:基本类型和引用类型 八大基本数据类型 整数类型 byte(占 ...
- python下载图片实现方法
转载: https://www.jb51.net/article/119178.htm
- 登峰造极,师出造化,Pytorch人工智能AI图像增强框架ControlNet绘画实践,基于Python3.10
人工智能太疯狂,传统劳动力和内容创作平台被AI枪毙,弃尸尘埃.并非空穴来风,也不是危言耸听,人工智能AI图像增强框架ControlNet正在疯狂地改写绘画艺术的发展进程,你问我绘画行业未来的样子?我只 ...
- pat乙级 1018 锤子 剪刀 布
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> int ...
- sqlserver update join
update a set a.UserAgent = b.UserAgent from InfoVisitDetails a inner join InfoVisitDetails b on a.IP ...
- 溢出标志位OF与进位标志位CF判断
1.OF与CF概述 OF(Overflow Flag,溢出标志位):有符号数之间加减运算的溢出标志 CF(Carry Flag,进位标志位):无符号数之间加减运算的溢出标志 快速判断(加法)(减法可转 ...
- day11_多态&抽象类&接口
1.多态 1.1 多态的概述(记忆) 什么是多态 同一对象,在不同时刻表现出来的不同形态. 多态的前提 有继承/实现关系 有方法重写 有父类对象的引用执行子类对象 1.2 多态中的成员访问特点 ...