Gunner

 Accepts: 391
 Submissions: 1397
 Time Limit: 8000/4000 MS (Java/Others)
 Memory Limit: 65536/65536 K (Java/Others)
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.

 #include<stdio.h>
#include<string.h>
typedef long long ll ;
const int M = + ;
struct edge
{
int nxt ;
ll num ;
}e[M];
bool vis [M] ;
int H[M] , E ;
int cnt ;
int n , m ;
ll h ; void init ()
{
E = ;
memset (H , , sizeof(H)) ;
memset (vis , , sizeof(vis)) ;
} void Insert (ll x)
{
int y = x % M ;
if (y < ) y += M ;
e[++ E].nxt = H[y] ;
e[E].num = x ;
H[y] = E ;
} bool Find (ll x)
{
int y = x % M ;
if (y < ) y += M ;
for (int i = H[y] ; i ; i = e[i].nxt) {
if (e[i].num == x && vis[i]) {
return false ;
}
else if (e[i].num == x && !vis[i]) {
cnt ++ ;
vis[i] = true ;
}
}
} inline ll read () {
ll ans = ; char c; bool flag = false;
while ((c = getchar()) == ' ' || c == '\n' || c == '\r');
if (c == '-') flag = true; else ans = c - '';
while ((c = getchar()) >= '' && c <= '') ans = ans * + c - '';
return ans * (flag ? - : );
} int main ()
{
// freopen ("a.txt" , "r" , stdin ) ;
while (~ scanf ("%d%d" , &n , &m) ) {
init () ;
while (n--) {
h = read () ;
Insert (h) ;
}
while (m--) {
cnt = ;
h = read () ;
Find (h) ;
printf ("%d\n" , cnt) ;
}
}
return ;
}

BC.36.Gunner(hash)的更多相关文章

  1. 二分查找 BestCoder Round #36 ($) Gunner

    题目传送门 /* 题意:问值为x的个数有几个,第二次查询就是0 lower/upper_bound ()函数的使用,map也可过,hash方法不会 */ #include <cstdio> ...

  2. BC#32 1002 hash

    代码引用kuangbin大神的,膜拜 第一次见到hashmap和外挂,看来还有很多东西要学 维护前缀和sum[i]=a[0]-a[1]+a[2]-a[3]+…+(-1)^i*a[i] 枚举结尾i,然后 ...

  3. 并行HASH JOIN小表广播问题

    SQL语句: SELECT /*+parallel(t1 16)*/ T1.DATA_DATE, T1.ACCT_NO, T1.ACCT_ORD, T1.ACCT_NO_PK, T1.ACCT_BAL ...

  4. [20180705]关于hash join 2.txt

    [20180705]关于hash join 2.txt --//昨天优化sql语句,执行计划hash join right sna,加入一个约束设置XX字段not null,逻辑读从上万下降到50.- ...

  5. 以太坊(Ethereum) - 节点时间未同步和区块同步失败案例分析

    背景 以太坊技术搭建的区块链网络,节点间需要保证时间一致,才能正常有序的发送交易和生成区块,使得众多节点共同维护分布式账本(区块数据+状态数据).但是,网络中节点的系统时间不一致回出现什么现象呢,我们 ...

  6. 【转】使用SQL Tuning Advisor STA优化SQL

    SQL优化器(SQL Tuning Advisor STA)是Oracle10g中推出的帮助DBA优化工具,它的特点是简单.智能,DBA值需要调用函数就可以给出一个性能很差的语句的优化结果.下面介绍一 ...

  7. 如何用 SQL Tuning Advisor (STA) 优化SQL语句

    在Oracle10g之前,优化SQL是个比较费力的技术活,不停的分析执行计划,加hint,分析统计信息等等.在10g中,Oracle推出了自己的SQL优化辅助工具: SQL优化器(SQL Tuning ...

  8. avi 格式详解

    http://blog.csdn.net/becomly/article/details/6283004 http://blog.csdn.net/easecom/article/details/45 ...

  9. 优化大型复杂SQL

    with aa as (select a.agmt_id, sum(c.acct_bal) as card_bal, --借记卡期末存款余额 a.card_open_org, a.OPEN_DATE, ...

随机推荐

  1. 看牙与IT项目

    周末为了一颗牙第五次去牙科诊所,得到的消息是:还需要观察至少2周才能做牙冠,同时发现了较深的牙结石需要做刮治,刮治疗需要2次.因此至少要再去医院3次.从去年的六月体检发现这颗牙的问题,目前最乐观估计也 ...

  2. 两个简单的Loading

    置顶文章:<纯CSS打造银色MacBook Air(完整版)> 上一篇:<JavaScript并非"按值传递"> 作者主页:myvin 博主QQ:85139 ...

  3. php并发请求

    一般在php进行请求url的时候,直接用 fopen 函数就可以搞定了,比如像这样: $file=fopen("http://www.cnblogs.com","r&qu ...

  4. 机器学习中的矩阵方法03:QR 分解

    1. QR 分解的形式 QR 分解是把矩阵分解成一个正交矩阵与一个上三角矩阵的积.QR 分解经常用来解线性最小二乘法问题.QR 分解也是特定特征值算法即QR算法的基础.用图可以将分解形象地表示成: 其 ...

  5. Bootstrap3.0学习第二十四轮(JavaScript插件——按钮)

    详情请查看 http://aehyok.com/Blog/Detail/30.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:h ...

  6. Ibatis中传List参数

    Ibatis中用list传参数的方式. Java代码  select count(id) from `user` where id in #[]# and status=1 . <select ...

  7. PHP函数可变参数列表的具体实现方法介绍

    PHP函数可变参数列表可以通过_get_args().func_num_args().func_get_arg()这三个函数来实现.我们下面就对此做了详细的介绍. AD:2014WOT全球软件技术峰会 ...

  8. xml_MathML的基本知识点__这东西要自己实践最好

    1 : <mi> 一般的字符串 2: <mo> 操作字符串 <mo> ( </mo> <mo>∑</mo> 3:<mn&g ...

  9. 用php生成数据字典

    <?php header("Content-type: text/html; charset=utf-8"); $dbserver = "localhost&quo ...

  10. 【Matplotlib】 标注摄氏度符号

    之前论文中作图遇到的,其实也很简单. 关键的代码如下: ax.set_xlabel('Temperature ($^\circ$C)') 完整的样例代码如下: # -*- coding: utf-8 ...