HDU4325 树状数组
Flowers
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3148 Accepted Submission(s): 1549
is known to all, the blooming time and duration varies between
different kinds of flowers. Now there is a garden planted full of
flowers. The gardener wants to know how many flowers will bloom in the
garden in a specific time. But there are too many flowers in the garden,
so he wants you to help him.
For
each case, the first line contains two integer N and M, where N (1
<= N <= 10^5) is the number of flowers, and M (1 <= M <=
10^5) is the query times.
In the next N lines, each line contains two integer Si and Ti (1 <= Si <= Ti <= 10^9), means i-th flower will be blooming at time [Si, Ti].
In the next M lines, each line contains an integer Ti, means the time of i-th query.
each case, output the case number as shown and then print M lines. Each
line contains an integer, meaning the number of blooming flowers.
Sample outputs are available for more details.
1 1
5 10
4
2 3
1 4
4 8
1
4
6
0
Case #2:
1
2
1
/*树状数组模板题,若在区间a,b内开花则使a端点+1,使b+1端点-1,最后求到某一点的和就是某一点的值
某一点的值即可。*/
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<queue>
#include<stack>
using namespace std;
int t,n,m;
int A[];
int lowbit(int x)
{
return x&(-x);
}
void add(int rt,int c)
{
while(rt<=)
{
A[rt]+=c;
rt+=lowbit(rt);
}
}
int sum(int rt)
{
int s=;
while(rt>)
{
s+=A[rt];
rt-=lowbit(rt);
}
return s;
}
int main()
{
int a,b,c;
scanf("%d",&t);
for(int i=;i<=t;i++)
{
memset(A,,sizeof(A));
printf("Case #%d:\n",i);
scanf("%d%d",&n,&m);
while(n--)
{
scanf("%d%d",&a,&b);
add(a,);
add(b+,-);
}
while(m--)
{
scanf("%d",&c);
printf("%d\n",sum(c));
}
}
return ;
}
HDU4325 树状数组的更多相关文章
- HDU4325 树状数组+离散化
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4325 Flowers Time Limit: 4000/2000 MS (Java/Others) ...
- BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]
1103: [POI2007]大都市meg Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2221 Solved: 1179[Submit][Sta ...
- bzoj1878--离线+树状数组
这题在线做很麻烦,所以我们选择离线. 首先预处理出数组next[i]表示i这个位置的颜色下一次出现的位置. 然后对与每种颜色第一次出现的位置x,将a[x]++. 将每个询问按左端点排序,再从左往右扫, ...
- codeforces 597C C. Subsequences(dp+树状数组)
题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...
- BZOJ 2434: [Noi2011]阿狸的打字机 [AC自动机 Fail树 树状数组 DFS序]
2434: [Noi2011]阿狸的打字机 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 2545 Solved: 1419[Submit][Sta ...
- BZOJ 3529: [Sdoi2014]数表 [莫比乌斯反演 树状数组]
3529: [Sdoi2014]数表 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1399 Solved: 694[Submit][Status] ...
- BZOJ 3289: Mato的文件管理[莫队算法 树状数组]
3289: Mato的文件管理 Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 2399 Solved: 988[Submit][Status][Di ...
- 【Codeforces163E】e-Government AC自动机fail树 + DFS序 + 树状数组
E. e-Government time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...
- 【BZOJ-3881】Divljak AC自动机fail树 + 树链剖分+ 树状数组 + DFS序
3881: [Coci2015]Divljak Time Limit: 20 Sec Memory Limit: 768 MBSubmit: 508 Solved: 158[Submit][Sta ...
随机推荐
- animation动画兼容所有手机
.canvasAnim{ position: absolute; width:240px; height:240px; top:; z-index:; top:-20px; left:-5px; bo ...
- Linux编程(3) MakeFile
1. 在Linux中,make工具可以维护程序模块关系和生成可执行程序.它可根据程序模块的修改情况重新编译链接生成中间代码或最终的可执行程序.执行make命令,需要一个名为Makefile的文本文件, ...
- 【T_SQL】 基础 续+++
十五.T-SQL 编程 1.变量 (1)局部变量 A.局部变量必须以标记@作为前缀 ,如@age. B.局部变量的使用也是先 ...
- 【Filter 页面重定向循环】写一个过滤器造成的页面重定向循环的问题
今天做一个过滤器,碰上页面重定向循环的情况: 浏览器的访问路径是:http://192.168.16.104:8080/biologyInfo/login/login/login/login/logi ...
- MySQL数据库监控
MySQL MTOP由PHP和Python开发,所以监控机需要安装PHP运行环境和Python环境.需要的核心包如下: 1.MySQL 5.0及以上(用来存储监控系统采集的数据) 2.Apache 2 ...
- loadrunner通过C语言实现字符的替换(只能替换单个字符,慎用)
如果按照普通的定义字符串就会出现以下错误: 解决方法如下: 将双引号改成单引号: lr_searchReplace(abc,"test",' ','+'); Action也可以这些 ...
- cvKMeans2函数用法概述
一般情况下,我们通过C++/Matlab/Python等语言进行实现K-means算法,结合近期我刚刚学的C++,先从C++实现谈起,C++里面我们一般采用的是OpenCV库中写好的K-means函数 ...
- Mysql远程连接,并解决wordp主题添加问题
1.增加允许远程连接 MySQL 用户并授权. 在 Linux 主机中在命令提示行下输入下面的命令. > MySQL -uroot -p 密码 2.创建远程登陆用户并授权 grant all P ...
- Something about "for"
For语句引导了一个循环语句,格式for(::),例for(int i=0;i<100;i++).类似于if()括号的作用for()括号如同if()括号一样也是一个boolean型.int i= ...
- 17243 Huzi酱和他的俄罗斯套娃(贪心)
时间限制:500MS 内存限制:65535K 提交次数:15 通过次数:4 收入:12 题型: 编程题 语言: C++;C Description Huzi酱是个非常贪玩的人,除了魔方他还喜欢各 ...