首页 技术 正文
技术 2022年11月15日
0 收藏 891 点赞 3,112 浏览 1527 个字

1088 – Points in Segments

  PDF (English) Statistics Forum
Time Limit: 2 second(s) Memory Limit: 32 MB

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

Output for Sample Input

1

5 3

1 4 6 8 10

0 5

6 10

7 100000

Case 1:

2

3

2

Note

Dataset is huge, use faster I/O methods.

题目大意:数据量非常大,直接搞肯定就搞死了,明显二分查找,调用lower__bound和upper__bound就可以。

输出注意要用标准输入输出,否则超时gg.

代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
const int maxn=100000+100;
int a[maxn];
int main()
{
    int kase=0;
    int T;
    int n,p;
    scanf(“%d”,&T);
    while(T–)
    {
        scanf(“%d%d”,&n,&p);
        for(int i=0;i<n;i++)
            scanf(“%d”,&a[i]);
      printf(“Case %d:\n”,++kase);
        while(p–)
        {
            int c,d;
            scanf(“%d%d”,&c,&d);
            int t1=upper_bound(a,a+n,d)-a;
            int t2=lower_bound(a,a+n,c)-a;
            printf(“%d\n”,t1-t2);
        }
    }
    return 0;
}

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,564
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905