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 ...
随机推荐
- Ugly number丑数2,超级丑数
[抄题]: [思维问题]: [一句话思路]:Long.valueOf(2)转换为long型再做 [输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入): [画图 ...
- php Pthread 多线程 (三) Mutex 互斥量
当我们用多线程操作同一个资源时,在同一时间内只能有一个线程能够对资源进行操作,这时就需要用到互斥量了.比如我们对同一个文件进行读写操作时. <?php class Add extends Thr ...
- 记录java版本不兼容的坑,(kafka运行报错)
启动kafka报错 错误原因是: 由较高版本的jdk编译的java class文件 试图在较低版本的jvm上运行的报错 解决办法是: 查看java版本 C:\Users\Administrator&g ...
- Linux动态共享库
Linux操作系统上面的动态共享库大致分为三类: 一.操作系统级别的共享库和基础的系统工具库 libc.so, libz.so, libpthread.so等等,这些系统库会被放在/lib和/us ...
- Java中弹出对话框中的几种方式
1.显示一个错误对话框,该对话框显示的 message 为 'alert': JOptionPane.showMessageDialog(null, "alert", " ...
- OC调用Swift
Step by step swift integration for Xcode Objc-based project: Create new *.swift file (in Xcode) or a ...
- 【Java】Eclipse在线安装SVN插件
安装环境 系统:win7系统 软件:eclipse(Mars.2 Release (4.5.2)) 安装步骤 1. 打开eclipse软件,点击菜单栏的help——>Install New So ...
- ABP框架 - 缓存( 转)
出处:http://www.cnblogs.com/kid1412/p/5987083.html 文档目录 本节内容: 简介 ICacheManager ICache ITypedCache 配置 实 ...
- IntelliJ IDEA 2017版 spring-boot修改端口号配置把端口号改为8081
1.修改端口号主要是通过配置文件修改.如图: 完整版配置 ######################################################## ###server 配置信息 ...
- 'org.springframework.web.filter.CharacterEncodingFilter' is not assignable to 'javax.servlet.Filter,This inspection lets you spot the following problems that might occur in descriptors that are used t
1.jar包导入错误,因为maven下载的原因: 删除这样的包,然后让maven重新下载,问题就会解决