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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. [CF1311C] Perform the Combo

    Solution 前缀和搞一下即可 #include <bits/stdc++.h> using namespace std; #define int long long const in ...

  4. 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 ...

  5. Codeforces Round #624 (Div. 3)(题解)

    Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...

  6. Codeforces Round #624 (Div. 3)(题解)

    A. Add Odd or Subtract Even 思路: 相同直接为0,如果两数相差为偶数就为2,奇数就为1 #include<iostream> #include<algor ...

  7. Codeforces #624 div3 C

    You want to perform the combo on your opponent in one popular fighting game. The combo is the string ...

  8. jquery Combo Select 下拉框可选可输入插件

    Combo Select 是一款友好的 jQuery 下拉框插件,在 PC 浏览器上它能模拟一个简单漂亮的下拉框,在 iPad 等移动设备上又能回退到原生样式.Combo Select 能够对选项进行 ...

  9. [转]Extjs combo数据绑定与获取

    原文地址:http://www.cnblogs.com/loveme123/archive/2012/05/10/2494466.html 1. 配置combo: {                  ...

  10. CDN的combo技术能把多个资源文件合并引用,减少请求次数

    CDN的combo技术能把多个资源文件合并引用,减少请求次数.比如淘宝的写法: <link rel="stylesheet" href="//g.alicdn.co ...

随机推荐

  1. Vue 07 js方法Object.defineProperty

    1 描述 该方法允许精确地添加或修改对象的属性.可以对已有的属性进行获取及修改,也可以添加新的属性并进行操作. 2 方法参数 Object.defineProperty(操作的对象,添加的属性的名称, ...

  2. 1.2.HBuilder软件与uniapp文件介绍

    uni-app官网地址 下载HBuilder 教程

  3. ubuntu20.04安装systemback

    sudo add-apt-repository --remove ppa:nemh/systemback sudo apt-key adv --keyserver keyserver.ubuntu.c ...

  4. 记一次使用tika解析文件文本导致的内存溢出问题

    背景 笔者曾供职于某信息安全公司,接到过一个需求,提取文档中的文本以供后续分析.tika是apache开源的解析文档内容的组件,应用十分广泛.tika几乎支持你能想到的所有文档格式,docx , pp ...

  5. ctfshow-web入门-SSTI学习

    千万要仔细,不要拼错单词 千万要仔细,不要拼错单词 千万要仔细,不要拼错单词 web 361 payload name={{[].__class__.__base__.__subclasses__() ...

  6. Fastjson Sec

    Fastjson 前置知识 autoType功能 序列化:fastjson在通过JSON.toJSONString()将对象转换为字符串的时候,当使用SerializerFeature.WriteCl ...

  7. WPF Xaml标签的一些特殊符号 如何输入

    小于号 <   输入 <  注意有分号 大于号 >   输入  > 符号 &   输入 & 引号 "  输入 "

  8. 面了几个说自己精通 Vue 的同学,实在一言难尽……

    请说一下响应式数据的原理 默认 Vue 在初始化数据时,会给 data 中的属性使用 Object.defineProperty 重新定义所有属性,当页面到对应属性时,会进行依赖收集 (收集当前组件中 ...

  9. go语言初记2(备忘)

     看<Go入门指南>,这里讲得比较基础,针对go 1.0版,以下是一些我自己觉得特别和不容易理解的地方的摘抄!  上次有说到go里不同类型之间操作必须显示转换,int和uint不固定,所以 ...

  10. conda创建和启动python虚拟环境

    conda与python虚拟环境 创建环境 conda create -n ENV_NAME python=3.9 激活环境 conda activate ENV_NAME 给虚拟环境安装包: con ...