#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const int maxN = 100005;
int a[maxN];
int t, tt;
int n, q, x, y; int Bsearch_lower_bound(int x)
{
int l = 0, r = n - 1, mid = 0;
while (l <= r)
{
mid = (l + r) >> 1;
if (a[mid] < x) l = mid + 1;
else r = mid - 1;
}
return l;
} int Bsearch_upper_bound(int x)
{
int l = 0, r = n - 1, mid = 0;
while (l <= r)
{
mid = (l + r) >> 1;
if (a[mid] <= x) l = mid + 1;
else r = mid - 1;
}
return l;
} void solve()
{
scanf("%d%d", &n, &q);
printf("Case %d:\n", ++tt);
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
for (int i = 0; i < q; i++)
{
scanf("%d%d", &x, &y);
int l = Bsearch_lower_bound(x);
int r = Bsearch_upper_bound(y);
printf("%d\n", r - l);
}
} int main()
{
scanf("%d", &t);
while (t--) solve();
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

二分--LIGHTOJ 1088查找区间(水题)的更多相关文章

  1. LightOJ 1248 Dice (III) (水题,期望DP)

    题意:给出一个n面的色子,问看到每个面的投掷次数期望是多少. 析:这个题很水啊,就是他解释样例解释的太...我鄙视他,,,,, dp[i] 表示 已经看到 i 面的期望是多少,然后两种选择一种是看到新 ...

  2. lightoj 1020 (博弈水题)

    lightoj 1020 A Childhood Game 链接:http://lightoj.com/volume_showproblem.php?problem=1020 题意:一堆石子有 m 个 ...

  3. LightOJ 1023 Discovering Permutations 水题

    http://www.lightoj.com/volume_showproblem.php?problem=1023 题意:26字母全排列 思路:用next_permutation或者思维想一下都可以 ...

  4. LightOJ 1214 Large Division 水题

    java有大数模板 import java.util.Scanner; import java.math.*; public class Main { public static void main( ...

  5. LightOJ 1220 Mysterious Bacteria 水题

    暴力就行了,找出素因子,正的最多是30,然后负的最多是31(这一点wa了一次) #include <cstdio> #include <iostream> #include & ...

  6. SPOJ CNTPRIME 13015 Counting Primes (水题,区间更新,求区间的素数个数)

    题目连接:http://www.spoj.com/problems/CNTPRIME/ #include <iostream> #include <stdio.h> #incl ...

  7. SPOJ 3693 Maximum Sum(水题,记录区间第一大和第二大数)

    #include <iostream> #include <stdio.h> #include <algorithm> #define lson rt<< ...

  8. SPOJ 7259 Light Switching (水题,区间01取反)

    #include <iostream> #include <stdio.h> #include <algorithm> #define lson rt<< ...

  9. lightoj 1010 (水题,找规律)

    lightoj 1010 Knights in Chessboard 链接:http://lightoj.com/volume_showproblem.php?problem=1010 题意:国际象棋 ...

随机推荐

  1. C#winform设置DateTimePicker的时间格式

    在对DateTimePicker进行时间格式设置时候,要先对属性Format设置为"Custom"自定义格式,然后再CustomFormat里面进行格式设置 比如"yyy ...

  2. foreach 和 list.foreach 初步测试

    单纯从速度上讲 小数据量下foreach 较快,list.Foreach 由于 public void ForEach(Action<T> action) { ; i <this._ ...

  3. Blend制作的下载动画

    最近使用Blend制作了一个下载动画,感觉很有意思,所以这篇给各位介绍下如何使用Blend制作一个简单的下载动画的步骤 首先拖出一个圆,参数如下: 选中椭圆后单击Properties面板,选择“Fil ...

  4. OC学习-1

    编译和编写代码. 1. 创建代码文件夹 mkdir lession2 2. 新建类文件 touch lession2.m 3. 打开编写代码,(会用xcode打开) open lession2.m 4 ...

  5. android空鼠修改

    抛弃盒子自带遥控器后,又不满意改键红外遥控器,选择飞鼠及无线键鼠成为最终方案.问题是:菜单键如何实现!其实很简单:即插即用USB无线飞鼠及键鼠套装只涉及2个文件:system/usr/layout/G ...

  6. android ping网络是否成功

    public static boolean pingHost(String str) { //str 为要ping的IP地址 boolean result = false; try { Process ...

  7. PropertyGrid 控件使用方法

    编写一个对象,后面传递给 PropertyGrid 来显示: using System; using System.Collections.Generic; using System.Linq; us ...

  8. 图表控件MsChart使用demo

    chart 控件主要有 Titles 标题集合  Chart Area图形显示区域 Series图表集合 Legends图列的集合 (1)  常用事件: 1. Series1.Points.DataB ...

  9. Python核心编程--学习笔记--1--Python简介

    本章介绍了Python的背景知识,包括什么是Python.Python的起源以及Python的一些关键特性. 1 什么是Python Python是一门优雅而健壮的编程语言,它继承了传统编译语言的强大 ...

  10. Telerik XML 数据源绑定的问题

    Telerik GridView 默认的 XElement 数据源的直接绑定,会导致内置的sort, filter ,group等功能无法使用. 原因在于Telerik GridView的那些功能是根 ...