nyoj----522 Interval (简单树状数组)
Interval
- 描述
-
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+];
void ope(int x,int val)
{
x+=;
while(x<=maxn)
{
aa[x]+=val;
x+=lowbit(x);
}
}
long long getsum(int x)
{
long long ans=;
while(x>)
{
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,,sizeof(aa));
for(i=;i<nn;i++)
{
scanf("%d%d",&a,&b);
ope(a,);
ope(b+,-);
}
for(i=;i<m;i++)
{
scanf("%d",&a);
a+=;
printf("%I64d\n",getsum(a));
}
}
return ;
}
nyoj----522 Interval (简单树状数组)的更多相关文章
- HDU 5489 Removed Interval DP 树状数组
题意: 给一个长度为\(N\)的序列,要删除一段长为\(L\)的连续子序列,问所能得到的最长的\(LIS\)的长度. 分析: 设\(f(i)\)表示以\(a_i\)结尾的\(LIS\)的长度,设\(g ...
- “玲珑杯”ACM比赛 Round #5 H -- Variance 简单树状数组
可以把每个公式都化简,然后得到要维护的东西就是平方和,和前缀和,两个bit即可 不能cin,超时.IOS后都不行. scanf用lld #include <cstdio> #include ...
- nyoj 600:花儿朵朵(树状数组+坐标离散化)
http://acm.nyist.net/JudgeOnline/problem.php?pid=600 只附代码好了 #include<bits/stdc++.h> using name ...
- hdu4911 简单树状数组
题意: 给你一串数字,然后给你最多进行k次交换(只能交换相邻的)问交换后的最小逆序数是多少. 思路: 首先要知道的一个就是给你一个序列,每次只能交换相邻的位置,把他交换成一个递增序 ...
- poj 2029 二维树状数组
思路:简单树状数组 #include<map> #include<set> #include<cmath> #include<queue> #inclu ...
- 2018.09.28 bzoj3688: 折线统计(dp+树状数组)
传送门 简单树状数组优化dp. 注意到k很小提示我们搜(d)(d)(d)索(p)(p)(p). 先按第一维排序. 用f[i][j][0/1]f[i][j][0/1]f[i][j][0/1]表示第i个点 ...
- 差分+树状数组 线段树【P2357】 守墓人
题目描述-->p2357 守墓人 敲了一遍线段树,水过. 树状数组分析 主要思路: 差分 简单介绍一下差分(详细概念太麻烦,看下面. 给定一个数组 7 8 6 5 1 8 18 20 35 // ...
- HDU 1166 敌兵布阵 树状数组||线段树
http://acm.hdu.edu.cn/showproblem.php?pid=1166 题目大意: 给定n个数的区间N<=50000,还有Q个询问(Q<=40000)求区间和. 每个 ...
- (简单) POJ 3321 Apple Tree,树链剖分+树状数组。
Description There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow ...
随机推荐
- SVN中的Trunk、Tag、Brance的用法
在SVN中Branch/tag在一个功能选项中,在使用中也往往产生混淆.在实现上,branch和tag,对于svn都是使用copy实现的,所以他们在默认的权限上和一般的目录没有区别.至于何时用tag, ...
- Bash,Vim,gdb&git常用命令
Bash 目录 pwd //查看当前目录 mkdir dir1 dir2 //创建目录 tree dir1 mv test1.cpp test2.cpp dir1 dir //移动文件/目录到目 ...
- 【BZOJ】【1178】【APIO2009】convention会议中心
贪心 如果不考虑字典序的话,直接按右端点排序,能选就选,就可以算出ans…… 但是要算一个字典序最小的解就比较蛋疼了= = Orz了zyf的题解 就是按字典序从小到大依次枚举,在不改变答案的情况下,能 ...
- Informatica 常用组件Source Qualifier之七 输入过滤器
通过输入源过滤器,可以降低 PowerCenter 查询的行数.如果在源过滤器中包括字符串 "WHERE" 或较大对象,PowerCenter 将使会话失败. 源限定符转换包括默 ...
- AngularJS driective 封装 自动滚动插件
1.ui-smooth-scroll.js文件内容 angular.module('app') .directive('uiSmoothScroll', ['$location', '$anchorS ...
- C#中HTML和UBB互相转换的代码
C#中HTML和UBB互相转换的代码html转UBB的还不是很完美,有空修改,一些代码来自百度谷歌 private string DoHtmlToUBB(string _Html) { ...
- ASP.NET MVC 编程参考
ASP.NET MVC 编程参考 转载请注明出处:http://surfsky.cnblogs.com MVC 参考 http://msdn.microsoft.com/zh-cn/dd40 ...
- phpcms pc标签 start不生效的原因
start 和 page 参数不可同时使用,使用了page参数 会造成start 参数无效
- scala里的模式匹配和Case Class
模式匹配的简介 scala语言里的模式匹配可以看作是java语言中switch语句的改进. 模式匹配的类型 包括:常量模式.变量模式.构造器模式.序列模式.元组模式以及变量绑定模式等. 常量模式匹配 ...
- 【Ansible】Playbook实例
Learn to build Ansible playbooks with our guide, one step at a time In our previous posts, we introd ...