http://acm.hdu.edu.cn/showproblem.php?pid=4325

题意:
给出n个区间和m个询问,每个询问为一个x,问有多少个区间包含了x。

思路:

因为数据量比较多,所以需要离散化。区间的离散化需要注意一下,如果端点不连续的话,需要额外插点。

区间情况就用树状数组来维护。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = *1e5+; int n, m, tot;
int a[maxn+],c[maxn]; struct node
{
int l,r;
}query[maxn/]; int lowbit(int x)
{
return x&-x;
} int sum(int x)
{
int ret = ;
while(x>)
{
ret+=c[x];
x-=lowbit(x);
}
return ret;
} void add(int x, int d)
{
while(x<=maxn)
{
c[x]+=d;
x+=lowbit(x);
}
} int main()
{
//freopen("in.txt","r",stdin);
int T;
int kase = ;
scanf("%d",&T);
while(T--)
{
tot = ;
memset(c,,sizeof(c));
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%d%d",&query[i].l,&query[i].r);
a[tot++] = query[i].l;
a[tot++] = query[i].r;
}
a[tot++] = ;
sort(a,a+tot);
int tmp = tot;
for(int i=;i<tmp;i++)
if(a[i]-a[i-]>) a[tot++] = a[i]-;
sort(a,a+tot);
int num = unique(a,a+tot)-a;
for(int i=;i<=n;i++)
{
int l = lower_bound(a,a+num,query[i].l)-a;
int r = lower_bound(a,a+num,query[i].r)-a;
add(l,);
add(r+,-);
}
printf("Case #%d:\n",++kase);
while(m--)
{
int x; scanf("%d",&x);
x = lower_bound(a,a+num,x)-a;
printf("%d\n",sum(x));
}
}
return ;
}

HDU 4325 Flowers(树状数组+离散化)的更多相关文章

  1. HDU 4325 Flowers 树状数组+离散化

    Flowers Problem Description As is known to all, the blooming time and duration varies between differ ...

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

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

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

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

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

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

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

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

  6. HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences             ...

  7. HDU 5256 - 序列变换 ,树状数组+离散化 ,二分法

    Problem Description 我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增.其中无论是修改前还是修改后,每个元素都必须是整数.请输出最少需要修改多少 ...

  8. 利用id来进行树状数组,而不是离散化以后的val HDU 4417 离线+树状数组

    题目大意:给你一个长度为n的数组,问[L,R]之间<=val的个数 思路:就像标题说的那样就行了.树状数组不一定是离散化以后的区间,而可以是id //看看会不会爆int!数组会不会少了一维! / ...

  9. HDU 5792 World is Exploding(树状数组+离散化)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=5792 题意: 思路: lmin[i]:表示左边比第i个数小的个数. lmax[i]:表示左边比第i个 ...

随机推荐

  1. numpy高级索引

    布尔值索引 name_arr = np.array(["bob","joe","will","bob","jo ...

  2. nodejs之pm2自动重启服务

    pm2 start xxx #启动服务器 pm2 list #查看运行状态 pm2 logs #查看日志 pm2 restart xxx #重启应用 pm2 stop xxx #停止应用 监听修改,并 ...

  3. 如何避免Scrum敏捷开发团队反思会形式化,海星法介绍

    如何避免Scrum敏捷开发团队反思会形式化? 迭代压力很大,根本没时间,而且,反思会上大家都在互相推脱责任,会议成了“批斗大会”,所以团队的人都觉得这个会很鸡肋. 很多团队在开反思会时是这么干的:产品 ...

  4. GUI常用对话框3

    %进度条 %waitbar h=waitbar(,'实例'); get(h); %获得进度条的子对象 get(get(h,'Children')) ha=get(h,'Children'); %获得坐 ...

  5. asp.net热门框架

    http://developer.51cto.com/art/201501/464292.htm

  6. flask框架----基于flask的扩展实现的简单的页面登录

    废话不多说,直接上代码 from flask import Flask,render_template,request,redirect,session app = Flask(__name__,te ...

  7. easyui dialog 表单提交,弹框初始化赋值,dialog实现

    //定义弹框html<div id="delete" class="easyui-dialog" title="Delete" dat ...

  8. 数据库-MySQL入门

    什么是数据库? 一定方式储存在一起.能与多个用户共享.具有尽可能小的冗余度.与应用程序彼此独立的数据集合 数据库管理系统(简称DBMS):是为管理数据库而设计的电脑软件系统,一般具有存储.截取.安全保 ...

  9. RTP协议全解析(H264码流和PS流)(转)

    源: RTP协议全解析(H264码流和PS流)

  10. intelliJ IDEA之使用svn或git管理代码

    intelliJ IDEA之使用svn管理代码 1.VCS—>import into Version Control—>Share Project(Subversion) 2.点击+    ...