(线段树 区间运算求点)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 ...
随机推荐
- 10.24JS日记
1.函数都有返回值,人为return,返回什么就是什么,否则,他的返回值就是undefined 而方法的本质也是函数,所以也有返回值 document.getElementById()返回的是获取的标 ...
- jquery 进阶 bootstrap
. 样式操作 . 操作class . 操作CSS属性的 .css("color") .css("color", "green") .css( ...
- Oracle_PL/SQL(6) 触发器(序列、视图)
序列1.创建序列create sequence seq_alog start with 1 increment by 1 maxvalue 999999999999999999999999999 mi ...
- layer.confirm在ASP.NET控件onclick上面的应用方法
有些时候,你可能要修改控件的事件,元素本身.等,这个时候如何操作呢?下面提供一个思路: <asp:LinkButton Visible="false" ID="sh ...
- (转)Eclipse中需要查看某个类的源码,直接按住Ctrl 然后点击想要查看的类或则方法
文章转自:http://blog.sina.com.cn/s/blog_52f623240102vpcr.html 在Eclipse中需要查看某个类的源码,直接按住Ctrl 然后点击想要查看的 ...
- 关于sublime Text 3安装sublimecodeIntel插件配置方法
打开preferences-package settings-sublimecodeIntel-settings users 添加 { "JavaScript": { " ...
- css font-size=0的妙用
转自:css font-size=0有什么妙用? 回答一: 问题的根源是 inline(a标签默认是display:inline) 和 inline-block (.list-info 设置的是 di ...
- andorid 菜单 进度条
activity_ui2.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout x ...
- robotframework 运行集合
Robot Framework 运行测试通过 pybot 命令,检查 _C:\Python36\Scripts_ 目录下是否有 pybot.bat 文件,正确安装 Robot Framework 一定 ...
- mysql 5.7.10 下互为主备配置
mysql安装方法这里就不在介绍,网上有很多教程 环境介绍: A主机: win2008_x64+mysql5.7.10 64位,ip192.168.7.180 B主机: win2008_x64+mys ...