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 ...
随机推荐
- AngularJS开发最常犯的10个错误
简介 AngularJS是目前最为活跃的Javascript框架之一,AngularJS的目标之一是简化开发过程,这使得AngularJS非常善于构建小型app原型,但AngularJS对于全功能的客 ...
- MySQL DECIMAL数据类型
https://blog.csdn.net/zyz511919766/article/details/49335565
- (Android MVVM)使用Data Binding Library(1)
Data Binding Library 用官方提供的Data Binding Library,可以最大限度的减少findViewById(),setOnClickListener()之类的胶水代码, ...
- 源代码管理SVN的使用
SVN 全称是Subversion,集中式版本控制之王者 SVN 版本控制,需要自己搭建一个管理代码的服务器,提供开发人员,上传和下载 1.基本介绍 使用环境 要想利用SVN管理源代码,必须得有2套环 ...
- Vue 路由知识三(过渡动画及路由钩子函数)
路由的过渡动画:让路由有过渡动画,需要在<router-view>标签的外部添加<transition>标签,标签还需要一个name属性. <transition nam ...
- vue-cli中使用rem,vue自适应
2018年04月27日 09:25:34 董小礼 阅读数:4196 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq_39588818/ar ...
- 10 Steps To be a senior programmer
What 软件工程师的职业生涯要历经以下几个阶段:初级.中级,最后才是高级.这篇文章主要是讲如何通过 10 个步骤助你成为一名高级软件工程师. Why 得到更多的报酬!因为你的薪水会随着你水平的提高而 ...
- 01Hibernate
Hibernate Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,它将POJO与数据库表建立映射关系,是一个全自动的orm框架,hibernate可以自 ...
- python闭包浅见
1.个人理解定义:在一个函数A内部定义一个函数B,并在定义的内部函数B内对这个函数A的变量进行引用,那么内部函数B就是闭包. 2.特性:在内部函数内不能对A函数的变量进行更改 (但是可以将其封装到一个 ...
- Spring boot 控制台打印sql
在application.ym中加入: logging: level: com.wechat.cwbt.dao : debug 发现无效 在log4j.properties中加入: log4j.log ...