(线段树 区间运算求点)Flowers -- hdu -- 4325
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
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.
Sample outputs are available for more details.
#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的更多相关文章
- hdu 1754 I Hate It(线段树区间求最值)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu4521-小明系列问题——小明序列(线段树区间求最值)
题意:求最长上升序列的长度(LIS),但是要求相邻的两个数距离至少为d,数据范围较大,普通dp肯定TLE.线段树搞之就可以了,或者优化后的nlogn的dp. 代码为 线段树解法. #include ...
- 模板—字符串—后缀自动机(后缀自动机+线段树合并求right集合)
模板—字符串—后缀自动机(后缀自动机+线段树合并求right集合) Code: #include <bits/stdc++.h> using namespace std; #define ...
- HDU 1828“Picture”(线段树+扫描线求矩形周长并)
传送门 •参考资料 [1]:算法总结:[线段树+扫描线]&矩形覆盖求面积/周长问题(HDU 1542/HDU 1828) •题意 给你 n 个矩形,求矩形并的周长: •题解1(两次扫描线) 周 ...
- [HDU] 2795 Billboard [线段树区间求最值]
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 2795.Billboard-完全版线段树(区间求最值的位置、区间染色、贴海报)
HDU2795.Billboard 这个题的意思就是在一块h*w的板子上贴公告,公告的规格为1*wi ,张贴的时候尽量往上,同一高度尽量靠左,求第n个公告贴的位置所在的行数,如果没有合适的位置贴则输出 ...
- 离散化+线段树/二分查找/尺取法 HDOJ 4325 Flowers
题目传送门 题意:给出一些花开花落的时间,问某个时间花开的有几朵 分析:这题有好几种做法,正解应该是离散化坐标后用线段树成端更新和单点询问.还有排序后二分查找询问点之前总花开数和总花凋谢数,作差是当前 ...
- 树状数组 && 线段树应用 -- 求逆序数
参考:算法学习(二)——树状数组求逆序数 .线段树或树状数组求逆序数(附例题) 应用树状数组 || 线段树求逆序数是一种很巧妙的技巧,这个技巧的关键在于如何把原来单纯的求区间和操作转换为 求小于等于a ...
- 扫描线 + 线段树 : 求矩形面积的并 ---- hnu : 12884 Area Coverage
Area Coverage Time Limit: 10000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit user ...
随机推荐
- vue通过代理实现跨域
http://www.cnblogs.com/wangyongcun/p/7665687.html
- jquery插件之选项卡
jQuery插件编写 首先来一个简拓展jQuery对象的方法 <body > <p>23</p> <script src="js/jquery-1. ...
- 引用类型中的push()、pop()、shift()方法
/** * write by waitingbar1014 * time 2013.10.18 * 用途:常用于如一堆游戏激活码中获得抽取的值 * **/ //有以下一个数组: var arrayli ...
- if __name__ == '__main__的理解
模块之间引用不能循环成环,圆圈 模块的收搜 !!!把模块当作脚本执行 什么叫模块:py文件,如果一个py文件被导入了,他就是一个模块, 模块没有具体的调用过程 但是能对外提供功能 什么叫脚 ...
- 强大的easygrid V7 ,可联系作者
增加历史记录事件 修改bug 修改风格 演示绑定表达式 下载demo
- for 循环分解
for (expression1; expression2; expression3) { statement; } statement称为循环体 expression1为初始化部分,只在循环开始前执 ...
- swift 中使用weak self
request.responseString(encoding: NSUTF8StringEncoding) {[weak self] (res) -> Void in if let stron ...
- Mysql 注入load_file常用路径
WINDOWS下: c:/boot.ini //查看系统版本 c:/windows/php.ini //php配置信息 c:/windows/my.ini //MYSQL配置文件,记录管理员登陆过的M ...
- c++11 并发 条件变量 超时等待的代码练习
资料地址 http://en.cppreference.com/w/cpp/thread/condition_variable/wait_until http://www.cnblogs.com/ha ...
- Partition Array into Disjoint Intervals LT915
Given an array A, partition it into two (contiguous) subarrays left and right so that: Every element ...