题目链接: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. 移动端如何定义字体font-family

    移动端如何定义字体font-family 中文字体使用系统默认即可,英文用Helvetica /* 移动端定义字体的代码 */ body{font-family:Helvetica;} 参考<移 ...

  2. Vue 学习之el、template、replace和vue的生命周期 参考网址:https://segmentfault.com/a/1190000008010666

  3. javascript中函数的四种调用模式详解

    介绍函数四种调用模式前,我们先来了解一下函数和方法的概念,其实函数和方法本质是一样,就是称呼不一样而已.函数:如果一个函数与任何对象关系,就称该函数为函数.方法:如果一个函数作为一个对象属性存在,我们 ...

  4. 【数据分析 R语言实战】学习笔记 第三章 数据预处理 (下)

    3.3缺失值处理 R中缺失值以NA表示,判断数据是否存在缺失值的函数有两个,最基本的函数是is.na()它可以应用于向量.数据框等多种对象,返回逻辑值. > attach(data) The f ...

  5. 迅为工业级arm开发板i.MX6DL开发板软件硬件全开源

    i.MX6是基于ARM Cortex™-A9架构的高扩展性多核系列应用处理器,促进了如高稳定性工业平板电脑.差异化智能本.前装车载中控系统和超高清电子书阅读器等新一代应用的发展.强劲的3D图形加速引擎 ...

  6. swift potocol 作为参量时函数的派发顺序

    1.检查protocol本体是否声明调用函数: 2.如果没有,检查protocol扩展是否有该函数:如果扩展中也没有,报错: 3.如果本体声明了函数,使用动态派发机制进行派发:扩展中的实现位于最末位.

  7. js 脚本语言

    字符串转换为数字 parseInt(string) .parseFloat().Number() 参考博客:https://zhidao.baidu.com/question/629898532158 ...

  8. node.js querystring类介绍

    querystring 模块提供了一些实用函数,用于解析与格式化 URL 查询字符串. 使用以下方法引入: const querystring = require('querystring'); 此类 ...

  9. CAD参数绘制椭圆弧(网页版)

    在CAD设计时,需要绘制椭圆弧,用户可以设置椭圆弧基本属性. 主要用到函数说明: _DMxDrawX::DrawEllipseArc 绘制椭圆弧.详细说明如下: 参数 说明 DOUBLE dCente ...

  10. C# 如何发送Http请求

    HttpSender是一个用于发送Http消息的轻量C#库,使用非常简单,只需要一两行代码,就能完成Http请求的发送 使用 Nuget,搜索 HttpSender 就能找到这个库 这个库的命名空间是 ...