题目链接: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): 3544    Accepted Submission(s): 1745

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.
 
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 Input
2
1 1
5 10
4
2 3
1 4
4 8
1
4
6
 
Sample Output
Case #1:
0
Case #2:
1
2
1
 
Author
BJTU
 
Source
 
题意  n朵花 m个时间点 第i朵花正在开放的时间是si,ti   问:在第mi个时间点有多少朵花正在开放
解析  思路是 我们记录每个时间点有多少个花是开放的   树状数组可以解决 但是数据太大会超时也存不下 数据数量还是比较少的 所以我们可以离散化一下 我们要把m也离散化进去
AC代码
 #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <vector>
#include <iomanip>
using namespace std;
const int maxn = 3e5+;
const int maxm = 1e4+;
const int inf = 0x3f3f3f3f;
const int mod = ;
const double epx = 1e-;
typedef long long ll;
const ll INF = 1e18;
const double pi = acos(-1.0);
int c[maxn],rankk[maxn];
int n,m,t;
struct node
{
int id,x;
bool operator<(const node &b)const
{
return x<b.x;
}
}a[maxn];
int lowbit(int x)
{
return x&(-x);
}
int getsum(int x)
{
int ans=;
for(int i=x;i>;i-=lowbit(i))
ans+=c[i];
return ans;
}
void update(int x,int y,int z)
{
for(int i=x;i<=y;i+=lowbit(i))
c[i]+=z;
}
int main()
{
int kase=;
cin>>t;
while(t--)
{
cin>>n>>m;
memset(c,,sizeof(c));
memset(rankk,,sizeof(rankk));
int temp=*n+m;
for(int i=;i<=temp;i++)
{
scanf("%d",&a[i].x);
a[i].id=i;
}
sort(a+,a++temp);
int k=;
rankk[a[].id]=k;
for(int i=;i<=temp;i++)
{
if(a[i].x==a[i-].x)
rankk[a[i].id]=k;
else
rankk[a[i].id]=++k;
}
for(int i=;i<*n;i+=)
{
update(rankk[i],k,);
update(rankk[i+]+,k,-);
}
printf("Case #%d:\n",kase++);
for(int i=*n+;i<=temp;i++)
{
printf("%d\n",getsum(rankk[i]));
}
}
}

离散化博客    https://blog.csdn.net/xiangaccepted/article/details/73276826

数据比较水 不离散化也可以水过去。。

HDU4325 树状数组+离散化的更多相关文章

  1. hdu4605 树状数组+离散化+dfs

    Magic Ball Game Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  2. BZOJ_5055_膜法师_树状数组+离散化

    BZOJ_5055_膜法师_树状数组+离散化 Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然 ...

  3. POJ 2299 【树状数组 离散化】

    题目链接:POJ 2299 Ultra-QuickSort Description In this problem, you have to analyze a particular sorting ...

  4. BZOJ-1227 虔诚的墓主人 树状数组+离散化+组合数学

    1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec Memory Limit: 259 MB Submit: 914 Solved: 431 [Submit][Statu ...

  5. POJ 2299 树状数组+离散化求逆序对

    给出一个序列 相邻的两个数可以进行交换 问最少交换多少次可以让他变成递增序列 每个数都是独一无二的 其实就是问冒泡往后 最多多少次 但是按普通冒泡记录次数一定会超时 冒泡记录次数的本质是每个数的逆序数 ...

  6. [HDOJ4325]Flowers(树状数组 离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4325 关于离散化的简介:http://blog.csdn.net/gokou_ruri/article ...

  7. Bzoj 1901: Zju2112 Dynamic Rankings 主席树,可持久,树状数组,离散化

    1901: Zju2112 Dynamic Rankings Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 6321  Solved: 2628[Su ...

  8. CF 61E 树状数组+离散化 求逆序数加强版 三个数逆序

    http://codeforces.com/problemset/problem/61/E 题意是求 i<j<k && a[i]>a[j]>a[k] 的对数 会 ...

  9. Ultra-QuickSort(树状数组+离散化)

    Ultra-QuickSort  POJ 2299 Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 50495   Accep ...

随机推荐

  1. android开发学习——Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/zxing/BarcodeFormat;

    在Android Studio中,sync project没有错,但是run时会报错; http://blog.csdn.net/q568430333/article/details/50969033 ...

  2. 大步小步法(BSGS) 学习笔记

    \(\\\) BSGS 用于求解关于 \(x\) 的方程: \[ a^x\equiv b\pmod p\ ,\ (p,a)=1 \] 一般求解的是模意义下的指数,也就是最小非负整数解. \(\\\) ...

  3. volley的框架安装与使用

    最后一步非常重要   不然会报错: publish = project.has("release")   替换为: publish = project.hasProperty(&q ...

  4. git --版本对比

    比较暂存区域和工作目录  -git diff 分别拷贝暂存区和工作目录的文件到a和b文件夹 ---   //表示旧文件  暂存区的 +++  //表示新文件   工作目录的 F 一页一页往下移 B 一 ...

  5. log级别

    trace<debug<info<warn<error<fatal trace: 是追踪,就是程序推进以下,你就可以写个trace输出,所以trace应该会特别多,不过没 ...

  6. 用npm来部署快速一个httpweb服务器

    https://blog.csdn.net/u012182627/article/details/55060594 http-server的安装######注意事项 安装http-server的时候 ...

  7. 20181019 记录 window.setTimeout('dofunction()',2000); - layui form 表单提交 事件 - F11全屏 事件 window.onresize

    1 延时事件 window.setTimeout('dofunction()',2000); 函数外面要有引号 如果没有引号 就不能延时执行 应该是内容进行eval,所以外层不是传递字符串的话,外层函 ...

  8. CAD交互绘制带颜色宽度的直线(com接口)

    用户可以在控件视区任意位置绘制直线. 主要用到函数说明: _DMxDrawX::DrawLine 绘制一个直线.详细说明如下: 参数 说明 DOUBLE dX1 直线的开始点x坐标 DOUBLE dY ...

  9. caffe实现自己的层

    http://blog.csdn.net/xizero00/article/details/52529341 将这篇博客所讲进行了实现 1.LayerParameter也在caffe.proto文件中 ...

  10. 【转】C# 二进制,十进制,十六进制 互转

    //十进制转二进制 Console.WriteLine(Convert.ToString(69, 2)); //十进制转八进制 Console.WriteLine(Convert.ToString(6 ...