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 ...
随机推荐
- Centos7 开机显示 ERST: Failed to get Error Log Address Range” 导致无法开机解决方法
开机显示 ERST: Failed to get Error Log Address Range” 导致无法开机,也无法重新安装系统,解决方法:开机进入BIOS , 关闭ACPI选项即可正常开机
- js中xml文件加载
- python面试题解析(前端、框架和其他)
答: HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.它于1990年提出,经过几年的使用与发展,得到不断地完善和扩展.目前在WWW中使用的是HTTP/1. ...
- luogu3370 【模板】字符串哈希
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> ...
- Selenium WebDriver-操作复选框
#encoding=utf-8 import unittest import time import chardet from selenium import webdriver class Visi ...
- PHP模版引擎twig wordpress中调用文章第一张图片
wordpress当文章没有添加Featured media的时候, 就调用文章第一张图片, 调用的wordpress代码函数为: <?php echo catch_that_image(); ...
- 【USACO09FEB】 庙会班车 Fair Shuttle 贪心+线段树
Although Farmer John has no problems walking around the fair to collect prizes or see the shows, his ...
- Python 开启线程的2中方式,线程VS进程(守护线程、互斥锁)
知识点一: 进程:资源单位 线程:才是CPU的执行单位 进程的运行: 开一个进程就意味着开一个内存空间,存数据用,产生的数据往里面丢 线程的运行: 代码的运行过程就相当于运行了一个线程 辅助理解:一座 ...
- POJ 1323 Game Prediction
Game Prediction Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8956 Accepted: 4269 D ...
- 《Spark Python API 官方文档中文版》 之 pyspark.sql (四)
摘要:在Spark开发中,由于需要用Python实现,发现API与Scala的略有不同,而Python API的中文资料相对很少.每次去查英文版API的说明相对比较慢,还是中文版比较容易get到所需, ...