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. C# 有关命名法

    常用的几种:匈牙利命名法,骆驼命名法,帕斯卡(pascal)命名法就说了. 总结下VS所用的标准命名: 1 ADO.NET 命名规范 数据类型 数据类型简写 标准命名举例 Connection con ...

  2. 人家为撩妹就鼓捣个网页,我做了个约炮APP(已开源)

    每年初夏第一场雷雨刚过,漫步河边的草坪,总是能闻到伴随着泥土的清新,这不是coco的前香,让人神魂颠倒:也不是gucci的后香,让人痴迷如梦.如24节气一样,它提醒人们,夏天到了.昨晚成都下了第一场雷 ...

  3. IT男的”幸福”生活"续8

    有段时间没写了,还是有点怀念的.   生活不记录下,怕真地会忘.. 以往的种种,时时刻刻回荡在我的脑海中,  最近看着孩子生活照, 猛得回首我便回了到了 续8. …… 坐在回去的公交车上,看着前面两M ...

  4. [C/C++基础] C语言常用函数sprintf和snprintf的使用方法

    Sprintf 函数声明:int sprintf(char *buffer, const char *format [, argument1, argument2, …]) 用途:将一段数据写入以地址 ...

  5. 第四章 一切从IL开始

    从这一部分开始,就开始讲.net的本质了,这第四章就是讲有关IL(中间语言)的内容,主要利用工具,看看VS到底编译出来的是什么东西,从中我们可以看到实现的方式和过程.有助于我们更好的了解.net的本质 ...

  6. Cordova4.0 系列 -- 常用命令(2)

    一. 创建一个cordova工程 create <directory> [<id> [<name>]] 二. 列出该工程支持哪些平台 platform [ls | ...

  7. 备忘:SSRS技巧三则

    前言 最近在弄SSRS,发现了三个小技巧.在此记录一下.免得以后忘了. 技巧 1. SSRS输出成EXCEL时,让两个dataset各占一个sheet, 这个简单,在其中一个table的属性加上pag ...

  8. redmine慢---提速方法

    最近readmine速度越来越慢.网上查了一下,把其自带的服务器webrick 换成为mongrel,可以解决这个问题,具体操作方法如下,方法: gem install mongrel 如果提示类似“ ...

  9. FZU5BOYS-Beta版本冲刺计划及安排

    1.下一阶段需要改进完善的功能 话题模块(分类参考Citeulike论文网站),文章/计划的删除功能 2.下一阶段新增的功能 1)推荐模块(冷启动问题,拟爬取部分豆瓣数据,部分伪专家数据(我们团队), ...

  10. 视频播放实时记录日志并生成XML文件

    需求描述: 在JWPlayer视频播放过程中,要求实时记录视频观看者播放.暂停的时间,并记录从暂停到下一次播放时所经过的时间.将所有记录保存为XML文件,以方便数据库的后续使用. 实现过程: 尝试1: ...