HDU4325 树状数组+离散化
题目链接: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
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.
Sample outputs are available for more details.
#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 树状数组+离散化的更多相关文章
- hdu4605 树状数组+离散化+dfs
Magic Ball Game Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- BZOJ_5055_膜法师_树状数组+离散化
BZOJ_5055_膜法师_树状数组+离散化 Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然 ...
- POJ 2299 【树状数组 离散化】
题目链接:POJ 2299 Ultra-QuickSort Description In this problem, you have to analyze a particular sorting ...
- BZOJ-1227 虔诚的墓主人 树状数组+离散化+组合数学
1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec Memory Limit: 259 MB Submit: 914 Solved: 431 [Submit][Statu ...
- POJ 2299 树状数组+离散化求逆序对
给出一个序列 相邻的两个数可以进行交换 问最少交换多少次可以让他变成递增序列 每个数都是独一无二的 其实就是问冒泡往后 最多多少次 但是按普通冒泡记录次数一定会超时 冒泡记录次数的本质是每个数的逆序数 ...
- [HDOJ4325]Flowers(树状数组 离散化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4325 关于离散化的简介:http://blog.csdn.net/gokou_ruri/article ...
- Bzoj 1901: Zju2112 Dynamic Rankings 主席树,可持久,树状数组,离散化
1901: Zju2112 Dynamic Rankings Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 6321 Solved: 2628[Su ...
- CF 61E 树状数组+离散化 求逆序数加强版 三个数逆序
http://codeforces.com/problemset/problem/61/E 题意是求 i<j<k && a[i]>a[j]>a[k] 的对数 会 ...
- Ultra-QuickSort(树状数组+离散化)
Ultra-QuickSort POJ 2299 Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 50495 Accep ...
随机推荐
- Oracle 用到的服务
1.Oracle ORCL VSS Writer Service Oracle卷映射拷贝写入服务,VSS(Volume ShadowCopy Service)能够让存储基础设备(比如磁盘,阵列等)创建 ...
- 详解Android Activity启动模式
相关的基本概念: 1.任务栈(Task) 若干个Activity的集合的栈表示一个Task. 栈不仅仅只包含自身程序的Activity,它也可以跨应用包含其他应用的Activity,这样有利于 ...
- nodejs idea 创建项目 (一)
1.在工作空间创建module file->new module next next 项目的目录结构: bin:跟业务无关的公共部分 node_modules :默认的模块 public:公共模 ...
- H.264学习笔记6——指数哥伦布编码
一.哥伦布码 哥伦布码就是将编码对象分能成等间隔的若干区间(Group),每个Group有一个索引值:Group Id. >对于Group Id采用二元码编码: >对于Group内的编码对 ...
- HTML5——动画延迟的另外一种方式
https://www.cnblogs.com/hhhhhh/p/5758167.html
- glm 矩阵乘法得反过来写
- linux查看内核版本和发行版本号
1.查看Linux内核版本号:1.1 uname -r #查看当前linux系统的内核版本号显示举例:2.6.21-1.3194.fc71.2 uname -a #可以查看包括内核版本号.机器硬件信息 ...
- 5-Java-C(单位分数)
题目描述: 形如:1/a 的分数称为单位分数. 可以把1分解为若干个互不相同的单位分数之和. 例如: 1 = 1/2 + 1/3 + 1/9 + 1/18 1 = 1/2 + 1/3 + 1/10 + ...
- CAD参数绘制点(网页版)
点在CAD中的作用除了可以分割对象外,还能测量对象,点不仅表示一个小的实体,而且通过点作为绘图的参考标记. pdmode是一个控制point的形式的系统变量,当pdmode=0时是可见的一个点,当pd ...
- 06C#类
C#类 1.2 类的继承 在1.3节,定义了一个描述个人情况的类Person,如果我们需要定义一个雇员类,当然可以从头开始定义雇员类Employee.但这样不能利用Person类中已定义的函 ...