HDU5618 Jam's problem again
CDQ分治模板题
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<cstring>
using namespace std;
inline int read()
{
int x = 0, flag = 1;
char c;
while(! isgraph(c = getchar()))
if(c == '-')
flag *= - 1;
while(isgraph(c))
x = x * 10 + c - '0', c = getchar();
return x * flag;
}
void println(int x)
{
if(x < 0)
putchar('-');
if(x == 0)
putchar('0');
int ans[10 + (1 << 4)], top = 0;
while(x)
ans[top ++] = x % 10, x /= 10;
for(; top; top --)
putchar(ans[top - 1] + '0');
putchar('\n');
}
const int MAXN = (int)1e5 + (1 << 5);
struct node
{
int x, y, z, ID;
node(int x = 0, int y = 0, int z = 0, int ID = 0): x(x), y(y), z(z), ID(ID){}
}a[MAXN], b[MAXN];
int operator <(node x, node y)
{
if(x.x != y.x)
return x.x < y.x;
if(x.y != y.y)
return x.y < y.y;
return x.z <= y.z;
}
int ans[MAXN];
int cmp(node x, node y)
{
if(x.y != y.y)
return x.y < y.y;
return x.ID < y.ID;
}
int tree[MAXN];
int MAXZ;
void modify(int u, int delta)
{
while(u <= MAXZ)
tree[u] += delta, u += (u & (-u));
}
int query(int u)
{
int ret = 0;
while(u)
ret += tree[u], u -= (u & (- u));
return ret;
}
void CDQ(int L, int R)
{
if(L == R)
return;
int mid = (L + R) >> 1;
int top = 0;
for(int i = L; i <= mid; i ++)
b[top ++] = node(0, a[i].y, a[i].z, 0);
for(int i = mid + 1; i <= R; i ++)
b[top ++] = node(0, a[i].y, a[i].z, a[i].ID);
sort(b, b + top, cmp);
for(int i = 0; i < top; i ++)
{
if(b[i].ID == 0)
modify(b[i].z, 1);
else
ans[b[i].ID] += query(b[i].z);
}
for(int i = 0; i < top; i ++)
if(b[i].ID == 0)
modify(b[i].z, - 1);
CDQ(L, mid);
CDQ(mid + 1, R);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("HDU5618.in", "r", stdin);
freopen("HDU5618.out", "w", stdout);
#endif
int T = read();
while(T --)
{
int n = read();
for(int i = 1; i <= n; i ++)
{
int x = read(), y = read(), z = read();
a[i] = node(x, y, z, i);
MAXZ = max(MAXZ, a[i].z);
}
sort(a + 1, a + n + 1);
memset(ans, 0, sizeof(ans));
memset(tree, 0, sizeof(tree));
int cnt = 0;
for(int i = n; i; i --)
{
if((a[i].x == a[i + 1].x)
&& (a[i].y == a[i + 1].y)
&& (a[i].z == a[i + 1].z))
cnt ++;
else
cnt = 0;
ans[a[i].ID] += cnt;
}
CDQ(1, n);
for(int i = 1; i <= n; i ++)
println(ans[i]);
}
}
HDU5618 Jam's problem again的更多相关文章
- HDU5618 Jam's problem again CDQ分治
Jam's problem again CDQ分治 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5618 题意: \[ 有n 个元素,第 i 个元素有 ...
- 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 5618 Jam's problem again(三维偏序,CDQ分治,树状数组,线段树)
Jam's problem again Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- Google Code Jam 资格赛: Problem A. Magic Trick
Note: To advance to the next rounds, you will need to score 25 points. Solving just this problem wil ...
- HDU 5618 Jam's problem again CDQ分治 BC ROUND 70
题意:给你1e5个点(x,y,z),对于每一个点询问有多少个点(x1,y1,z1)满足x1<=x&&y1<=y&&z1<=z 分析:(官方题解奉上)很 ...
- 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分治+BIT 或 树状数组套Treap)
题意:给n个点,求每一个点的满足 x y z 都小于等于它的其他点的个数. 析:三维的,第一维直接排序就好按下标来,第二维按值来,第三维用数状数组维即可. 代码如下: cdq 分治: #pragma ...
- HDU 5618:Jam's problem again(CDQ分治+树状数组处理三维偏序)
http://acm.hdu.edu.cn/showproblem.php?pid=5618 题意:…… 思路:和NEUOJ那题一样的.重新写了遍理解了一下,算作处理三维偏序的模板了. #includ ...
- Google Code Jam 2010 Round 1C Problem B. Load Testing
https://code.google.com/codejam/contest/619102/dashboard#s=p1&a=1 Problem Now that you have won ...
随机推荐
- AOP面向切面编程笔记
1.AOP概念:Aspect Oriented Programming 面向切面编程 2.作用:本质上来说是一种简化代码的方式 继承机制 封装方法 动态代理 …… 3.情景举例 ①数学计算器接口[Ma ...
- centos7 killall 命令
centos7精简安装后,使用中发现没有killall命令. 安装这个包即可: yum install psmisc
- UVA - 11572 Unique Snowflakes 滑动扫描
题目:点击打开题目链接 思路:从左往右扫描,定义扫描左端点L,右端点R,保证每次往几何中添加的都是符合要求的连续的数列中的元素,L和R从0扫到n,复杂度为O(n),使用set维护子数列,set查找删除 ...
- zoj 4049
Halting Problem Time Limit: 1 Second Memory Limit: 65536 KB In computability theory, the haltin ...
- Docker初认识(一)
1)简介 1.1)什么是Docker Docker 最初是 dotCloud 公司创始人 Solomon Hykes 在法国期间发起的一个公司内部项目,它是基于 dotCloud 公司多年云服务技术的 ...
- cygwin的使用
参考资料: 对话 UNIX: 在 Windows 上使用 Cygwin Cygwin使用指南
- TSS (任务状态段)的作用及结构
1.什么是TSS TSS全称Task State Segment ,是操作系统在进行进程切换时保存进程现场信息的段 2.TSS什么时候用,有什么用 TSS在任务(进程)切换时起着重要的作用,通过它保存 ...
- POJ 3469 最小割 Dual Core CPU
题意: 一个双核CPU上运行N个模块,每个模块在两个核上运行的费用分别为Ai和Bi. 同时,有M对模块需要进行数据交换,如果这两个模块不在同一个核上运行需要额外花费. 求运行N个模块的最小费用. 分析 ...
- python-高级编程-02
[yield 详解 协同程序 生成器表达式] 1> yield def res (): for i in range(10): x = yield i r = res() print r.nex ...
- logging——日志
导读 很多程序都有记录日志的需求,并且日志中包含的信息即有正常的程序访问日志,还可能有错误.警告等信息输出,python的logging模块提供了标准的日志接口,你可以通过它存储各种格式的日志,log ...