题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=26806

题目大意:略

题目思路:前缀和与离散化

可用线段树做,但是前缀和更简单

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cctype>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define fi first
#define se second
#define ping(x,y) ((x-y)*(x-y))
#define mst(x,y) memset(x,y,sizeof(x))
#define Min(x,y) (x<y?x:y)
#define Max(x,y) (x>y?x:y)
using namespace std;
#define gamma 0.5772156649015328606065120 //欧拉常数
#define MOD 100000007
#define inf 0x3f3f3f3f
#define N 50010
#define maxn 10001000
typedef long long LL;
typedef pair<int,int> PII; int n,m,a[N<<],res[N<<];
PII p[N]; int main()
{
int i,x,y,v,group,Case=;
//freopen("in.txt","r",stdin);
scanf("%d",&group);
while(group--)
{
mst(res,);
int cnt=;
scanf("%d%d",&n,&m);
for(i=; i<n; ++i)
{
scanf("%d%d",&p[i].fi,&p[i].se);
a[cnt++]=p[i].fi;
a[cnt++]=++p[i].se;
}
stable_sort(a,a+cnt);
cnt=unique(a,a+cnt)-a;
for(i=; i<n; ++i)
{
int l=lower_bound(a,a+cnt,p[i].fi)-a;
int r=lower_bound(a,a+cnt,p[i].se)-a;
++res[l];--res[r];
}
for(i=; i<cnt; ++i)
res[i]+=res[i-];
printf("Case %d:\n",++Case);
for(i=; i<m; ++i)
{
scanf("%d",&x);
int pos=upper_bound(a,a+cnt,x)-a;
printf("%d\n",res[pos-]);
}
}
return ;
}

LightOJ1089的更多相关文章

  1. LightOj1089(求点包含几个线段 + 线段树)

    题目链接 题意:n( n <= 50000 ) 个线段,q ( q <= 50000) 个点,问每个点在几个线段上 线段端点的和询问的点的值都很大,所以必须离散化 第一种解法:先把所有的线 ...

随机推荐

  1. [加入用户]解决useradd 用户后没有加入用户Home文件夹的情况,Linux改变文件或文件夹的訪问权限命令,linux改动用户password,usermod的ysuum安装包。飞

    usermod的yum安装包: shadow-utils 将nobody用户加入到nogroup 组: usermod -g nogroup nobody cat /etc/passwd|grep n ...

  2. C#秘密武器之反射——替换反射

    反射虽然有时很有必要,但是应用反射的代码大多“复杂难懂”.“性能不高”,因此我们可以找寻在一些场景下替换反射的方法.此处也只是一些栗子,更多巧妙的应用还是自己以后亲自查查~ 先来看看一个使用普通反射完 ...

  3. activiti入门3排他网关,并行网管,包括网关,事件网关

    网关用来控制流程的流向 网关能够消费也能够生成token. 网关显示成菱形图形,内部有有一个小图标. 图标表示网关的类型. 基本分支 首先 利用 流程变量  写个带有分支的一个基本流程 流程图: wa ...

  4. Spring 配置中的 ${}

    Spring 配置中的 ${}     <!-- ============ GENERAL DEFINITIONS========== --> <!-- Configurer tha ...

  5. python中MySQL模块TypeError: %d format: a number is required, not str异常解决

    转载自:http://www.codeif.com/topic/896 python代码: attr_sql = "INSERT INTO `ym_attribute` (`attr_nam ...

  6. HttpClient Coder Example

    Example 1:   HttpClient httpClient = new HttpClient();                 httpClient.getHostConfigurati ...

  7. oc自定义不定参数函数

    -(void)getValueFormConfig:(NSString *)key,... or -(void)getValueFormConfig:(NSString *)key,...NS_REQ ...

  8. javascript-ajax之json学习笔记

    ajax什么时候解析json的时候用eval 1.如果是原生js实现的ajax,就需要eval转json对象 如果使用了类似jquery的js插件,里面有些方法是不需要转的,因为jquery已经帮你处 ...

  9. 网易2016年研发project师编程题(2)

    序 网易互联网的实习笔试立即就開始了,做几个练习题熟悉熟悉~嘿嘿~ 题目一: 小易的升级之路 小易常常沉迷于网络游戏.有一次,他在玩一个打怪升级的游戏,他的角色的初始能力值为 a.在接下来的一段时间内 ...

  10. 最小生成树之Kruskal算法和Prim算法

    依据图的深度优先遍历和广度优先遍历,能够用最少的边连接全部的顶点,并且不会形成回路. 这样的连接全部顶点并且路径唯一的树型结构称为生成树或扩展树.实际中.希望产生的生成树的全部边的权值和最小,称之为最 ...