HDU4325-Flowers
来源:互联网 发布:淘宝基础版不能设背景 编辑:程序博客网 时间:2024/06/03 20:25
Flowers
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 3290 Accepted Submission(s): 1630
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.
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 outputs are available for more details.
Sample Input
21 15 1042 31 44 8146
Sample Output
Case #1:0Case #2:121
Author
BJTU
Source
2012 Multi-University Training Contest 3
Recommend
zhoujiaqi2010
题意:给你n多花的开放时间,问一个时间有多少花开放
解题思路:先将所有时间离散化,然后就是维护树状数组,区间修改求单点
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <algorithm>#include <queue>#include <vector>#include <set>#include <stack>#include <map>#include <climits>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;int n, q;int x[300009], t[300009],a[100009],l[100009],r[100009],m;int lowbit(int k){return k&-k;}void update(int k,int val){while (k <m){x[k]+=val;k += lowbit(k);}}int getsum(int k){int sum = 0;while (k){sum += x[k];k -= lowbit(k);}return sum;}int main(){int T,cas=0;scanf("%d", &T);while (T--){int cnt = 1;memset(x, 0, sizeof x);scanf("%d%d", &n,&q);for (int i = 1; i <= n; i++){scanf("%d%d", &l[i], &r[i]);t[cnt++] = l[i];t[cnt++] = r[i];}for (int i = 1; i <= q; i++) scanf("%d", &a[i]), t[cnt++] = a[i];sort(t+1, t + cnt);m = unique(t+1, t + cnt) - t;for (int i = 1; i <= n; i++){int ll = lower_bound(t+1, t + m, l[i]) - t;int rr = lower_bound(t+1, t + m, r[i]) - t;update(ll, 1); update(rr + 1, -1);}printf("Case #%d:\n", ++cas);for (int i = 1; i <= q; i++){int aa = lower_bound(t, t + m, a[i]) - t;printf("%d\n", getsum(aa));}}return 0;}
阅读全文
0 0
- hdu4325 Flowers
- HDU4325-Flowers
- 【线段树】 hdu4325 Flowers
- 【hdu4325】【线段树】Flowers 动态建树
- hdu4325-Flowers-2012 Multi-University Training Contest 3-题解
- hdu4325 Flowers【树状数组区间更新单点求值 离散化】
- flowers
- Flowers
- Flowers
- hdu4325线段树+离散化
- hdu4325 树状数组+离散化
- hdu1587 Flowers
- HDU1587:Flowers
- HDU Flowers
- F - Flowers
- D. Flowers
- 1002: Flowers
- HDU1587-Flowers
- Android平台dalvik模式下java Hook框架ddi的分析(1)
- 我的CV路
- ActivityManager框架之简要
- 关于java中的文件读写java io【复习1】
- RecyclerView 的简单使用
- HDU4325-Flowers
- 【Linux基础系列之】同步机制介绍
- python之read和tell 和SEEK_SET、SEEK_CUR、SEEK_END
- Linux Shell脚本之利用mysqldump备份MySQL数据库(详细注解)
- java与javac版本不一致问题
- Windows操作系统下安装MAC OS系统虚拟机
- nginx+keepalived实现高可用
- 30分钟了解php依赖管理工具Composer
- 性能优化:__builtin_expect详解