BC.36.Gunner(hash)
Gunner
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.
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.
For each q[i], output an integer in a single line indicates the number of birds Jack shot down.
4 3
1 2 3 4
1 1 4
1
0
1
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)的更多相关文章
- 二分查找 BestCoder Round #36 ($) Gunner
题目传送门 /* 题意:问值为x的个数有几个,第二次查询就是0 lower/upper_bound ()函数的使用,map也可过,hash方法不会 */ #include <cstdio> ...
- BC#32 1002 hash
代码引用kuangbin大神的,膜拜 第一次见到hashmap和外挂,看来还有很多东西要学 维护前缀和sum[i]=a[0]-a[1]+a[2]-a[3]+…+(-1)^i*a[i] 枚举结尾i,然后 ...
- 并行HASH JOIN小表广播问题
SQL语句: SELECT /*+parallel(t1 16)*/ T1.DATA_DATE, T1.ACCT_NO, T1.ACCT_ORD, T1.ACCT_NO_PK, T1.ACCT_BAL ...
- [20180705]关于hash join 2.txt
[20180705]关于hash join 2.txt --//昨天优化sql语句,执行计划hash join right sna,加入一个约束设置XX字段not null,逻辑读从上万下降到50.- ...
- 以太坊(Ethereum) - 节点时间未同步和区块同步失败案例分析
背景 以太坊技术搭建的区块链网络,节点间需要保证时间一致,才能正常有序的发送交易和生成区块,使得众多节点共同维护分布式账本(区块数据+状态数据).但是,网络中节点的系统时间不一致回出现什么现象呢,我们 ...
- 【转】使用SQL Tuning Advisor STA优化SQL
SQL优化器(SQL Tuning Advisor STA)是Oracle10g中推出的帮助DBA优化工具,它的特点是简单.智能,DBA值需要调用函数就可以给出一个性能很差的语句的优化结果.下面介绍一 ...
- 如何用 SQL Tuning Advisor (STA) 优化SQL语句
在Oracle10g之前,优化SQL是个比较费力的技术活,不停的分析执行计划,加hint,分析统计信息等等.在10g中,Oracle推出了自己的SQL优化辅助工具: SQL优化器(SQL Tuning ...
- avi 格式详解
http://blog.csdn.net/becomly/article/details/6283004 http://blog.csdn.net/easecom/article/details/45 ...
- 优化大型复杂SQL
with aa as (select a.agmt_id, sum(c.acct_bal) as card_bal, --借记卡期末存款余额 a.card_open_org, a.OPEN_DATE, ...
随机推荐
- 整理sqlserver 级联更新和删除 c#调用存储过程返回值
整理一下级联更新和删除 c#调用返回值 use master go IF exists(select 1 from sysdatabases where name='temp') BEGIN DROP ...
- PRML读书会第一章 Introduction(机器学习基本概念、学习理论、模型选择、维灾等)
主讲人 常象宇 大家好,我是likrain,本来我和网神说的是我可以作为机动,大家不想讲哪里我可以试试,结果大家不想讲第一章.估计都是大神觉得第一章比较简单,所以就由我来吧.我的背景是统计与数学,稍懂 ...
- IIS7 IIS7.5 配置备份
IIS 7 提供了一个新的命令行工具 Appcmd.exe,可以使用该工具来配置和查询 Web 服务器上的对象,并以文本或 XML 格式返回输出. IIS 备份还原命令如下: 开始-运行-CMD 进入 ...
- JS的解析机制
JS的解析机制,是JS的又一大重点知识点,在面试题中更经常出现,今天就来唠唠他们的原理.首先呢,我们在我们伟大的浏览器中,有个叫做JS解析器的东西,它专门用来读取JS,执行JS.一般情况是存在作用域就 ...
- MYSQL查询语句优化
mysql的性能优化包罗甚广: 索引优化,查询优化,查询缓存,服务器设置优化,操作系统和硬件优化,应用层面优化(web服务器,缓存)等等.这里的记录的优化技巧更适用于开发人员,都是从网络上收集和自己整 ...
- springmore-让编程更容易
这是我多年项目的总结,并将其抽象出来,形成一个开源的项目 部分借鉴springside,将更多的实践总结进来 基于spring+ibatis+springMVC springmore-core专注于一 ...
- WCF入门(12)
前言 上次写是小半年前的事情了,还在原来的公司,还在原来的项目,同时认识了不少人.外包公司总是有些不适应的地方,总在很闲和很忙之间徘徊.凌晨2点被客户电话叫醒,只为copy一个文件从一台服务器到另一台 ...
- Memcached——分布式缓存
下载文件:https://sourceforge.net/projects/memcacheddotnet/ 将Commons.dll,ICSharpCode.SharpZipLib.dll,log4 ...
- iOS开发小技巧--设置按钮圆角
方法一:代码设置 方法二:通过图形化界面
- iOS边练边学--级联菜单的两种实现方法
一.方法1:如图,图中的两个tableView分别交给两个控制器来管理 重点难点:categoryTableView被点击之后,subcategoryTableView要取得相应的数据进行刷新,所以s ...