Ultimate Array
来源:互联网 发布:linux 调整时区 编辑:程序博客网 时间:2024/06/05 02:32
Think:
方案1 : 直接用一个map<long long int, int>;来进行储存即可。
方案2 : 字典树解题
Problem Description
bLue 这次又获得了一个更厉害的数组,欣喜之余,他想知道某个数字在数组中出现了多少次,你能帮助他吗?
Input
输入数据有多组(数据组数不超过 20),到 EOF 结束。
对于每组数据:
第 1 行输入 2 个用空格隔开的整数 n, q (1 <= n, q <= 10^5),分别表示数组中数字的个数和询问的次数。
第 2 行输入 n 个用空格隔开的整数 ai (0 <= ai <= 10^9),表示数组中的数字。
接下来 q 行,每行输入一个整数 v (0 <= v <= 10^9),表示要询问的数字。
Output
对于每组数据:
每次询问输出一行,包含一个整数,表示 bLue 询问的数字在数组中出现的次数。
每组数据末尾输出一行空行。
Example Input
6 4
2 0 2 666 666 2
0
2
666
7
Example Output
1
3
2
0
Author
「2017年寒假集训 结训赛2」bLue
#include<bits/stdc++.h>using namespace std;int main(){ int n, m; int key; while(cin >> n >> m) { map<long long int, int>Map; while(n --) { cin >> key; Map[key] ++; } while(m --) { cin >> key; cout << Map[key] << endl; } cout << endl; }}
阅读全文
0 0
- Ultimate Array
- Ultimate Array
- Ultimate Array
- The Ultimate Bash Array Tutorial with 15 Examples
- CodeForces 671C - Ultimate Weirdness of an Array
- Codeforces 672E:Ultimate Weirdness of an Array 线段树
- Codeforces Round #352 ——Ultimate Weirdness of an Array
- SDUT 3832 Ultimate Array 之哈希表链式法
- Codeforces problem 671C Ultimate Weirdness of an Array - 线段树
- Codeforces 672 E:Ultimate Weirdness of an Array 线段树 ★ ★ ★
- Ultimate toolbox
- Ultimate Grid
- VNC Ultimate
- Ultimate Action
- vs2013 Ultimate
- Ultimate ToolBox 界面库
- Ultimate toolbox实用工具类
- Linksys WRT54G Ultimate Hacking
- Java 中的堆和栈
- color/box-flex/transition/inline-block/outline/:not()
- dapper-fastcrud
- 携程酒店自动化360度质量保障体系
- 感染力的六个原则
- Ultimate Array
- js中的左查询和右查询
- leetcode--Longest Substring Without Repeating Characters
- 扇区 块 缓冲区 页框
- Spring(16)——使用注解进行bean定义
- 对Windows下的Socket通信进行封装
- POJ 1061 青蛙的约会 拓展欧几里得 经典题
- POI解析
- mybatis+springmvc+miniui实战开发基本知识点