LightOJ1089
题目链接: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的更多相关文章
- LightOj1089(求点包含几个线段 + 线段树)
题目链接 题意:n( n <= 50000 ) 个线段,q ( q <= 50000) 个点,问每个点在几个线段上 线段端点的和询问的点的值都很大,所以必须离散化 第一种解法:先把所有的线 ...
随机推荐
- [加入用户]解决useradd 用户后没有加入用户Home文件夹的情况,Linux改变文件或文件夹的訪问权限命令,linux改动用户password,usermod的ysuum安装包。飞
usermod的yum安装包: shadow-utils 将nobody用户加入到nogroup 组: usermod -g nogroup nobody cat /etc/passwd|grep n ...
- Web service--百度百科
Web service是一个平台独立的,低耦合的,自包含的.基于可编程的web的应用程序,可使用开放的XML(标准通用标记语言下的一个子集)标准来描述.发布.发现.协调和配置这些应用程序,用于开发分布 ...
- C# Windows form application 播放小视频
1. 下载direcly-show lib DLL点击打开链接 2. DxPlay.cs (能够在下载的样例中找到): public class DxPlay : IDisposable { e ...
- Spring 对没有实现接口的类使用aspect的时候,可以使用CGLIB
AspectJ中使用CGLIB 在spring中,当对没有实现接口的类使用aspect的时候,可以使用CGLIB, <aop:aspectj-autoproxy proxy-target-cla ...
- 你要相信你所做的一切对一个更美好的世界 Do have faith in what you are doing All for a better world
http://www.nowamagic.net/librarys/veda/detail/2502 Do have faith in what you are doing. 先不要往下看,试试品尝上 ...
- Velocity中文乱码问题解决方法
http://yonge812.iteye.com/blog/1010290 Velocity中文乱码问题需要注意一下几点: 1.eclipse默认编码方式 2.页面的编码方式 3.volocity模 ...
- win10 在当前目录下 打开cmd
windows7 : 按住 shift 键 , 右键 就有该选项. windows10 : 运行下面的 注册表文件: 该注册表文件内容如下: Windows Registry Editor Versi ...
- 对象关系映射 EmitMapper 及Tuple的使用
public TDestination Map<TSource, TDestination>(TSource tSource) { if (tSource == null) return ...
- centos 7.x systemctl 几个常用的操作
# 开机启动 systemctl enable nginx # 禁止开机启动 systemctl disable nginx # 开启服务 systemctl start nginx # 停止服务 s ...
- chrome扩展(浏览器插件)开发实用教程
原创文章,转载请注明出处. 作者:简体字丶冯; QQ:564372931 1.Chrome能搞这些事情 (1) 操作浏览器中打开的页面DOM 这能做什么哪?譬如说你想修改页面DOM(DOM是什 ...