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 ...
随机推荐
- P29_全局配置 - window - 导航栏
window 了解 window 节点常用的配置项 设置导航栏的标题 设置步骤:app.json -> window -> navigationBarTitleText 需求:把导航栏上的 ...
- shrio
Shrio 页面报错 <link rel="shortcut icon" href="#"/> 简单的安全框架 官网:https://shiro.a ...
- OWASP 靶机下载
OWASP靶机下载安装详细过程一. OWASP靶机下载二. VM虚拟机三. OWASP安装四. OWASP启动运行一. OWASP靶机下载下载地址:https://sourceforge.net/pr ...
- python爬虫学习——文件操作,异常处理
文件操作 ''' f = open("a.txt","w") #打开一个文件, w模式(写),如果文件不存在就在当前目录下创建 f.write("he ...
- FPS 逆向 CS.起源 绘制 教程(下周完成笔记)
1.找到人物坐标X YZ2.找到鼠标X Y3.易语言读取人物坐标4.读取敌人坐标打开控制台服务器与客户端尽量找客户端 找到XYZ5.实时读取敌人坐标6.三角函数转换屏幕坐标FOV 视场角狙击枪找FOV ...
- LAMP环境搭建——最详细的手工编译
环境:阿里云服务器ECS,Alibaba Cloud Linux 3.2104 LTS 64位 ,2核(vCPU) 2 GiB LAMP 是搭建Web应用时最常用的环境,LAMP 分别表示 Linux ...
- SpringBoot2.6.x及以上版本整合swagger文档
SpringBoot的版本更新中引入了一些新的特性,并且Swagger的版本更新也同样引入了很多新的东西,这样就造成了许多配置无法实现一一对应的情况,因此高版本的SpringBoot集成Swagger ...
- 基于官方Chrome、Firefox软件包得到便携版
1. 前言 安装好操作系统后,一般系统都带有浏览器,比如,Windows 10 自带Edge.Ubuntu 自带Firefox等等.有的时候我们想使用一下别的浏览器或者是别的版本(如,开发者版),可是 ...
- PostgreSQL 打印详细错误调用栈 - pg_backtrace
一.用法 create extension pg_backtrace; select pg_backtrace_init(); 二.示例 postgres=# select count(*)/0.0 ...
- 理论+实战,详解Sharding Sphere-jdbc
摘要:Apache ShardingSphere 是一款分布式的数据库生态系统,它包含两大产品:ShardingSphere-Proxy和ShardingSphere-JDBC. 本文分享自华为云社区 ...