[COGS2479]偏序
[COGS2479]偏序
题目大意:
\(n(n\le50000)\)个四元组,求四维偏序。
思路:
CDQ分治套CDQ分治套树状数组。
细节:
第二层CDQ之前要备份数组\(a\),否则第二层CDQ结束以后\(a\)就不对了。
源代码:
#include<cstdio>
#include<cctype>
#include<algorithm>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
const int N=50001;
int n,ans;
struct Node {
int id,x,y,z,type;
};
Node a[N],tmp[N];
inline bool cmp1(const Node &p1,const Node &p2) {
return p1.x<p2.x;
}
inline bool cmp2(const Node &p1,const Node &p2) {
return p1.y<p2.y;
}
class FenwickTree {
private:
int val[N];
int lowbit(const int &x) const {
return x&-x;
}
public:
void modify(int p,const int &x) {
for(;p<=n;p+=lowbit(p)) val[p]+=x;
}
int query(int p) const {
int ret=0;
for(;p;p-=lowbit(p)) ret+=val[p];
return ret;
}
};
FenwickTree t;
void cdq2(const int &b,const int &e) {
if(b==e) return;
const int mid=(b+e)>>1;
cdq2(b,mid);
cdq2(mid+1,e);
int p=b,q=mid+1;
for(;q<=e;q++) {
if(a[q].type==1) continue;
for(;p<=mid&&a[p].y<a[q].y;p++) {
if(a[p].type==1) t.modify(a[p].z,1);
}
ans+=t.query(a[q].z);
}
while(--p>=b) {
if(a[p].type==1) t.modify(a[p].z,-1);
}
std::inplace_merge(&a[b],&a[mid]+1,&a[e]+1,cmp2);
}
void cdq1(const int &b,const int &e) {
if(b==e) return;
const int mid=(b+e)>>1;
cdq1(b,mid);
cdq1(mid+1,e);
for(register int i=b;i<=mid;i++) a[i].type=1;
for(register int i=mid+1;i<=e;i++) a[i].type=2;
std::inplace_merge(&a[b],&a[mid]+1,&a[e]+1,cmp1);
std::copy(&a[b],&a[e]+1,&tmp[b]);
cdq2(b,e);
std::copy(&tmp[b],&tmp[e]+1,&a[b]);
}
int main() {
freopen("partial_order.in","r",stdin);
freopen("partial_order.out","w",stdout);
n=getint();
for(register int i=1;i<=n;i++) a[i].id=i;
for(register int i=1;i<=n;i++) a[i].x=getint();
for(register int i=1;i<=n;i++) a[i].y=getint();
for(register int i=1;i<=n;i++) a[i].z=getint();
cdq1(1,n);
printf("%d\n",ans);
return 0;
}
[COGS2479]偏序的更多相关文章
- cogs2479 偏序(CDQ套CDQ)
题目链接 思路 四维偏序 \(CDQ\)套\(CDQ\),第一维默认有序.第二维用第一个\(CDQ\)变成有序的.并且对每个点标记上第一维属于左边还是右边.第二个\(CDQ\)处理第三维,注意两个\( ...
- cogs2479 偏序 cdq+树套树
cdq+树状数组套替罪羊树. cdq归并a,树套树解决b,c. 记住平衡树树根不能暴力清零!!! // It is made by XZZ #include<cstdio> #includ ...
- 几道很Interesting的偏序问题
若干道偏序问题(STL,分块) 找了4道题目 BZOJ陌上花开(权限题,提供洛谷链接) Cogs2479偏序 Cogs2580偏序II Cogs2639偏序++ 作为一个正常人,肯定先看三维偏序 做法 ...
- 【COGS2479】 HZOI2016—偏序
http://cogs.pro/cogs/problem/problem.php?pid=2479 (题目链接) 题意 四维偏序. Solution CDQ套CDQ. 细节 第二次分治不能直接按照mi ...
- [COGS2479 && COGS2639]高维偏序(CDQ分治,bitset)
COGS2479:四维偏序. CDQ套CDQ CDQ:对a分治,对b排序,再对a打标记,然后执行CDQ2 CDQ2:对b分治,对c归并排序,对d树状数组. #include<cstdio> ...
- COGS2479(四维偏序)
题意:给定一个有n个元素的序列,元素编号为1~n,每个元素有三个属性a,b,c,求序列中满足i<j且ai<aj且bi<bj且ci<cj的数对(i,j)的个数. 分析:cdq分治 ...
- 【教程】CDQ套CDQ——四维偏序问题
前言 上一篇文章已经介绍了简单的CDQ分治,包括经典的二维偏序和三维偏序问题,还有带修改和查询的二维/三维偏序问题.本文讲介绍多重CDQ分治的嵌套,即多维偏序问题. 四维偏序问题 给定N( ...
- c++模板函数实例化的偏序机制
一:废话 今天在stackoverflow上看到一个关于c++模板specialization的问题: http://stackoverflow.com/questions/18283851/temp ...
- COGS 2479 偏序 题解
[题意] 给定一个有n个元素的序列,元素编号为1~n,每个元素有三个属性a,b,c,求序列中满足i<j且ai<aj且bi<bj且ci<cj的数对(i,j)的个数. 对于30%的 ...
随机推荐
- 防范xss的正确姿势
防范xss的正确姿势 xss攻击是web攻击中非常常见的一种攻击手段.如果你还没有听说过xss攻击,可以先了解xss的相关知识和原理,例如: XSS)" target="_blan ...
- 大规模实时流处理平台架构-zz
随着不同网络质量下接入终端设备种类的增多,服务端转码已经成为视频点播和直播产品中必备的能力之一.直播产品讲究时效性,希望在一定的时间内让所有终端看到不同尺寸甚至是不同质量的视频,因此对转码的实时性要求 ...
- DevExpress 行事历(Scheduler)的常用属性、事件和方法
一.TcxScheduler[TcxScheduler常用属性]1.Storage - 邦定一个Storage为Scheduler显示提供数据 2.DateNavigate.ColCount ...
- linux用户权限 -> 系统用户管理
用户基本概述: Linux用户属于多用户操作系统,在windows中,可以创建多个用户,但不允许同一时间多个用户进行系统登陆,但是Linux可以同时支持多个用户同时登陆操作系统,登陆后互相之间并不影响 ...
- JS可以监控手机的返回键吗?
html5的话 一进页面就pushState,然后监控onpopstate不过好像没有办法知道是前进还是后退我的奇淫巧计是,一个数字变量,pushState一个锚,锚是这个数字,前进一个页面数字+1, ...
- Docker - CentOS安装Docker
如果要在CentOS下安装Docker容器,必须是CentOS 7 (64-bit).CentOS 6.5 (64-bit) 或更高的版本,并要求 CentOS 系统内核高于 3.10. uname ...
- java基础50 配置文件类(Properties)
1. 配置文件类Properties的概念 主要生产配置文件与读取配置文件的信息 2.Properties要注意的细节 1.如果配置文件一旦使用了中文,那么在使用store方法生产的配置文件额时候字符 ...
- WinForm界面开发之 启动界面
我们在开发桌面应用程序的时候,由于程序启动比较慢,往往为了提高用户的体验,增加一个闪屏,也就是SplashScreen,好处有:1.让用户看到加载的过程,提高程序的交互响应:2.可以简短展示或者介绍程 ...
- hdu 4813(2013长春现场赛A题)
把一个字符串分成N个字符串 每个字符串长度为m Sample Input12 5 // n mklmbbileay Sample Outputklmbbileay # include <iost ...
- for循环输出菱形
package com.hanqi; public class lingxing { public static void main(String[] args) { for(int m=1;m< ...