LightOJ1089
2016-04-10 09:27
225 查看
题目链接: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<<1],res[N<<1]; PII p ; int main() { int i,x,y,v,group,Case=0; //freopen("in.txt","r",stdin); scanf("%d",&group); while(group--) { mst(res,0); int cnt=0; scanf("%d%d",&n,&m); for(i=0; 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=0; 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=1; i<cnt; ++i) res[i]+=res[i-1]; printf("Case %d:\n",++Case); for(i=0; i<m; ++i) { scanf("%d",&x); int pos=upper_bound(a,a+cnt,x)-a; printf("%d\n",res[pos-1]); } } return 0; }
相关文章推荐
- 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
- Educational Codeforces Round 11 C. Hard Process 二分
- shuffle 过程map与reduce交换数据过程的关键
- Android 深入理解Android中的自定义属性
- 斯坦福课程总结一
- LeetCode *** 190. Reverse Bits
- centos7搭建hadoop集群
- 详解如何建立Qt插件学习教程
- win8.1系统不能设置使用小键盘该怎么办?
- Mark
- QT插件开发方式
- 使用Qt编写模块化插件式应用程序
- SpringMVC运行原理
- SpringMVC运行原理
- QT插件机制
- plqsl中创建用户
- oracle自动生成主键不连续
- python 将有序list打乱
- 20145109 《Java实验报告1》
- STM32函数 命名规则