hdu 5199 Gunner(STL之map,水)

Problem Description

Long long ago, there is a gunner whose name is Jack. He likes to go hunting very much. One day he go to the grove. There are n birds and n trees. The i−thbird stands on the top of the i−th tree. The trees stand in straight line from left to the right. Every tree has its height. Jack stands on the left side of the left most tree. When Jack shots a bullet in height H to the right, the bird which stands in the tree with height H will falls.
Jack will shot many times, he wants to know how many birds fall during each shot.

a bullet can hit many birds, as long as they stand on the top of the tree with height of H.

Input

There are multiple test cases (about 5), every case gives n,m in the first line, n indicates there are n trees and n birds, m means Jack will shot m times.

In the second line, there are n numbers h[1],h[2],h[3],…,h[n] which describes the height of the trees.

In the third line, there are m numbers q[1],q[2],q[3],…,q[m] which describes the height of the Jack’s shots.

Please process to the end of file.

[Technical Specification]

1≤n,m≤1000000(106)

1≤h[i],q[i]≤1000000000(109)

All inputs are integers.
 

Output

For each q[i], output an integer in a single line indicates the number of birds Jack shot down.

Sample Input

4 3
1 2 3 4
1 1 4

Sample Output

1
0
1

Hint


Huge input, fast IO is recommended.

 

Source

BestCoder Round #36 ($)

用map保存数量即可。

 1 #pragma comment(linker, "/STACK:1024000000,1024000000")
 2 #include<iostream>
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<cmath>
 6 #include<math.h>
 7 #include<algorithm>
 8 #include<queue>
 9 #include<set>
10 #include<bitset>
11 #include<map>
12 #include<vector>
13 #include<stdlib.h>
14 #include <stack>
15 using namespace std;
16 #define PI acos(-1.0)
17 #define max(a,b) (a) > (b) ? (a) : (b)
18 #define min(a,b) (a) < (b) ? (a) : (b)
19 #define ll long long
20 #define eps 1e-10
21 #define MOD 1000000007
22 #define N 1000000
23 #define inf 1e12
24 int n,m;
25 map<int,int>mp;
26 int main()
27 {
28    while(scanf("%d%d",&n,&m)==2){
29       mp.clear();
30       for(int i=0;i<n;i++){
31          int x;
32          scanf("%d",&x);
33          mp[x]++;
34       }
35       for(int i=0;i<m;i++){
36          int x;
37          scanf("%d",&x);
38          printf("%d\n",mp[x]);
39          mp[x]=0;
40       }
41    }
42     return 0;
43 }

时间: 2024-10-08 03:27:03

hdu 5199 Gunner(STL之map,水)的相关文章

HDU Bombing (STL multiset+map)

题意:给你 n 个坐标(x,y),m 个询问(c,d) c==0,求出x==d有多少个,并删除这些点: c==1,求出y==d有多少个,并删除这些点. map+multiset的多重映射 #include<cstdio> #include<stdlib.h> #include<string.h> #include<string> #include<map> #include<cmath> #include<iostream>

hdu 5199 Gunner

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5199 简单题,stl水之... 1 #include<algorithm> 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstring> 5 #include<cstdio> 6 #include<set> 7 #include<map> 8 using std::m

HDU 2352 Verdis Quo (map 水)

#include<stdio.h> #include<string.h> #include<math.h> #include<iostream> #include<algorithm> #include<map> using namespace std; map <char,int> a; int main() { a['I']=1; a['V']=5; a['X']=10; a['L']=50; a['C']=100;

hdu 5199 Gunner (hash || 排序+二分)

题意:有n个不同高度的树排成一列,树上各有1只鸟. 然后m个询问,每次询问可以打掉h[i](1<=i<=m)高度的所有鸟,问m个询问中的各高度能打掉多少只鸟. 分析: 1.题目给了提示要 “快速读入”  咩~ 2.排序+二分 这里可以两次二分(lower_bound找下界,upper_bound找上界) 也可以合并+二分(合并相同的数字,记录次数) g++提交要用#include<stdio.h> 不要用#include<cstdio> 后者有效率问题,会 tle (⊙

hdu 1251 统计难题 (map水过)

# include <stdio.h> # include <algorithm> # include <string.h> # include <map> # include <iostream> using namespace std; int main() { char a; string x; map<string,int>q; while(true) { scanf("%c",&a); if(a=

STL HDOJ 5199 Gunner

题目传送门 1 /* 2 题意:问值为x的个数有几个,第二次查询就是0 3 lower/upper_bound ()函数的使用,map也可过,hash方法不会 4 */ 5 #include <cstdio> 6 #include <cmath> 7 #include <cstring> 8 #include <algorithm> 9 #include <iostream> 10 #include <vector> 11 #incl

hdu 4941 stl的map&lt;node,int&gt;用法

#include<iostream> #include<cstdio> #include<cstring> #include<map> using namespace std; typedef struct node{ int x,y; bool operator<(const node &b)const { if(x==b.x) return y<b.y; else return x<b.x; } }node; int main(

HDU 2112 HDU Today(STL MAP + Djistra)

题目链接:HDU Today 立即集训要開始,抓紧时间练练手,最短路的基础题,第一次用STL的map 题目非常水,可是错了N遍.手贱了.本题不优点理的就是把地名转化为数字 #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <map> #define N 155 #define INF 1e7 using namespace

HDU 4022 Bombing(stl,map,multiset,iterater遍历)

题目 参考了     1     2 #define _CRT_SECURE_NO_WARNINGS //用的是STL中的map 和 multiset 来做的,代码写起来比较简洁,也比较好容易理解. //multiset可以允许重复 //multiset<int>::iterator it; 用来遍历 #include<stdio.h> #include<string.h> #include<algorithm> #include<iostream&g