树状数组(区间更新,但点查询)
来源:互联网 发布:linux 文件上传权限 编辑:程序博客网 时间:2024/06/03 21:06
#include<iostream>#include<cstring>using namespace std;const int MAX=100010;int T, N, M;int c[MAX];inline int lowBit(int x){ return x & (-x);}void add(int pos, int v){ while(pos<=MAX-5) { c[pos]+=v; pos+=lowBit(pos); }}int getSum(int pos){ int sum=0; while(pos>0) { sum+=c[pos]; pos-=lowBit(pos); } return sum;}void addInterval(int l, int r){ add(l, 1); add(r+1, -1);}int main(){ ios::sync_with_stdio(0); cin>>T; int cnt=1; int l, r, ans; while(T--) { cin>>N>>M; memset(c, 0, sizeof(c)); for(int i=1; i<=N; i++) { cin>>l>>r; addInterval(l, r); } cout<<"Case #"<<cnt++<<":"<<endl; for(int i=1; i<=M; i++) { cin>>l; ans=getSum(l); cout<<ans<<endl; } } return 0;}
阅读全文
0 0
- 树状数组(区间更新,但点查询)
- 树状数组(区间更新区间查询)
- 【树状数组 区间更新区间查询】code
- HDOJ-1556(线段树||树状数组,区间更新+点查询)
- 树状数组点更新,区间更新理解
- HDU 4031 Attack(树状数组修改区间查询点)
- hdu1556(树状数组/线段树,区间修改,点查询)
- poj2155(树状数组,区间修改,点查询)
- hdu3584(三维树状数组,区间修改,点查询)
- 【树状数组】区间修改&点查询
- 【树状数组】点修改&区间查询
- hdu1556 树状数组 区间修改,点查询
- hdu 4533(树状数组区间更新+单点查询)
- 树状数组模板(区间更新单点查询)
- 三维树状数组(区间更新,单点查询)POJ
- poj2155树状数组 区间更新 单点查询
- 树状数组的单点更新,区间查询。
- Flowers(树状数组+区间更新+单点查询+区间更新单点查询模板)
- 大整数存储和运算
- ExerciseP134
- python高级: 解析式、生成器
- caffe上运行mnist实例---手写数字识别所遇到的问题及解决方案
- Qt————学习记录(一)
- 树状数组(区间更新,但点查询)
- 22.leetCode463: Island Perimeter
- Gram矩阵计算实例
- 实验三:内部模块化的命令行菜单小程序V2.0
- 表达式求值
- 成绩排序
- ajxa调去json文件和xml文件
- 360Lib:WS-PSNR
- javaEE之Filter