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 ...
随机推荐
- Vue11 vue的data中属性的值(基础数据类型和对象)
1 代码 <body> <div id="root"> <h1>{{name}}</h1> <h1>{{obj}}< ...
- Html音频播放代码
页面代码: <html> <head> <script src="https://code.jquery.com/jquery-3.1.1.min.js&quo ...
- 1 - 【RocketMQ 系列】CentOS 7.6 安装部署RocketMQ
一.前置准备工作 CentOS 7.6 安装 jdk1.8 openjdk 1.查看JDK版本 yum search java|grep jdk 2.安装jdk1.8,安装默认的目录为: /usr/l ...
- 数值的扩展方法以及新增数据类型BigInt
二进制和八进制表示法 ES6提供了二进制和八进制数值的新的写法,分别用前缀0b(或0B)和0o或(0O)表示 0b111110111 === 503 // true; 0o767 === 503; / ...
- Win下依据端口排查步骤
Win下依据端口排查步骤 目录 Win下依据端口排查步骤 1 排查步骤 2 参考 今天突然发现自己电脑出现7680端口的内网连接,决定看看这个端口是做什么用的 1 排查步骤 确认7680端口连接情况与 ...
- 补充人物pawn的旋转方向
先找到控制pawn的控制器的Rotation GetControlRotaion() 然后获得控制器的Z轴旋转 创建新的Rotator YawRotaion(0,GetControlRotaion() ...
- CPU L1,L2,L3多级缓存的基本作用
基本作用 加快CPU与主内存之间的数据交换. 区别 缓存类型 L1 L2 L3 位置 最靠近CPU核心 次之 再次之 容量 一般几十KB~几百KB 几百KB~几MB 几MB~几十MB 速度 几个时钟周 ...
- k8s-分布式系统架构master-worker
K8S系列一:概念入门 - 知乎 (zhihu.com) 大白话先了解k8s. k8s是为容器服务而生的一个可移植容器的编排管理工具 概述 Master-Workers 架构(粗译为主从架构)是分布式 ...
- org.elasticsearch.ElasticsearchException: not all primary shards of [.geoip_databases] index are active解决办法
解决办法 在配置elasticsearch.yml中加上 ingest.geoip.downloader.enabled: false
- Linux与Windows对比
1. 前言 Windows是微软为个人台式机/设备或电脑(PC)开发的一系列操作系统.计算机操作系统(OS).每个操作系统都有一个图形用户界面(GUI),桌面允许用户查看所有文件.视频等.Window ...