HDU 5199

Gunner

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 1323    Accepted Submission(s): 586

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?th bird
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 ($)

#include <cstdio>
#include <iostream>
#include <map>

using namespace std;
#define maxn 1000000 + 10

int n, m;
map<int, int> M;

int main()
{
    while(~scanf("%d%d", &n, &m))
    {
        int t;
        M.clear();
        for(int i=0; i<n; i++)
        {
            scanf("%d", &t);
            M[t]++;
        }
        for(int i=0; i<m; i++)
        {
            scanf("%d", &t);
            if(M[t])
            {
                printf("%d\n", M[t]);
                M.erase(t);
            }
            else
                printf("0\n");
        }
    }
    return 0;
}
时间: 2024-10-06 02:22:05

HDU 5199的相关文章

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 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 fr

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 - 5198 - Strange Class &amp;&amp; 5199 - Gunner

Strange Class Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 74    Accepted Submission(s): 60 Problem Description In Vivid's school, there is a strange class(SC). In SC, the students' names ar

hdoj 5199 Gunner map

Gunner Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5199 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

HDU 6203 ping ping ping [LCA,贪心,DFS序,BIT(树状数组)]

题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=6203] 题意 :给出一棵树,如果(a,b)路径上有坏点,那么(a,b)之间不联通,给出一些不联通的点对,然后判断最少有多少个坏点. 题解 :求每个点对的LCA,然后根据LCA的深度排序.从LCA最深的点对开始,如果a或者b点已经有点被标记了,那么continue,否者标记(a,b)LCA的子树每个顶点加1. #include<Bits/stdc++.h> using namespace std;

HDU 5542 The Battle of Chibi dp+树状数组

题目:http://acm.hdu.edu.cn/showproblem.php?pid=5542 题意:给你n个数,求其中上升子序列长度为m的个数 可以考虑用dp[i][j]表示以a[i]结尾的长度为j的上升子序列有多少 裸的dp是o(n2m) 所以需要优化 我们可以发现dp的第3维是找比它小的数,那么就可以用树状数组来找 这样就可以降低复杂度 #include<iostream> #include<cstdio> #include<cstring> #include

hdu 1207 汉诺塔II (DP+递推)

汉诺塔II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4529    Accepted Submission(s): 2231 Problem Description 经典的汉诺塔问题经常作为一个递归的经典例题存在.可能有人并不知道汉诺塔问题的典故.汉诺塔来源于印度传说的一个故事,上帝创造世界时作了三根金刚石柱子,在一根柱子上从下往

[hdu 2102]bfs+注意INF

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2102 感觉这个题非常水,结果一直WA,最后发现居然是0x3f3f3f3f不够大导致的--把INF改成INF+INF就过了. #include<bits/stdc++.h> using namespace std; bool vis[2][15][15]; char s[2][15][15]; const int INF=0x3f3f3f3f; const int fx[]={0,0,1,-1};