nyoj----522 Interval (简单树状数组)
2014-04-18 22:12
274 查看
Interval
时间限制:2000 ms | 内存限制:65535 KB难度:4
描述
There are n(1 <= n <= 100000) intervals [ai, bi] and m(1 <= m <= 100000) queries, -100000 <= ai <= bi <= 100000 are integers.
Each query contains an integer xi(-100000 <= x <= 100000). For each query, you should answer how many intervals convers xi.
输入The first line of input is the number of test case.
For each test case,
two integers n m on the first line,
then n lines, each line contains two integers ai, bi;
then m lines, each line contains an integer xi.输出m lines, each line an integer, the number of intervals that covers xi.样例输入
2 3 4 1 3 1 2 2 3 0 1 2 3 1 3 0 0 -1 0 1
样例输出
0 2 3 2 0 1 0
上传者ACM_赵铭浩 代码:
#include<stdio.h> #include<string.h> #include<stdlib.h> #define maxn 200005 //整体平移100001个单位 #define lowbit(x) ((x)&(-x)) int aa[maxn+5]; void ope(int x,int val) { x+=100001; while(x<=maxn) { aa[x]+=val; x+=lowbit(x); } } long long getsum(int x) { long long ans=0; while(x>0) { ans+=aa[x]; x-=lowbit(x); } return ans; } int main() { int test,nn,m,i,a,b; scanf("%d",&test); while(test--) { scanf("%d%d",&nn,&m); memset(aa,0,sizeof(aa)); for(i=0;i<nn;i++) { scanf("%d%d",&a,&b); ope(a,1); ope(b+1,-1); } for(i=0;i<m;i++) { scanf("%d",&a); a+=100001; printf("%I64d\n",getsum(a)); } } return 0; }
View Code
相关文章推荐
- 南阳28 大数阶乘
- linux awk命令详解
- Hadoop2.2.0 64位源码编译手记(centos6.4)
- Android开发:LayoutParams的用法
- Windows socket I/O模型 之 select(2)
- 关于PC可以识别并连接网络,但却无法访问问题
- 设计一个接口Shape,包括2个抽象方法getPerimeter()和getArea()
- CSS中背景图片定位方法
- OPENCV中滑动条的使用
- 求数列的下一个排列
- Java知识总结——LinkedList和ArrayList的区别
- js交换变量写法
- ASP.NET Web API 2 返回 Json格式
- typedef 的常见用法
- MyEclipse快捷键
- apache本地配置多域名(wampserver本地配置多域名)
- java中static作用详解
- 安卓开发_九宫格布局
- 杂七杂八
- HDU 3549