题目传送门

 /*
题意:查询x的id,每次前排的树倒下
使用lower_bound ()查找高度,f[i]记录第一棵高度为x树的位置,查询后+1(因为有序)
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
struct A
{
int v, id;
bool operator < (const A &x) const
{
if (v == x.v) return id < x.id;
return v < x.v;
}
}a[MAXN];
int h[MAXN], f[MAXN]; inline int read(void)
{
int x = , f = ; char ch = getchar ();
while (ch < '' || ch > '') {if (ch == '-') f = -; ch = getchar ();}
while (ch >='' && ch <= '') {x = x * + ch - ''; ch = getchar ();}
return f * x;
} int main(void) //HDOJ 5233 Gunner II
{
int n, q;
while (scanf ("%d%d", &n, &q) == )
{
for (int i=; i<=n; ++i) {a[i].v = read (); a[i].id = i;}
sort (a+, a++n);
for (int i=; i<=n; ++i)
{
f[i] = i; h[i] = a[i].v;
}
while (q--)
{
int x, p; scanf ("%d", &x);
p = lower_bound (h+, h++n, x) - h;
if (h[f[p]] != x) {puts ("-1"); continue;}
printf ("%d\n", a[f[p]].id);
f[p]++;
}
} return ;
} /*
5 5
1 2 3 4 1
1 3 1 4 2
*/

二分查找 BestCoder Round #42 1002 Gunner II的更多相关文章

  1. 贪心/二分查找 BestCoder Round #43 1002 pog loves szh II

    题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每 ...

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

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

  3. 矩阵快速幂---BestCoder Round#8 1002

    当要求递推数列的第n项且n很大时,怎么快速求得第n项呢?可以用矩阵快速幂来加速计算.我们可以用矩阵来表示数列递推公式比如fibonacci数列 可以表示为 [f(n)   f(n-1)] = [f(n ...

  4. 暴力+降复杂度 BestCoder Round #39 1002 Mutiple

    题目传送门 /* 设一个b[]来保存每一个a[]的质因数的id,从后往前每一次更新质因数的id, 若没有,默认加0,nlogn复杂度: 我用暴力竟然水过去了:) */ #include <cst ...

  5. Manacher BestCoder Round #49 ($) 1002 Three Palindromes

    题目传送门 /* Manacher:该算法能求最长回文串,思路时依据回文半径p数组找到第一个和第三个会文串,然后暴力枚举判断是否存在中间的回文串 另外,在原字符串没啥用时可以直接覆盖,省去一个数组空间 ...

  6. 二分图判定+点染色/并查集 BestCoder Round #48 ($) 1002 wyh2000 and pupil

    题目传送门 /* 二分图判定+点染色:因为有很多联通块,要对所有点二分图匹配,若不能,存在点是无法分配的,no 每一次二分图匹配时,将点多的集合加大最后第一个集合去 注意:n <= 1,no,两 ...

  7. hdu 5195 DZY Loves Topological Sorting BestCoder Round #35 1002 [ 拓扑排序 + 优先队列 || 线段树 ]

    传送门 DZY Loves Topological Sorting Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131 ...

  8. BestCoder Round #36 [B] Gunner

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5199 先对树的高度排序,然后对每次射击高度二分查找即可,打过之后数目变为0. #include< ...

  9. ACM学习历程—HDU5592 ZYB's Premutation(逆序数 && 树状数组 && 二分)(BestCoder Round #65 1003)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5592 题目大意就是给了每个[1, i]区间逆序对的个数,要求复原原序列. 比赛的时候2B了一发. 首先 ...

随机推荐

  1. xamarin.android searchview的一些用法

    前言 searchview是安卓常用的搜索控件,网上有很多关于searchview都是java的,所以我参看xamaroin官网的一些demo总结一些方法. 导读 1.如何创建一个searchview ...

  2. matlab max函数

    >> a=[1,6,3;7,5,6] a = 1 6 3 7 5 6 >> [q,p]=max(a,[],2) 返回每行最大值,q是结果.p是索引 q = 6 7 p = 2 ...

  3. About "self"

    Class method can't refer derectly to instance variables. Within the body of  a class method, self re ...

  4. golang-----golang sync.WaitGroup解决goroutine同步

    go提供了sync包和channel来解决协程同步和通讯.新手对channel通道操作起来更容易产生死锁,如果时缓冲的channel还要考虑channel放入和取出数据的速率问题. 从字面就可以理解, ...

  5. js遍历map

    //火狐控制台打印输出: Object { fileNumber="文件编号", fileName="文件名称"} console.log(map); for( ...

  6. 解决ubuntu没有/var/log/messages的问题

    1:root身份打开 /etc/rsyslog.d/50-default.conf 2:把注释#去掉 #*.=info;*.=notice;*.=warn;\ # auth,authpriv.none ...

  7. Why is an 'Any CPU' application running as x86 on a x64 machine?

      It's likely that you linked some assemblies that are not Any CPU, but include native code (or are ...

  8. BestCoder5 1001 Poor Hanamichi(hdu 4956) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4956(它放在题库后面的格式有一点点问题啦,所以就把它粘下来,方便读者观看) 题目意思:给出一个范围 [ ...

  9. codeforces 440C. One-Based Arithmetic 解题报告

    题目链接:http://codeforces.com/problemset/problem/440/C 题目意思:给出一个数你,问需要用到的1来组成这个数的最少数量是多少. 我一开始对每个数只从 “+ ...

  10. HDUoj4857逃生 拓扑排序

    逃生 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...