http://acm.hdu.edu.cn/showproblem.php?pid=4325

Flowers

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

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
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<queue>
using namespace std; #define N 110000
#define MOD 100000007
#define Lson r<<1
#define Rson r<<1|1 struct node
{
int L, R, e;
int Mid()
{
return (L+R)/;
}
}a[N<<]; void BuildTree(int r, int L, int R)
{
a[r].L=L, a[r].R=R, a[r].e=; if(L==R)
return ; BuildTree(Lson, L, a[r].Mid());
BuildTree(Rson, a[r].Mid()+, R);
} void Update(int r, int L, int R)
{
if(a[r].L==L && a[r].R==R)
{
a[r].e++;
return ;
} if(R<=a[r].Mid())
return Update(Lson, L, R);
else if(L>a[r].Mid())
return Update(Rson, L, R);
else
{
Update(Lson, L, a[r].Mid());
Update(Rson, a[r].Mid()+, R);
}
} void UP(int r, int L, int R)
{
if(L==R)
return ; if(a[r].L==L && a[r].R==R )
{
a[Lson].e += a[r].e;
a[Rson].e += a[r].e;
} if(R<=a[r].Mid())
UP(Lson, L, R);
else if(L>a[r].Mid())
UP(Rson, L, R);
else
{
UP(Lson, L, a[r].Mid());
UP(Rson, a[r].Mid()+, R);
}
} int Query(int r, int x)
{
if(a[r].L==a[r].R && a[r].L==x)
return a[r].e; if(x<=a[r].Mid())
return Query(Lson, x);
else
return Query(Rson, x);
} int main()
{
int T, iCase=;
scanf("%d", &T);
while(T--)
{
int n, m, i, L, R, x; scanf("%d%d", &n, &m); BuildTree(, , ); for(i=; i<n; i++)
{
scanf("%d%d", &L, &R);
Update(, L, R);
} UP(, , ); printf("Case #%d:\n", iCase++);
for(i=; i<m; i++)
{
scanf("%d", &x);
printf("%d\n", Query(, x));
}
}
return ;
}

(线段树 区间运算求点)Flowers -- hdu -- 4325的更多相关文章

  1. hdu 1754 I Hate It(线段树区间求最值)

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. hdu4521-小明系列问题——小明序列(线段树区间求最值)

    题意:求最长上升序列的长度(LIS),但是要求相邻的两个数距离至少为d,数据范围较大,普通dp肯定TLE.线段树搞之就可以了,或者优化后的nlogn的dp. 代码为  线段树解法. #include ...

  3. 模板—字符串—后缀自动机(后缀自动机+线段树合并求right集合)

    模板—字符串—后缀自动机(后缀自动机+线段树合并求right集合) Code: #include <bits/stdc++.h> using namespace std; #define ...

  4. HDU 1828“Picture”(线段树+扫描线求矩形周长并)

    传送门 •参考资料 [1]:算法总结:[线段树+扫描线]&矩形覆盖求面积/周长问题(HDU 1542/HDU 1828) •题意 给你 n 个矩形,求矩形并的周长: •题解1(两次扫描线) 周 ...

  5. [HDU] 2795 Billboard [线段树区间求最值]

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. HDU 2795.Billboard-完全版线段树(区间求最值的位置、区间染色、贴海报)

    HDU2795.Billboard 这个题的意思就是在一块h*w的板子上贴公告,公告的规格为1*wi ,张贴的时候尽量往上,同一高度尽量靠左,求第n个公告贴的位置所在的行数,如果没有合适的位置贴则输出 ...

  7. 离散化+线段树/二分查找/尺取法 HDOJ 4325 Flowers

    题目传送门 题意:给出一些花开花落的时间,问某个时间花开的有几朵 分析:这题有好几种做法,正解应该是离散化坐标后用线段树成端更新和单点询问.还有排序后二分查找询问点之前总花开数和总花凋谢数,作差是当前 ...

  8. 树状数组 && 线段树应用 -- 求逆序数

    参考:算法学习(二)——树状数组求逆序数 .线段树或树状数组求逆序数(附例题) 应用树状数组 || 线段树求逆序数是一种很巧妙的技巧,这个技巧的关键在于如何把原来单纯的求区间和操作转换为 求小于等于a ...

  9. 扫描线 + 线段树 : 求矩形面积的并 ---- hnu : 12884 Area Coverage

    Area Coverage Time Limit: 10000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit user ...

随机推荐

  1. mysql --secure-file-priv is set to NULL.Operations related to importing and exporting data are disabled

    --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabledmy ...

  2. c# 24种设计模式

    备忘录模式(Memento Pattern) 策略模式(Strategy Pattern) 抽象工厂模式(Abstract Factory Pattern) 代理模式(Proxy Pattern) 单 ...

  3. c# 关于取小数点后值四舍五入精度问题

    ---恢复内容开始--- 最近做一个校验码验证法算法的生成程序,涉及到取小数点后值的问题;对其中遇到的问题做一下总结: 1:ToString()转换时碰到0.9999999999999之类的数据,给自 ...

  4. PAT 1037 在霍格沃茨找零钱(20)(代码+思路)

    1037 在霍格沃茨找零钱(20)(20 分) 如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 -- 就如海格告诉哈利的:"十七个银西可(Sickle)兑一个加隆(Galleon) ...

  5. JVM 体系结构概述 (一)

    一.jvm运行在操作系统之上的,它与硬件没有直接交互: 二.JVM体系结构概览 JVM的基本结构:类加载器.执行引擎.运行时数据区.本地方法接口: 过程:class文件 ----> 类加载器 - ...

  6. Android.InstallAntOnMacOSX

    在Mac OS X上安装ant http://blog.csdn.net/crazybigfish/article/details/18215439

  7. JoyOI1035 棋盘覆盖

    原题链接 对棋盘染色,坐标和为奇数的染黑,偶数为白.这时会发现对于相同颜色的格子,是无法放置骨牌的,这样我们就将所有格子分成两类,然后根据能否放置骨牌连边,最后就是求二分图最大匹配了. 这里我是用的匈 ...

  8. 0 or 1,1 and 0

    最近小编遇到很头疼的的一件事 就是以下这几道运算题 ,以下结果是小编经过大量的运算得出的 一.或运算 1.0 or 1 结果为:1 2.1 or 0 结果为:1 3.1 or 2 结果为:1 4.2 ...

  9. django DEBUG=False

    在django的settings中. 将DEBUG 设置为False. 会出现 #python manage.py runserver 8888 CommandError: You must set ...

  10. 【Linux】CentOS 7.4 安装 MySQL 8.0.12 解压版

    安装环境/工具 1.Linux(CentOS 7.4版) 2.mysql-8.0.12-el7-x86_64.tar.gz 安装步骤 参考:https://dev.mysql.com/doc/refm ...