HDU4325--Flowers--树状数组,离散化
Description
As 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.
Input
The first line contains a single integer t (1 <= t <= 10), the number of test cases.
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 S i and T i (1 <= S i <= T i <= 10^9), means i-th flower will be blooming at time [S i, T i].
In the next M lines, each line contains an integer T i, means the time of i-th query.
Output
For 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.
Sample Input
2
1 1
5 10
4
2 3
1 4
4 8
1
4
6
Sample Output
Case #1:
0
Case #2:
1
2
1
很简单的一道树状数组的改段求点的模版题,基本思想是:tree[]为树状数组,N个元素,tree[i]存放的是i至N被加了多少,
所以,修改[l,r]区间值的操作就变为了,
update(l,1);
update(r+1,-1);
查询某点的操作就变为了查询此点的前缀和
需要注意的是,此题目的数据范围太大,需要进行离散化1 (关于离散化,会再写一篇博客)
```c++
#include
#include
#include
#include
#include
using namespace std;
const int M=100100;
int tree[M];
int q[M];
int N=0;
map ls;
struct node
{
int le;
int ri;
}a[M];
int lowbits(int x)
{
return x&(-x);
}
void update(int i,int val)
{
for(;i0;i-=lowbits(i)){
sum+=tree[i];
}
return sum;
}
void init()
{
memset(tree,0,sizeof(tree));
ls.clear();
}
int main()
{
freopen("data.in","r",stdin);
int m,n;
int t;
int l,r;
int tem;
int casn=1;
cin>>t;
while(t--){
cout>n>>m;
for(int i=0;i>l>>r;
if(ls.find(l)==ls.end()) ls.insert(make_pair(l,1));
if(ls.find(r)==ls.end()) ls.insert(make_pair(r,1));
a[i].le=l;a[i].ri=r;
}
for(int i=0;i>l;
if(ls.find(l)==ls.end()) ls.insert(make_pair(l,1));
q[i]=l;
}
int i=1;
for(map::iterator ite=ls.begin();ite!=ls.end();ite++){
ite->second=i++;
}
N=i-1;
for(int i=0;i
HDU4325--Flowers--树状数组,离散化的更多相关文章
- HDU 4325 Flowers 树状数组+离散化
Flowers Problem Description As is known to all, the blooming time and duration varies between differ ...
- hdu4605 树状数组+离散化+dfs
Magic Ball Game Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- BZOJ_5055_膜法师_树状数组+离散化
BZOJ_5055_膜法师_树状数组+离散化 Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然 ...
- POJ 2299 【树状数组 离散化】
题目链接:POJ 2299 Ultra-QuickSort Description In this problem, you have to analyze a particular sorting ...
- HDU4325 树状数组+离散化
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4325 Flowers Time Limit: 4000/2000 MS (Java/Others) ...
- [HDOJ4325]Flowers(树状数组 离散化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4325 关于离散化的简介:http://blog.csdn.net/gokou_ruri/article ...
- HDU 4325 Flowers(树状数组+离散化)
http://acm.hdu.edu.cn/showproblem.php?pid=4325 题意:给出n个区间和m个询问,每个询问为一个x,问有多少个区间包含了x. 思路: 因为数据量比较多,所以需 ...
- BZOJ-1227 虔诚的墓主人 树状数组+离散化+组合数学
1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec Memory Limit: 259 MB Submit: 914 Solved: 431 [Submit][Statu ...
- POJ 2299 树状数组+离散化求逆序对
给出一个序列 相邻的两个数可以进行交换 问最少交换多少次可以让他变成递增序列 每个数都是独一无二的 其实就是问冒泡往后 最多多少次 但是按普通冒泡记录次数一定会超时 冒泡记录次数的本质是每个数的逆序数 ...
- Bzoj 1901: Zju2112 Dynamic Rankings 主席树,可持久,树状数组,离散化
1901: Zju2112 Dynamic Rankings Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 6321 Solved: 2628[Su ...
随机推荐
- C - 娜娜梦游仙境系列——吃不完的糖果
C - 娜娜梦游仙境系列——吃不完的糖果 Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Oth ...
- 灰色关联度Matlab代码
load x.txt %把原始数据存放在纯文本文件x.txt中,其中把数据的"替换替换成. for i=1:40x(i,:)=x(i,:)/x(i,1); %标准化数据end data=x; ...
- elasticsearch 批量插入
将下面数据写入requests { "create": { "_index": "index1", "_type": & ...
- Html的Table与Echart的饼图实现联动效果
功能描述: 单击Table中的某个单元格,Echart的饼图加载相关的数据,鼠标悬停在Echarts饼图中的某一块中,Table显示与Echarts饼图相关的数据. 例:楼宇经济概要显示每一个季度所有 ...
- margin的auto的理解
auto 总是试图充满父元素 margin有四个值: All the margin properties can have the following values: auto - the brows ...
- 十三、oracle 数据字典和动态性能视图
一.概念数据字典是oracle数据库中最重要的组成部分,它提供了数据库的一些系统信息.动态性能视图记载了例程启动后的相关信息. 二.数据字典1).数据字典记录了数据库的系统信息,它是只读表和视图的集合 ...
- CSS样式与选择器
CSS构造块的样式: 1. h1{color:red;background-color:yellow} 其中:h1是选择器,花括号内是声明部分.多个声明之间用分号隔开. 2.为样式规则添加注释:/* ...
- nodejs全局安装与本地安装区别
本地安装 1. 将安装包放在 ./node_modules 下(运行 npm 命令时所在的目录),如果没有 node_modules 目录,会在当前执行 npm 命令的目录下生成 node_modul ...
- LeetCode OJ 96. Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...
- 官方windows10升级工具
https://www.microsoft.com/zh-cn/software-download/windows10