Flowers

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3150    Accepted Submission(s): 1549

Problem 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 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.
 
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
 
Author
BJTU
 
Source

/*
给你每一朵话的开花时间段,询问你某一时刻的开花数量
*/ /*
重新定义树状数组的意义,不再是前i个数的和,而是第i个位置的数值
*/
/*
明显数据会爆的,我去.....数据太水了
*/
#include<iostream>
#include<string.h>
#include<stdio.h>
#define N 100010
using namespace std;
int c[N],T[N];
int t;
int n,m;
int lowbit(int x)
{
return x&(-x);
}
void update(int x,int val)
{
while(x<=N)
{
c[x]+=val;
x+=lowbit(x);
}
}
int getsum(int x)
{
int s=;
while(x>)
{
s+=c[x];
x-=lowbit(x);
}
return s;
}
int main()
{
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
scanf("%d",&t);
for(int Case=;Case<=t;Case++)
{
memset(c,,sizeof c);
scanf("%d%d",&n,&m);
//cout<<"n="<<n<<" "<<"m="<<m<<endl;
int si,ti;
for(int i=;i<n;i++)
{
scanf("%d%d",&si,&ti);
//cout<<si<<" "<<ti<<endl; update(si,); // for(int j=si;j<=ti;j++)
// update(j,1);
update(ti+,-);
}
for(int i=;i<m;i++)
scanf("%d",&T[i]);
printf("Case #%d:\n",Case);
// for(int i=1;i<10;i++)
// printf("%d\n",getsum(i));
for(int i=;i<m;i++)
{
//cout<<"T[i]="<<T[i]<<" "<<"T[i]-1="<<T[i]-1<<endl;
printf("%d\n",getsum(T[i]));
}
}
}

HDU 4325 Flowers(树状数组)的更多相关文章

  1. HDU 4325 Flowers 树状数组+离散化

    Flowers Problem Description As is known to all, the blooming time and duration varies between differ ...

  2. HDU 4325 离散化+树状数组 或者 不使用树状数组

    题意:给出一些花的开放时间段,然后询问某个时间点有几朵花正在开放. 由于ti<1e9,我们需要先将时间离散化,然后将时间点抽象为一个数组中的点,显然,我们需要进行区间更新和单点查询,可以考虑线段 ...

  3. HDU 2838 (DP+树状数组维护带权排序)

    Reference: http://blog.csdn.net/me4546/article/details/6333225 题目链接: http://acm.hdu.edu.cn/showprobl ...

  4. HDU 2689Sort it 树状数组 逆序对

    Sort it Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  5. hdu 4046 Panda 树状数组

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4046 When I wrote down this letter, you may have been ...

  6. hdu 5497 Inversion 树状数组 逆序对,单点修改

    Inversion Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5497 ...

  7. HDU 5493 Queue 树状数组

    Queue Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5493 Des ...

  8. POJ 2352 &amp;&amp; HDU 1541 Stars (树状数组)

    一開始想,总感觉是DP,但是最后什么都没想到.还暴力的交了一发. 然后開始写线段树,结果超时.感觉自己线段树的写法有问题.改天再写.先把树状数组的写法贴出来吧. ~~~~~~~~~~~~~~~~~~~ ...

  9. hdu 1541 (基本树状数组) Stars

    题目http://acm.hdu.edu.cn/showproblem.php?pid=1541 n个星星的坐标,问在某个点左边(横坐标和纵坐标不大于该点)的点的个数有多少个,输出n行,每行有一个数字 ...

  10. hdu 4031(树状数组+辅助数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4031 Attack Time Limit: 5000/3000 MS (Java/Others)    ...

随机推荐

  1. 为ASP.NetCore程序启用SSL

    紧接着上一篇搭建连接MySql的三层架构的ASP.NetCore2.0的WebApi的案例,这篇来实现为ASP.NetCore启用SSL支持 由于ASP.NetCore默认服务器Kestrel不像ii ...

  2. DotNetCore跨平台~linux上还原自主nuget包需要注意的问题

    问题的产生的背景 由于我们使用了jenkins进行部署(jenkins~集群分发功能和职责处理),而对于.net core项目来说又是跨平台的,所以对它的项目拉取,包的还原,项目的编译和项目的发布都是 ...

  3. 实际开发--->php时间函数

    当前日期(例:2017-10-04):date('Y-m-d',time()); 当前时间戳:strtotime(date('Y-m-d H-i-s',time()); 当前年月(例:2017-10) ...

  4. Python多线程练习(threading)

    这几天学习python多线程的时候,试了几次thread模块和threading模块,发现thread模块非常的不好用.强烈不建议大家使用thread,建议使用threading模块,此模块对thre ...

  5. 使用Scrapy创建一个爬虫

    使用Scrapy创建一个爬虫 创建项目 您可以使用下面的命令来创建 Scrapy 项目: scrapy startproject 项目名称 例:scrapy startproject scrapy_p ...

  6. PowerBI开发 第七篇:数据集和数据刷新

    PowerBI报表是基于数据分析的引擎,数据真正的来源(Data Source)是数据库,文件等数据存储媒介,PowerBI支持的数据源类型多种多样.PowerBI Service(云端)有时不直接访 ...

  7. Python实战之用类的静态方法实现登录验证

    #!usr/bin/env Python3 # -*-coding:utf-8-*- __author__="William" #define a class,just to le ...

  8. HDU 1219 AC Me

    strlen能不用就不用 #include<cstdio> #include<cstdlib> #include<iostream> #include<alg ...

  9. Java web AJAX入门

    一:AJAX简介 AJAX :Asynchronous JavaScript And XML 指异步 JavaScript 及 XML 一种日渐流行的Web编程方式 Better Faster Use ...

  10. asp.net调用Lodop实现页面打印或局部打印,可进行打印设置或预览

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebPrint.aspx.cs ...