HDU 5618 Jam's problem again CDQ分治 BC ROUND 70
题意:给你1e5个点(x,y,z),对于每一个点询问有多少个点(x1,y1,z1)满足x1<=x&&y1<=y&&z1<=z
分析:(官方题解奉上)很显然让你找(x,y,z)(x,y,z)都大于别的(x,y,z)(x,y,z),当然厉害的人可以用树套树水一下,但正解写的是CDQ分治,以xx为第一关键字排序,以yy为第二关键字来找,以zz为第三关键字建一个树状数组找就好了,当然等于的情况可以实现前做一下。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
using namespace std;
typedef long long LL;
const int maxn=1e5+;
struct BIT
{
int c[maxn];
void init()
{
memset(c,,sizeof(c));
}
int lowbit(int x)
{
return x&(-x);
}
void add(int x,int t)
{
while(x<=1e5)
{
c[x]+=t;
x+=lowbit(x);
}
}
int sum(int x)
{
int ans=;
while(x>)
{
ans+=c[x];
x-=lowbit(x);
}
return ans;
}
} bit;
struct Node
{
int x,y,z,id;
} o[maxn],tem[maxn];
bool cmp(Node a,Node b)
{
if(a.x!=b.x)
return a.x<b.x;
if(a.y!=b.y)
return a.y<b.y;
return a.z<b.z;
}
bool cmp1(Node a,Node b)
{
return a.y<b.y;
}
int res[maxn];
void solve(int l,int r)
{
if(l==r)return;
int m=(l+r)>>;
for(int i=l; i<=r; ++i)
tem[i]=o[i];
sort(tem+l,tem+m+,cmp1);
sort(tem+m+,tem+r+,cmp1);
int cnt=l;
for(int i=m+; i<=r; ++i)
{
while(cnt<=m&&tem[cnt].y<=tem[i].y)bit.add(tem[cnt].z,),cnt++;
res[tem[i].id]+=bit.sum(tem[i].z);
}
for(int i=l; i<cnt; ++i)
bit.add(tem[i].z,-);
solve(l,m);
solve(m+,r);
}
int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
bit.init();
for(int i=; i<=n; ++i)
scanf("%d%d%d",&o[i].x,&o[i].y,&o[i].z),o[i].id=i;
sort(o+,o++n,cmp);
memset(res,,sizeof(res));
solve(,n);
for(int i=n-; i>; --i)
if(o[i].x==o[i+].x&&o[i].y==o[i+].y&&o[i].z==o[i+].z)
res[o[i].id]=res[o[i+].id];
for(int i=; i<=n; ++i)
printf("%d\n",res[i]);
}
return ;
}
HDU 5618 Jam's problem again CDQ分治 BC ROUND 70的更多相关文章
- HDU 5618 Jam's problem again (cdq分治+BIT 或 树状数组套Treap)
题意:给n个点,求每一个点的满足 x y z 都小于等于它的其他点的个数. 析:三维的,第一维直接排序就好按下标来,第二维按值来,第三维用数状数组维即可. 代码如下: cdq 分治: #pragma ...
- 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; ...
- HDU5618 Jam's problem again CDQ分治
Jam's problem again CDQ分治 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5618 题意: \[ 有n 个元素,第 i 个元素有 ...
- HDU 5618 Jam's problem again(三维偏序,CDQ分治,树状数组,线段树)
Jam's problem again Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- HDU 5618 Jam's problem again
题意: 三维坐标,对于1个点,找出有多少个点,3个坐标都比该点小! Sample Input 1 4 10 4 7 10 6 6 8 2 5 7 3 10 Sample Output 1 1 0 ...
- hdu_5618_Jam's problem again(cdq分治+lowbit)
题目链接:hdu_5618_Jam's problem again 题意: 给你n个点,每个点有一个坐标(x,y,z),找出有ans个点,3个坐标都比该点小,这个点的level就为ans,然后让你输出 ...
- HDU - 5730 :Shell Necklace(CDQ分治+FFT)
Perhaps the sea‘s definition of a shell is the pearl. However, in my view, a shell necklace with n b ...
- HDU - 5324:Boring Class (CDQ分治&树状数组&最小字典序)
题意:给定N个组合,每个组合有a和b,现在求最长序列,满足a不升,b不降. 思路:三位偏序,CDQ分治. 但是没想到怎么输出最小字典序,我好菜啊. 最小字典序: 我们倒序CDQ分治,ans[i]表 ...
- SPOJ LIS2 - Another Longest Increasing Subsequence Problem(CDQ分治优化DP)
题目链接 LIS2 经典的三维偏序问题. 考虑$cdq$分治. 不过这题的顺序应该是 $cdq(l, mid)$ $solve(l, r)$ $cdq(mid+1, r)$ 因为有个$DP$. #i ...
随机推荐
- poj 2186 Popular Cows (强连通分量+缩点)
http://poj.org/problem?id=2186 Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissi ...
- vbe6ext.olb不能被加载 宏内存溢出
今天想玩一下PowerPoint的宏,却发现玩不起来!!! 另外,每次打开ppt时都会提示vbe6ext.olb不能加载. 网上说重新下载个vbe6ext.olb然后复制到相应的路径.我也试着下载,然 ...
- c#用反射原理递归遍历复杂实体对象
之前在网上看到的都是遍历那种比较简单的实体对象,但是如果有实体嵌套,甚至是包含有List<XXInfo>这种属性的时候就没有办法处理了.通过递归遍历的方式可以完成对复杂实体对象的所有属性的 ...
- hadoop 任务执行优化
任务执行优化 1. 推测式执行: 如果jobtracker 发现有拖后的任务,会再启动一个相同的备份任务,然后哪个先执行完就会去kill掉另一个,因此会在监控页面上经常能看到正常执行完的作业会有被ki ...
- Extjs4.2布局——layout: accordion(Ext.layout.container.Accordion)
API这样介绍这种布局: 示例:(来自API)注:打开默认展开第一个面板. Ext.create('Ext.panel.Panel', { title: 'Accordion Layout', wid ...
- SQL SERVER数据导入
我的博客已好久没有文字方面的记载了,好歹昨天已经结束软件设计师的考试了,今天怎么说也需要锻炼自己的写作能力.不然真怕自己又像上一年一样,一停就一年多了. 想好好学习数据库(SQL SERVER)方面的 ...
- BZOJ 3288 Mato矩阵 解题报告
这个题好神呀..Orz taorunz 有一个结论,这个结论感觉很优美: $$ans = \prod_{i=1}^{n}\varphi(i)$$ 至于为什么呢,大概是这样子的: 对于每个数字 $x$, ...
- FaceNet--Google的人脸识别(转)
引入 随着深度学习的出现,CV领域突破很多,甚至掀起了一股CV界的创业浪潮,当次风口浪尖之时,Google岂能缺席.特贡献出FaceNet再次刷新LFW上人脸验证的效果记录. 本文是阅读FaceNet ...
- Android支付接入(五):机锋网
原地址:http://blog.csdn.net/simdanfeg/article/details/9012083 前边已经陆续跟大家走了一遍运营商和支付宝付费接入,今天跟大家一起看看机锋网的支付接 ...
- Side-by-side assembly
Side-by-side technology is a standard for executable files in Windows 98 Second Edition, Windows 200 ...