NYOJ 522 裸的树状数组
来源:互联网 发布:ipa应用分发源码 编辑:程序博客网 时间:2024/04/27 21:21
又是一道水题,,话说这次月赛水题真的很多很多,貌似比赛时写出来的题都是水题。。。看来,水平也就能水一下题而已。。。。不过这道题比赛时还是坑了不少人,很多人在处理边界问题0的时候没有注意,都TLE了,,当时我也TLE了一次,后来仔细想了想,改过后就ac了。相比那些一直TLE到最后的孩纸来说,我算是幸运了。不过,这道题难度有点高了,除了边界问题外,就是道裸的树状数组,没什么难度的。题目:
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.
- 样例输入
23 41 31 22 301231 30 0-101
- 样例输出
0232010
#include <iostream>#include <cstdio>#include <string.h>#include <cmath>const int N=200002;const int M=100001;int num[N],ans[N];int lowbit(int x){return x&(-x);}void update(int m,int value){while(m>0){ num[m]+=value; m-=lowbit(m);}}int sum(int x){int s=0;while(x<=N){ s+=num[x]; x+=lowbit(x);}return s;}int main(){//freopen("1.txt","r",stdin);int numcase;scanf("%d",&numcase);while(numcase--){ memset(num,0,sizeof(num)); // memset(ans,0,sizeof(ans)); int n,m; scanf("%d%d",&n,&m); int x,y; while(n--){ scanf("%d%d",&x,&y);x=x+M;y=y+M;update(x-1,-1);update(y,1); } while(m--){ scanf("%d",&x);x=x+M;//if(!ans[x]) printf("%d\n",sum(x));/*elseprintf("%d\n",ans[x]);*/ }}return 0;}
- NYOJ 522 裸的树状数组
- NYOJ-522 Interval【树状数组】
- nyoj 522 树状数组入门
- NYOJ 522 Interval (树状数组)
- NYOJ 116 树状数组
- nyoj 树状数组系列
- NYOJ 2689(树状数组)
- nyoj 123 树状数组 插线问点
- nyoj 322 Sort 【树状数组】
- NYOJ 233 &&NYOJ 322 Sort(树状数组)
- NYOJ 123 士兵杀敌4-树状数组的插线求点
- nyoj 树状数组 522Interval 116士兵杀敌(二)
- NYOJ 士兵杀敌 (树状数组)
- NYOJ 士兵杀敌(四) 树状数组
- NYOJ 士兵杀敌(二) 树状数组
- NYOJ 600 花儿朵朵 树状数组
- NYOJ - 士兵杀敌(二)(树状数组)
- 【树状数组】nyoj 116 123 士兵杀敌
- NYOJ 529 月赛水题
- Visual Studio 各版本区别: 从1998年的 6.0 到现在的 2010 Ultimate 如何注册和获得以及购买许可
- NYOJ 532 月赛水题
- Hibernate---->生命周期
- csdnS2-lesson4
- NYOJ 522 裸的树状数组
- 系统设计黄金法则:简单之美
- asp.net gv导出excel
- ERROR: Application requires API version 9. Device API version is 4 (Android 1.6).
- Android应用资源---绘制资源类型(Drawable)(五)
- 互联网盈利模式分析一
- 互联网企业盈利模式全分析二
- 第10周-任务0-构造和析构函数的执行过程实例解析
- [Java]读取文件方法