<span style="color:#6633ff;">/*
G - 二分
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Submit Status
Description
Given n points (1 dimensional) and q segments, you have to find the number of points that lie in each of the segments. A point pi will lie in a segment A B if A ≤ pi ≤ B. For example if the points are 1, 4, 6, 8, 10. And the segment is 0 to 5. Then there are 2 points that lie in the segment. Input
Input starts with an integer T (≤ 5), denoting the number of test cases. Each case starts with a line containing two integers n (1 ≤ n ≤ 105) and q (1 ≤ q ≤ 50000). The next line contains n space separated integers denoting the points in ascending order. All the integers are distinct and each of them range in [0, 108]. Each of the next q lines contains two integers Ak Bk (0 ≤ Ak ≤ Bk ≤ 108) denoting a segment. Output
For each case, print the case number in a single line. Then for each segment, print the number of points that lie in that segment. Sample Input
1 5 3 1 4 6 8 10 0 5 6 10 7 100000 Sample Output
Case 1: 2 3 2 Hint
Dataset is huge, use faster I/O methods.
By Grant Yuan
2014.7.16
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int t;
long long low,high,mid,ans;
int n,m;
int a[100005];
long long x,y;
int ct=1;
int main()
{int l,r;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m); for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Case %d:\n",ct++);
while(m--){
scanf("%d%d",&x,&y);
if(x<a[0]) l=0;
else {l=lower_bound(a,a+n,x)-a;
}
if(y>a[n-1]) r=n;
else {r=upper_bound(a,a+n,y)-a;
}
printf("%d\n",r-l);}}
return 0;
}
</span>

最新文章

  1. Python爬网获取全国各地律师电话号
  2. svn 权限配置
  3. PHP 获取图像信息 getimagesize 函数
  4. LeetCode Minimum Path Sum (简单DP)
  5. Python Counter()计数工具
  6. Tomcat7集群扩展session集中管理,tomcat-redis-session-manager使用
  7. php插入转义与查找转义
  8. 终于懂了:TWinControl主要是Delphi官方用来封装Windows的官方控件,开发者还是应该是有TCustomControl来开发三方控件
  9. Python学习【第26篇】:Python系列- 多线程(threading)
  10. spring启动容器加载成功后执行调用方法
  11. 【快捷键】IntelliJ IDEA For Mac 常用快捷键
  12. 洛谷P4823 拯救小矮人 [TJOI2013] 贪心+dp
  13. Nginx限制某个IP同一时间段的访问次数和请求数示例代码
  14. 题目1162:I Wanna Go Home(最短路径问题进阶dijkstra算法))
  15. [Linux]-Linux常用命令之文件解压
  16. 20155322 2016-2017-2 《Java程序设计》第6周学习总结
  17. ThinkPHP项目笔记之数据库配置篇
  18. Spring的注解配置与XML配置之间的比较
  19. RegExp.prototype.exec()使用技巧
  20. (三)js循环结构

热门文章

  1. 【简●解】POJ 1845 【Sumdiv】
  2. SCOI2013 密码
  3. phpstorm破解激活码
  4. swift -从相册中选择照片并上传
  5. 用PowerPoint中的VB实现课件中的智能交互
  6. UI &amp; 原型
  7. bzoj 1049 [HAOI2006]数字序列
  8. Spring boot data JPA数据库映射关系 : @OneToOne,@OneToMany,@ManyToMany
  9. 【ZJOI2017 Round1后记】
  10. HTML5调用传感器的资料汇总