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 ...
随机推荐
- POJ 3241 Object Clustering 曼哈顿最小生成树
Object Clustering Description We have N (N ≤ 10000) objects, and wish to classify them into severa ...
- Windows服务定时执行任务
1.创建多线程类 /// <summary> /// 多线程 /// </summary> public abstract class MuliThread<T> ...
- 【转】最近搞Hadoop集群迁移踩的坑杂记
http://ju.outofmemory.cn/entry/237491 Overview 最近一段时间都在搞集群迁移.最早公司的hadoop数据集群实在阿里云上的,机器不多,大概4台的样子,据说每 ...
- PS切图的几种方式
方法一 点击图层右键-->导出为 导出需要的格式与大小 方法二 选择多个图层右键--->快速导出为PNG(导出的名字就是图层名字) 方法三
- react-redux(1)
基础 Array.prototype.reduce //类似的核心思想 const initState = ''; const actions = ['a', 'b', 'c']; const new ...
- js-新兴的API,最佳实践,离线应用于客户端存储
离线应用于客户端存储: 1.离线检测:online以及offline事件,都是在window对象上触发 navigator.online为true的时候是表示设备能够上网 2.使用一个描述文件(man ...
- EF框架step by step(2)—Model-First
这一篇主要说一下EF框架中,Model First做法,仍然采用上一篇的案例.但增加评论功能.首先打开Blog.edmx文件,在空白处右键,添加新实体Comment,如下图示: 点击确定,关闭窗口. ...
- 类型“System.Windows.Markup.IQueryAmbient”在未被引用的程序集中定义
错误 1 类型"System.Windows.Markup.IQueryAmbient"在未被引用的程序集中定义.必须添加对程序集"System.Xaml, ...
- ural 1255. Graveyard of the Cosa Nostra
1255. Graveyard of the Cosa Nostra Time limit: 1.0 secondMemory limit: 64 MB There is a custom among ...
- 盐水的故事[HDU1408]
盐水的故事Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissio ...