Jam's problem again CDQ分治

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5618

题意:

\[有n 个元素,第 i 个元素有 a_i、 b_i、 c_i 三个属性,设 f(i) 表示满足 a_i\leq a_j 且 b_i \leq b_j且 c_i \leq c_j的 j 的数量。\\
对于 d \in [0, n],求 f(i) = d 的数量
\]

题解:

和陌上花开这个题是一样的实际上

就不写详细过程了,思想是一样的

详情看这个吧

https://www.cnblogs.com/buerdepepeqi/p/11182571.html

代码:

#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL;
typedef long long ll;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define ls rt<<1
#define rs rt<<1|1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define bug printf("*********\n")
#define FIN freopen("input.txt","r",stdin);
#define FON freopen("output.txt","w+",stdout);
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define debug1(x) cout<<"["<<#x<<" "<<(x)<<"]\n"
#define debug2(x,y) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<"]\n"
#define debug3(x,y,z) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<" "<<#z<<" "<<z<<"]\n" const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 3e5 + 5;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3f;
struct EDGE {
int v, nxt;
} edge[maxn << 1];
int head[maxn], tot;
void add_edge(int u, int v) {
edge[tot].v = v, edge[tot].nxt = head[u], head[u] = tot++;
}
LL bit[maxn];
int lowbit(int x) {
return x & (-x);
}
void add(int pos, int val) {
while(pos < maxn) {
bit[pos] += val, pos += lowbit(pos);
}
}
int sum(int pos) {
int ans = 0;
while(pos) {
ans += bit[pos], pos -= lowbit(pos);
} return ans;
}
struct node {
int x, y, z;
int ans;
int id;
} t[maxn], a[maxn], b[maxn];
bool cmp1(node a, node b) {
if(a.x == b.x && a.y == b.y) return a.z < b.z;
if(a.x == b.x) return a.y < b.y;
return a.x < b.x;
}
bool cmp2(node a, node b) {
if(a.y == b.y && a.z == b.z) return a.x < b.x;
if(a.y == b.y) return a.z < b.z;
return a.y < b.y;
} int ans[maxn];
int num[maxn];
void CDQ(int l, int r) {
if(l == r) {
return;
}
int mid = (l + r) >> 1;
CDQ(l, mid);
CDQ(mid + 1, r);
sort(a + l, a + mid + 1, cmp2);
sort(a + mid + 1, a + r + 1, cmp2);
int j = l;
for(int i = mid + 1; i <= r; ++i) {
while(j <= mid && a[j].y <= a[i].y) {
add(a[j].z, 1), ++j;
}
a[i].ans += sum(a[i].z);
}
for(j--; j >= l; j--) add(a[j].z, -1); } int main() {
#ifndef ONLINE_JUDGE
FIN
#endif
int T;
scanf("%d", &T);
while(T--) {
int n, k;
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].z);
a[i].id = i;
a[i].ans = 0;
}
sort(a + 1, a + n + 1, cmp1);
CDQ(1, n); for(int i = 1; i <= n;) {
int j = i + 1;
int tmp = a[i].ans;
for(; j <= n && a[i].x == a[j].x && a[i].y == a[j].y && a[i].z == a[j].z; j++) tmp = max(tmp, a[j].ans);
for(int k = i; k < j; k++) ans[a[k].id] = tmp;
i = j;
}
for(int i = 1; i <= n; i++) printf("%d\n", ans[i]);
} return 0;
}

最新文章

  1. 透过浏览器看HTTP缓存
  2. 网站整体架构去Windows化
  3. hrbust1279
  4. JQuery插件让图片旋转任意角度且代码极其简单
  5. PostMan入门使用教程
  6. SQL注入式攻击
  7. Linux命令-wc
  8. 功能齐全、效率一流的免费开源数据库导入导出工具(c#开发,支持SQL server、SQLite、ACCESS三种数据库),每月借此处理数据5G以上
  9. C#基础总复习01
  10. C++一些注意点之操作符重载
  11. [转]前端利器:SASS基础与Compass入门
  12. wpf 如何设置滚动条在超出范围的时候才显示?(转)
  13. 基于Spring的异步系统实现方案
  14. 20155304 2016-2017-2 《Java程序设计》第六周学习总结
  15. 老李分享:QTP的录制原理以及实现
  16. 高性能网络通信框架 HP-Socket
  17. 适合精致女孩使用的APP软件 不容错过的精彩人生
  18. 使用composer遇到的坑
  19. [ERROR] - Error reading string. Unexpected token: StartObject. Path &#39;formData&#39;, line 1, position 13.
  20. 写好Java代码的30条经验总结

热门文章

  1. hdu2176 尼姆博弈
  2. mysql中时间字段datetime怎么判断为空和不为空
  3. 常用开源网站:sourceforge,github,foss,launchpad,PortableApps,datamation,opensourcewindows,opensourceMac,apache.org,kde,
  4. 项目中容易出现的BUG预警
  5. 微信授权登录-微信公众号和PC端网站
  6. Open Source Software List: The Ultimate List
  7. DirectEvents用法
  8. logging.basicConfig函数
  9. 2018-11-19-win10-uwp-使用-Matrix3DProjection-进行-3d-投影
  10. Mysql错误:#1054 - Unknown column &#39;id&#39; in &#39;field list&#39; 解决办法