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 ...
随机推荐
- Java注解处理器(转)
Java中的注解(Annotation)是一个很神奇的东西,特别现在有很多Android库都是使用注解的方式来实现的.一直想详细了解一下其中的原理.很有幸阅读到一篇详细解释编写注解处理器的文章.本文的 ...
- Duilib介绍以及各个类的简介
转自http://note.sdo.com/u/icez/n/mvO-X~jyVnpFnM01A0000m DirectUI意为直接在父窗口上绘图(Paint on parent dc directl ...
- 1195: [HNOI2006]最短母串 - BZOJ
Description 给定n个字符串(S1,S2,„,Sn),要求找到一个最短的字符串T,使得这n个字符串(S1,S2,„,Sn)都是T的子串.Input 第一行是一个正整数n(n<=12), ...
- 有关js的变量、作用域和内存问题
来自<javascript高级程序设计 第三版:作者Nicholas C. Zakas>的学习笔记(四) js共有5种基本数据类型:Undefined.NULL.Boolean.Numbe ...
- [转载]JS、C#编码解码
escape不编码字符有69个:*,+,-,.,/,@,_,0-9,a-z,A-Z encodeURI不编码字符有82个:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@ ...
- 为什么样本方差(sample variance)的分母是 n-1?
为什么样本方差(sample variance)的分母是 n-1? (補充一句哦,題主問的方差 estimator 通常用 moments 方法估計.如果用的是 ML 方法,請不要多想不是你們想的那樣 ...
- Scala学习——基础篇
[<快学Scala>笔记] 一.基础 1.变量val 标志符: 声明常量: 如,val answer = 1var 标志符:声明变量: 类型推断:变量的类型由scala根据初始化变量的表达 ...
- POJ1002487-3279(map)
http://poj.org/problem?id=1002 题意:是说很多公司用了容易记住的电话号码,例如有英文字母的或者是用了很多连字符或没有连字符的.每个电话号码都有标准模式,而为了统计有没有重 ...
- hdu 3859 Inverting Cups
题意是给出A个杯子,一开始都朝上,每次可以翻B个杯子,问最少需要翻转多少次可以让所有杯子都朝下. 分类讨论: 首先对于A%B==0一类情况,直接输出. 对于A>=3B,让A减到[2B,3B)区间 ...
- [topcoder]BadNeighbors
http://community.topcoder.com/stat?c=problem_statement&pm=2402&rd=5009 动态规划题.对于圈状的题目有了点感觉. 题 ...