hdu 1541 (cdq分治)

For example, look at the map shown on the figure above. Level of the star number 5 is equal to 3 (it's formed by three stars with a numbers 1, 2 and 4). And the levels of the stars numbered by 2 and 4 are 1. At this map there are only one star of the level 0, two stars of the level 1, one star of the level 2, and one star of the level 3.
You are to write a program that will count the amounts of the stars of each level on a given map.
1 1
5 1
7 1
3 3
5 5
2
1
1
0
思路:
排序以后把在第二维上分治
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int N = 1e5+7;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
typedef long long ll;
const ll mod = 1e9+7;
struct node{
int x,y,id;
friend bool operator < (node a,node b){
if(a.x!=b.x) return a.x<b.x;
return a.y<b.y;
}
}p[N],a[N];
int f[N];
int ans[N];
void cdq(int l,int r){
if(l==r) return ;
int mid=(l+r)>>1;
cdq(l,mid); cdq(mid+1,r);
int i=l,j=mid+1,cnt=l;
while(i<=mid&&j<=r){
if(p[i].y<=p[j].y){
a[cnt++]=p[i++];
}else{
f[p[j].id]+=(i-l);
a[cnt++]=p[j++];
}
}
while(i<=mid) a[cnt++]=p[i++];
while(j<=r){
f[p[j].id]+=(i-l);
a[cnt++]=p[j++];
}
for(int k=l;k<=r;k++) p[k]=a[k];
}
int main(){
// ios::sync_with_stdio(false);
// cin.tie(0); cout.tie(0);
int n;
while(~scanf("%d",&n)){
memset(f,0,sizeof(f));
memset(ans,0,sizeof(ans));
for(int i=1;i<=n;i++){
int x,y; scanf("%d%d",&x,&y);
p[i]=node{x,y,i};
}
sort(p+1,p+n+1);
cdq(1,n);
for(int i=1;i<=n;i++)
ans[f[i]]++;
for(int i=0;i<n;i++)
printf("%d\n",ans[i]);
}
return 0;
}
hdu 1541 (cdq分治)的更多相关文章
- HDU 3507 Print Article(CDQ分治+分治DP)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3507 [题目大意] 将长度为n的数列分段,最小化每段和的平方和. [题解] 根据题目很容易得到dp ...
- HDU 5730 Shell Necklace(CDQ分治+FFT)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5730 [题目大意] 给出一个数组w,表示不同长度的字段的权值,比如w[3]=5表示如果字段长度为3 ...
- hdu 3842 Machine Works(cdq分治维护凸壳)
题目链接:hdu 3842 Machine Works 详细题解: HDU 3842 Machine Works cdq分治 斜率优化 细节比较多,好好体会一下. 在维护斜率的时候要考虑x1与x2是否 ...
- hdu 5830 FFT + cdq分治
Shell Necklace Time Limit: 16000/8000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- cdq分治(hdu 5618 Jam's problem again[陌上花开]、CQOI 2011 动态逆序对、hdu 4742 Pinball Game、hdu 4456 Crowd、[HEOI2016/TJOI2016]序列、[NOI2007]货币兑换 )
hdu 5618 Jam's problem again #include <bits/stdc++.h> #define MAXN 100010 using namespace std; ...
- 【 HDU - 4456 】Crowd (二维树状数组、cdq分治)
BUPT2017 wintertraining(15) #5A HDU 4456 题意 给你一个n行n列的格子,一开始每个格子值都是0.有M个操作,p=1为第一种操作,给格子(x,y)增加z.p=2为 ...
- hdu 4366 Successor - CDQ分治 - 线段树 - 树分块
Sean owns a company and he is the BOSS.The other Staff has one Superior.every staff has a loyalty an ...
- HDU 5324 Boring Class【cdq分治】
这就是一个三维排序的问题,一维递减,两维递增,这样的问题用裸的CDQ分治恰好能够解决. 如同HDU 4742(三维排序,一个三维都是递增的) 由于最小字典序比較麻烦,所以要从后面往前面做分治.每一个点 ...
- Boring Class HDU - 5324 (CDQ分治)
Mr. Zstu and Mr. Hdu are taking a boring class , Mr. Zstu comes up with a problem to kill time, Mr. ...
- HDU 5730 Shell Necklace cdq分治+FFT
题意:一段长为 i 的项链有 a[i] 种装饰方式,问长度为n的相连共有多少种装饰方式 分析:采用dp做法,dp[i]=∑dp[j]*a[i-j]+a[i],(1<=j<=i-1) 然后对 ...
随机推荐
- Lesson_strange_words3
can 电话耳机,(头戴式听筒) determine 决定 perform 执行 regular 常规的 duty 责任 compatible 兼容 preset 预置,预设 in either or ...
- node.js常用内置模块一
在使用内模块的时候需要先将所需的内置模块进行引入. OS模块 在nodejs中OS模块提供了与操作系统相关的属性和方法 // 导入OS内置模块,必须先进行导入,否则无法使用 const os = re ...
- 对于k8s微服务的性能测试监控平台搭建
之前有写过对于传统项目的性能测试监控,但是对于目前市场占比已经很低,大部分项目使用k8s,今天讲一下对于k8s如何去监控. 对于k8s的监控我们所有的操作都要在master下进行. 一.部署grafa ...
- 紧急预警】关于爆发的 incaseformat 病毒事件亲身体验
相关报道 incaseformat病毒 360安全卫士服务号 https://mp.weixin.qq.com/s/KM6esd1eUlBt-YHtEwnfuw 广东省网络安全应急响应平台 https ...
- 【MyBatis】自定义 MyBatis
自定义 MyBatis 文章源码 执行查询信息的分析 我们知道,MyBatis 在使用代理 DAO 的方式实现增删改查时只做两件事: 创建代理对象 在代理对象中调用 selectList() 配置信息 ...
- Mac安装homebrew,postman,charles
Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装.卸载.更新.查看.搜索等很多实用的功能.简单的一条指令,就可以实现包管理,而不用你关心各种依赖和文件路径的情况,十分方便快捷. 1. ...
- 【译】Async/Await(二)——Futures
原文标题:Async/Await 原文链接:https://os.phil-opp.com/async-await/#multitasking 公众号: Rust 碎碎念 翻译 by: Praying ...
- 【SpringBoot】前缀树 Trie 过滤敏感词
1.过滤敏感词 Spring Boot实践,开发社区核心功能 完成过滤敏感词 Trie 名称:Trie也叫做字典树.前缀树(Prefix Tree).单词查找树 特点:查找效率高,消耗内存大 应用:字 ...
- awk -v参数
-v var=val --assign var=val Assign the value val to the variable var, before execution of the progra ...
- 电子邮箱、邮件地址、网站地址正则表达式!几个有用的RE、regex、regexp!
几个常用的正则表达式! r"\w[-\w\.]*@\w[-\w]*(\.\w[-\w]*)+" 这个是电子邮件地址的. r"<TAG\b[^>]*<(. ...