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数学数据处理

    数学和统计方法 sum 对数组中全部或某轴向的元素求和.零长度的数组的sum为0. mean 算术平均数.零长度的数组的mean为NaN. import numpy as np import nump ...

  2. python 列表推导

    废话不多说,直接上代码 #coding=utf-8 def getitem(index, element): return '%d: %s' % (index, element) def getite ...

  3. mybatis源码解析7---MappedStatement初始化过程

    上一篇我们了解到了MappedStatement类就是mapper.xml中的一个sql语句,而Configuration初始化的时候会加载所有的mapper接口类,而本篇再分析下是如何将mapper ...

  4. GUI常用对象介绍3

    %text hf = axes; ht = text(,,'示例'); get(ht); %公式 并且设置位置坐标 (积分符号) text('String','\int_0^x dF(x)','Pos ...

  5. Django框架----用户认证auth模块

    一.auth模块 auth模块:针对auth_user表 创建超级管理用户命令: Python manage.py createsuperuser添加用户名添加密码(至少8位)确认密码添加邮箱(可为空 ...

  6. 用到临时表空间的几种SQL

    用到临时表空间的几种SQL CREATE INDEX SELECT ... ORDER BY SELECT DISTINCT ... SELECT ... GROUP BY SELECT ... UN ...

  7. Git clone 报错 Unable to negotiate with xxx.xxx.xxx.xxx port 12345: no matching cipher found. Their offer: aes128-cbc,3des-cbc,blowfish-cbc

    git clone 报错 Unable to negotiate with xxx.xxx.xxx.xxx. port 12345: no matching cipher found. Their o ...

  8. mariadb的flashback到底怎么样???防误删可以,但算不上真正的闪回--再看mariadb 10.3的System-Versioned Tables

    mariadb 在10.2.4引入闪回特性,支持DML(INSERT, DELETE, UPDATE)操作的闪回,不支持DDL语句,使用闪回,必须设置binlog_row_image=FULL. 其原 ...

  9. 获取RadioButton选中的值

    1.RadioButtonList的RepeatDirection="Horizontal"可以设置按扭选项横对齐: 2.获取选中的RadioButton值; $("#& ...

  10. 快速阅读《QT5.9 c++开发指南》1

    简介:<QT5.9 c++开发指南>的作者是和i三位主要从事地球物理探测仪器设计.数据处理方法研究和软件开发等工作的博士们,这本书以QT Widget为主要内容,比较全面地教授了QT开发桌 ...