【Codeforces Round 367 (Div 2) B】【二分查找】Interesting drink
来源:互联网 发布:淘宝厂家直销标签 编辑:程序博客网 时间:2024/06/02 20:22
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in n different shops in the city. It's known that the price of one bottle in the shop i is equal to xi coins.
Vasiliy plans to buy his favorite drink for q consecutive days. He knows, that on the i-th day he will be able to spent mi coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains n integers xi (1 ≤ xi ≤ 100 000) — prices of the bottles of the drink in the i-th shop.
The third line contains a single integer q (1 ≤ q ≤ 100 000) — the number of days Vasiliy plans to buy the drink.
Then follow q lines each containing one integer mi (1 ≤ mi ≤ 109) — the number of coins Vasiliy can spent on the i-th day.
Print q integers. The i-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the i-th day.
53 10 8 6 114110311
0415
On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop.
#include<stdio.h>#include<iostream>#include<string.h>#include<string>#include<ctype.h>#include<math.h>#include<set>#include<map>#include<vector>#include<queue>#include<bitset>#include<algorithm>#include<time.h>using namespace std;void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }#define MS(x,y) memset(x,y,sizeof(x))#define MC(x,y) memcpy(x,y,sizeof(x))#define MP(x,y) make_pair(x,y)#define ls o<<1#define rs o<<1|1typedef long long LL;typedef unsigned long long UL;typedef unsigned int UI;template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }const int N = 1e5 + 10, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;int n;int a[N];int q;int main(){while (~scanf("%d", &n)){for (int i = 1; i <= n; ++i)scanf("%d", &a[i]);sort(a + 1, a + n + 1);scanf("%d", &q);while (q--){int x; scanf("%d", &x);printf("%d\n", upper_bound(a + 1, a + n + 1, x) - a - 1);}}return 0;}/*【trick&&吐槽】upper_bound()是返回第一个>x的数的下标lower_bound()是返回第一个>=x的数的下标*/
- 【Codeforces Round 367 (Div 2) B】【二分查找】Interesting drink
- Codeforces Round #367 (Div. 2) B Interesting drink【二分】
- Codeforces Round #367 (Div. 2) B Interesting drink(二分)
- Codeforces Round #367 (Div. 2) B. Interesting drink (二分)
- Codeforces Round #367 (Div. 2) B. Interesting drink (二分)
- Codeforces Round #367 (Div. 2) B. Interesting drink(二分)
- Codeforces Round #367 (Div. 2) [B] Interesting drink
- Codeforces Round #367 (Div. 2) B. Interesting drink 树状数组
- Codeforces Round #367 (Div. 2) B - Interesting drink
- Codeforces Round #367 (Div. 2) B Interesting drink
- Codeforces Round #367 (Div. 2) B. Interesting drink 离线操作
- Codeforces #367 B. Interesting drink(二分)
- Codeforces #367(Div.2)B Interesting drink【树状数组】
- codeforces 706B B. Interesting drink (二分)
- codeforces-367#B. Interesting drink
- 【Codeforces】-706B-Interesting drink(二分)
- 【二分】Codeforces 706B Interesting drink
- Codeforces 706B Interesting drink 【二分】
- 如何防止房票出问题
- Java中按值传递还是按引用传递详细解说
- ofbiz之服务实体api积累
- 使用控件/Dialog时提示"未声明标识符"的解决方法
- Timer计时器
- 【Codeforces Round 367 (Div 2) B】【二分查找】Interesting drink
- 动态规划算法
- 小谈php处理 大并发 大流量 大存储
- Error:(2, 0) Plugin with id 'com.github.dcendents.android-maven' not found.
- 常见的蓝牙4.0模块
- SDUT OJ 数据结构实验之查找三:树的种类统计
- 咬碎STL空间配置器
- Fragment 中的 onCreateOptionsMenu 方法不执行
- OFBiz 开发需要用到的几个重要(配置)文件