Educational Codeforces Round 2_B. Queries about less or equal elements
来源:互联网 发布:淘宝csv数据怎么制作 编辑:程序博客网 时间:2024/06/11 10:04
B. Queries about less or equal elements
time limit per test
2 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputYou are given two arrays of integers a andb. For each element of the second array bj you should find the number of elements in arraya that are less than or equal to the valuebj.
Input
The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the sizes of arraysa and b.
The second line contains n integers — the elements of arraya ( - 109 ≤ ai ≤ 109).
The third line contains m integers — the elements of arrayb ( - 109 ≤ bj ≤ 109).
Output
Print m integers, separated by spaces: thej-th of which is equal to the number of such elements in arraya that are less than or equal to the valuebj.
Sample test(s)
Input
5 41 3 5 7 96 4 2 8
Output
3 2 1 4
Input
5 51 2 1 2 53 1 4 1 5
Output
4 2 4 2 5
二分||
#include <bits/stdc++.h>using namespace std;typedef long long int LL ;const int maxn = 2e5+100;LL a[maxn], b[maxn], c[maxn];int n, m;int erfen(LL p) {int le = 1, ri = n, mid;mid = (le+ri)/2;for (int i = 1; i<300; i++) {if (p>=a[mid]) le = mid;else if (p<a[mid]) ri = mid;mid = (le+ri)/2;}if (p == a[mid] && p!=a[ri])return mid;else if (p == a[mid] && p==a[ri])return ri;if (p>a[mid] && p<a[ri])return mid;else if (p>a[mid] && p >= a[ri]) return ri;else if (p<a[mid] && p<a[le])return mid-1;else if (p<a[mid] && p>=a[le])return le;}int main() {memset(a, 0, sizeof(a));memset(b, 0, sizeof(b));memset(c, 0, sizeof(c));cin >> n >> m;for (int i = 1; i<=n; i++)cin >> a[i];for (int i = 1; i<=m; i++)cin >> b[i];sort(a+1, a+n+1);//sort(b, b+m);int num = 0;for (int i = 1; i<=m; i++) {c[num++] = erfen(b[i]);}for (int i = 0; i<num-1; i++)cout << c[i] << " ";cout << c[num-1] << endl;return 0;}
0 0
- Educational Codeforces Round 2_B. Queries about less or equal elements
- Codeforces Educational Codeforces Round 2 B. Queries about less or equal elements
- Educational Codeforces Round 2B. Queries about less or equal elements(二分查找)
- Educational Codeforces Round 2 B. Queries about less or equal elements
- Educational Codeforces Round 2 B. Queries about less or equal elements (二分)
- Educational Codeforces Round 2 B.Queries about less or equal elements(排序&&二分)
- 【Educational Codeforces Round 2B】【map or 二分查找】Queries about less or equal elements b[]中的每个数比a[]中多少数大
- codeforces B.Queries about less or equal elements
- codeforces Queries about less or equal elements 二分
- Codeforces-600B Queries about less or equal elements(二分)
- Codeforces 600.B Queries about less or equal elements
- Queries about less or equal elements
- Codeforces 600B Queries about less or equal elements(二分查找)
- Codeforces 600B Queries about less or equal elements 【离散化去重二分查找 + 树状数组】
- 【CodeForces 600B 】Queries about less or equal elements(二分查找)
- Codeforces 600B Queries about less or equal elements(二分、upper_bound()的应用)
- codeforces_600B. Queries about less or equal elements(排序二分)
- cordforces 600B Queries about less or equal elements
- java消息机制
- Qt的时钟Example
- Win7下安装OK6410的USB驱动以及Linux下源码安装dnw
- sublist分组list模拟代码
- TECHNIQUES(技术)
- Educational Codeforces Round 2_B. Queries about less or equal elements
- 适配器模式
- HDU 2955 Robberies
- UESTC 1033 Marineking wilyin
- 10007---注入属性值细节
- vim的跳转
- 再次唠叨linux中的strings命令
- UESTC 1012 Ladygod 任意进制的转化
- [Swoole入门]-异步毫秒定时器