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) 个点,问每个点在几个线段上 线段端点的和询问的点的值都很大,所以必须离散化 第一种解法:先把所有的线 ...
随机推荐
- [Parcel] Running TypeScript with parcel-bundler
TO get started with TypeScirpt quickly in your local computer is using parcel-bunlder: npm i -g parc ...
- Java Volatile keyword
Volatile修饰的成员变量在每次被线程訪问时,都强迫从主内存中重读该成员变量的值.并且,当成员变量发生变化时,强迫线程将变化值回写到主内存.这样在不论什么时刻,两个不同的线程总是看到某个成员变量的 ...
- Spring Ajax一个简单样例
配置不说了.要在前面helloworld的样例基础上弄. 相同在hello下新建ajax.jsp <%@ page language="java" contentType=& ...
- zoj 1100 - Mondriaan's Dream
题目:在m*n的地板上铺上同样的1*2的地板砖,问有多少种铺法. 分析:dp,组合,计数.经典dp问题,状态压缩. 状态:设f(i,j)为前i-1行铺满,第i行铺的状态的位表示为j时的铺砖种类数: 转 ...
- 微信小程序 - 文本框显示限制最大长度
wxml <view class='textarea-count'> <textarea placeholder='请输入文字' bindinput="getWords&q ...
- ssh中使用spring的集成quartz 编写定时任务
之前没有使用框架开发时对于开发定时任务都是 使用java的原声timer类,重写线程的run方法跑要执行的任务.刚刚换的新公司,项目使用ssh2,目前该项目中的定时任务的使用spirng集成的quar ...
- Js中数组的追加
Concat arrayObject.concat(arrayX,arrayX,......,arrayX) 常用于 加载更多 ,数组的追加.
- selenium从入门到应用 - 8,selenium+testNG实现多线程的并发测试
本系列所有代码 https://github.com/zhangting85/simpleWebtest本文将介绍一个Java+TestNG+Maven+Selenium的web自动化测试脚本环境下s ...
- 深入浅出理解之 onInterceptTouchEvent与onTouchEvent
参考:http://blog.csdn.net/android_tutor/article/details/7193090 与 http://www.cnblogs.com/kingcent/ ...
- PHP正则表达式教程
1.入门简介 在编写处理字符串的程序或网页时,经常会有查找符合某些复杂规则的字符串的需要.正则表达式就是用于描述这些规则的工具.换句话说,正则表达式就是记录文本规则的代码. 很可能你使用过Windo ...