二分--LIGHTOJ 1088查找区间(水题)
#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查找区间(水题)的更多相关文章
- LightOJ 1248 Dice (III) (水题,期望DP)
题意:给出一个n面的色子,问看到每个面的投掷次数期望是多少. 析:这个题很水啊,就是他解释样例解释的太...我鄙视他,,,,, dp[i] 表示 已经看到 i 面的期望是多少,然后两种选择一种是看到新 ...
- lightoj 1020 (博弈水题)
lightoj 1020 A Childhood Game 链接:http://lightoj.com/volume_showproblem.php?problem=1020 题意:一堆石子有 m 个 ...
- LightOJ 1023 Discovering Permutations 水题
http://www.lightoj.com/volume_showproblem.php?problem=1023 题意:26字母全排列 思路:用next_permutation或者思维想一下都可以 ...
- LightOJ 1214 Large Division 水题
java有大数模板 import java.util.Scanner; import java.math.*; public class Main { public static void main( ...
- LightOJ 1220 Mysterious Bacteria 水题
暴力就行了,找出素因子,正的最多是30,然后负的最多是31(这一点wa了一次) #include <cstdio> #include <iostream> #include & ...
- SPOJ CNTPRIME 13015 Counting Primes (水题,区间更新,求区间的素数个数)
题目连接:http://www.spoj.com/problems/CNTPRIME/ #include <iostream> #include <stdio.h> #incl ...
- SPOJ 3693 Maximum Sum(水题,记录区间第一大和第二大数)
#include <iostream> #include <stdio.h> #include <algorithm> #define lson rt<< ...
- SPOJ 7259 Light Switching (水题,区间01取反)
#include <iostream> #include <stdio.h> #include <algorithm> #define lson rt<< ...
- lightoj 1010 (水题,找规律)
lightoj 1010 Knights in Chessboard 链接:http://lightoj.com/volume_showproblem.php?problem=1010 题意:国际象棋 ...
随机推荐
- js一些稀奇古怪的写法-带你装逼带你飞
//定时器的第三个参数 setInterval(function(str1,str2,num){ alert(str1+str2+num) },1000,'参数1','还可以有很多参数,不同的类型.. ...
- asp.net mvc 用Redis实现分布式集群共享Session。
1.这两天研究Redis搞分布式session问题,网上找的资料都是用ServiceStack.Redis来实现的,但是在做性能测试的时候发现最新的v4版本有限制每小时候最多请求6000次,因为官网开 ...
- form表单无刷新提交文件(iframe)
先看一段代码(PHP例子) 1.表单代码(form.html): <iframe name="testIframeName" style="display:none ...
- a标签至于flash之上的时候,IE浏览器无法点击连接的问题
<a style="display: block;height: 131px;position: absolute;z-index: 999;width: 222px;backgrou ...
- Oracle与SQL Server事务处理的比较
事务处理是所有大型数据库产品的一个关键问题,各数据库厂商都在这个方面花费了很大精力,不同的事务处理方式会导致数据库性能和功能上的巨大差异.事务处理也是数据库管理员与数据库应用程序开发人员必须深刻理解的 ...
- Servlet之HttpServletResponse和HttpServletRequest
HttpServletResponse 1.告诉服务器应用使用UTF-8解析文本的两种方式,告诉客户端要使用什么编码 response.setHeader("content-type&quo ...
- C# 平时碰见的问题【3】
今天发现一个问题纳闷了半个小时, 需求是处理project文件里边的数据内容,其中需要判断任务名称不存在重复; 在测试的时候弄了两行一样的任务,如预想: 任务[xxx]重复 然后删掉重复的任务行,继续 ...
- STM32F0xx_EXIT中断配置详细过程
Ⅰ.概述 EXIT外部中断在使用到按键或者开关控制等应用中比较常见,低功耗中断唤醒也是很常见的一种.因此,EXIT在实际项目开发中也是比较常见的一种. STM32F0中外部中断EXIT属于中断和事件的 ...
- equals函数
equals函数在Object类当中,而Object类是所有类的父类,所以所有的类里面都有equals函数. “==”操作符之前用于比较两个基本数据类型的值是否相等,而对于引用数据类型,“==”操作符 ...
- 文件系统 第八次迭代 VFS相关说明
麻烦访问evernote链接 http://www.evernote.com/shard/s133/sh/53e5b5ac-1192-4910-8bd5-6886218562af/59516c32a5 ...