hdu 4325 Flowers(区间离散化)
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): 2633 Accepted Submission(s): 1290
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<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm> using namespace std; typedef long long ll;
const int N = ;
const int INF = 0x3f3f3f3f; int c[ * N], a[N], b[N], used[N], d[N]; int cmp(const void *a, const void *b)
{
return *(int *)a - *(int *)b;
} int main()
{
int t, n, m, f = ;
int p, q, k, e;
scanf("%d", &t);
while(t--)
{
f++;
k = ;
memset(used, , sizeof(used));
scanf("%d%d", &n, &m);
for(int i = ; i < n ; i++)
{
scanf("%d%d", &p, &q);
a[i] = p;
b[i] = q;
c[k++] = p;
c[k++] = p - ;/***///这里为嘛,个人认为是防止查询的数比q要小
c[k++] = q;
c[k++] = q + ;/***/
} qsort(c, k, sizeof(c[]), cmp); k = unique (c, c + k)- c;//去重
int x, y, maxn = -INF;
for(int i = ; i < n ; i++)
{
x = lower_bound(c, c + k, a[i]) - c;
y = lower_bound(c, c + k, b[i]) - c;
used[x]++;
used[y + ]--;
maxn = max(maxn, y + );
} for(int i = ; i < maxn ; i++)
used[i + ] += used[i]; printf("Case #%d:\n", f);
while(m--)
{
scanf("%d", &e);
int s = lower_bound(c, c + k, e) - c; printf("%d\n", used[s]);
}
}
return ;
}
hdu 4325 Flowers(区间离散化)的更多相关文章
- HDU 4325 Flowers(树状数组+离散化)
http://acm.hdu.edu.cn/showproblem.php?pid=4325 题意:给出n个区间和m个询问,每个询问为一个x,问有多少个区间包含了x. 思路: 因为数据量比较多,所以需 ...
- HDU 4325 Flowers 树状数组+离散化
Flowers Problem Description As is known to all, the blooming time and duration varies between differ ...
- HDU 4325 Flowers(树状数组)
Flowers Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- hdoj 4325 Flowers 线段树+离散化
hdoj 4325 Flowers 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4325 思路: 直接线段树,按照花的开放区间的大小建树,要注意虽然 ...
- (线段树 区间运算求点)Flowers -- hdu -- 4325
http://acm.hdu.edu.cn/showproblem.php?pid=4325 Flowers Time Limit: 4000/2000 MS (Java/Others) Mem ...
- hdu 3436 splay树+离散化*
Queue-jumpers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- HDU 5862 Counting Intersections(离散化+树状数组)
HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...
- HDU 5726 GCD 区间GCD=k的个数
GCD Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- POJ 2528 Mayor's posters 【区间离散化+线段树区间更新&&查询变形】
任意门:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total S ...
随机推荐
- python之用户登陆作业
实现一个用户登陆的小程序,如果密码错误,可以重试三次,如果三次均错误,则锁定 数据库如下格式,分别用户名|密码|锁定,其中锁定字段0为正常,1为被锁定 root|admin123|0 admin|ad ...
- python笔记之循环控制
学习python的第一个例子,while循环中嵌套if-else语句,一个猜年龄的例子 #案例1,实现循环猜年龄 # my_age = 12 # while True: # guess_age1 = ...
- How to add libraries to “External Libraries” in WebStorm/PhpStorm/Intellij
Stack Overflow Questions Developer Jobs Tags Users Log In Sign Up Join Stack Overflow to learn, sh ...
- Ubuntu 网卡多个 IP 地址
临时添加 IP 地址 首先,让我们找到网卡的 IP 地址.在我的 Ubuntu 15.10 服务器版中,我只使用了一个网卡. 运行下面的命令找到 IP 地址: 复制代码 代码如下: sudo ip a ...
- [SoapUI] 通过正则表达式从xml格式的response中提取ID
import com.eviware.soapui.support.GroovyUtils import java.util.regex.* //Get response def groovyUtil ...
- Python3 urllib库和requests库
1. Python3 使用urllib库请求网络 1.1 基于urllib库的GET请求 请求百度首页www.baidu.com ,不添加请求头信息: import urllib.requests d ...
- setTimeout setInterval 详解
http://www.jb51.net/article/74606.htm var tttt=setTimeout('northsnow()',1000);//执行一次 clearTimeou ...
- ubuntu系统中安装RoboMongo
1.下载RoboMongo RoboMongo官网下载链接.选择好相应版本. 2.解压文件 tar -xzf robomongo--linux-x86_64-.tar.gzcd robomongo-0 ...
- c++编程思想里面的错误(可能c++标准变了,所以以前的东西没有更新)
第一卷 第五章 5.3友元 下面的代码是<c++编程思想>里面的代码, struct X; struct Y{ void f(X*); }; struct X{ private: int ...
- Devexpress VCL Build v2013 vol 13.2.4 发布
不说了,自己看吧. What's New in 13.2.4 (VCL Product Line) New Major Features in 13.2 What's New in VCL Pro ...