题目链接: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

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

最新文章

  1. observejs改善组件编程体验
  2. RabbitMQ - TcpConnection析构引发的一次handshake_timeout
  3. 【C++自绘控件】如何用GDI+来显示图片
  4. (2)RGB-D SLAM系列- 工具篇(依赖库及编译)
  5. linux socket高性能服务器处理框架
  6. vs2010自带的报表
  7. 《Linear Algebra and Its Applications》-chaper6-正交性和最小二乘法-最小二乘问题
  8. Ecshop后台菜单添加
  9. js cookies存取删操作实例
  10. UITabbar的常用属性
  11. 【Objective-C 基础】4.分类和协议
  12. yii2 邮件发送
  13. [nodejs] nodejs开发个人博客(二)入口文件
  14. django 接受 ajax 传来的数组对象
  15. Docker : Tomcat Clustering with Load Balancer (Tomcat and Nginx)
  16. mybatis oracle 插入自增记录 获取主键值 写回map参数
  17. OGeek CTR预估
  18. Everything常见问题及搜索技巧,附Demo
  19. 遇到问题----linux-----linux 打开文件数 too many open files 解决方法
  20. 在Foreda8中整合Apche httpd2.4.6和Tomcat7.0.42(使用tomcat-connectors-1.2.37)

热门文章

  1. HttpServletRequest对象,自己学习的心得。
  2. 支付宝SDK
  3. Node.js——异步上传文件
  4. mongodb用户权限管理(二)
  5. Vue beaforeCreate时获取data中的数据
  6. CE工具里自带的学习工具--第六关
  7. Ubuntu16.04 python3.4.3升级到python3.7.1
  8. 设置npm taobao源和使用cnpm的不同
  9. 【C语言】控制台窗口图形界面编程(五):文本移动
  10. Myeclipse快速排版的快捷键