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. 打开mmc后添加单元,出现停止工作的解决方法

    出现mmc停止工作,一般是其他软件的影响.关闭其他软件就可以了,但不知道是什么软件,所以只有进入干净状态.(也可以进入安全模式) 1.如何进入干净启动状态: ===================== ...

  2. 【niubi-job——一个分布式的任务调度框架】----框架设计原理以及实现

    引言 niubi-job的框架设计是非常简单实用的一套设计,去掉了很多其它调度框架中,锦上添花但并非必须的组件,例如MQ消息通讯组件(kafka等).它的框架设计核心思想是,让每一个jar包可以相对之 ...

  3. QRadioButton分组且无边框的简单实现

    最近在用QT+VS2008做一个项目,涉及到一个综合测评表,说白了有点像问卷调查——很多题目每题若干个选项. 初始时打算用下拉框,每个框中填入所有选项,但后来一琢磨这种方式不够直观与人性化,增添了一步 ...

  4. Cordova4.0 系列 -- 基本环境搭建(1)

    一. 安装Node.js基本环境 官网下载地址:https://nodejs.org/ 安装成功之后可以使用简单命令查看其版本 node -v npm相关命令 node cli.js install ...

  5. linux用户管理命令

    关键字 useradd passwd who w uptime 1.useradd添加用户命令 useradd 用户名 passwd 用户名 (设置密码) 2.userdel 删除用户 userdel ...

  6. HTML5——地图应用

    我们就拿百度地图举例吧: 废话少说,直接上Demo 简要截图如下:' 简要代码如下: <!DOCTYPE html> <html> <head> <title ...

  7. Linux下巧用my.cnf,mysql连接服务器不需要输入账号密码信息

    Linux下每次用mysql连接连接服务器,常常用如下方式: [root@localhost ~]# mysql -hlocalhost -uroot -p11111 每次都输入用户名,密码,多折腾人 ...

  8. iOS开发中的错误整理,启动图片设置了没有效果;单独创建xib需要注意的事项;图片取消系统渲染的快捷方式

    一.启动图片设置了没有效果 解决方案:缓存啊!卸了程序重新安装吧!!!!! 二.单独创建xib需要注意的事项 三.图片取消系统渲染的快捷方式

  9. 【BZOJ 3143】【Hnoi2013】游走 期望+高斯消元

    如果纯模拟,就会死循环,而随着循环每个点的期望会逼近一个值,高斯消元就通过列方正组求出这个值. #include<cstdio> #include<cctype> #inclu ...

  10. 【Java线程】Callable和Future

    Future模式 Future接口是Java线程Future模式的实现,可以来进行异步计算. Future模式可以这样来描述: 我有一个任务,提交给了Future,Future替我完成这个任务.期间我 ...