[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%的 ...
随机推荐
- python模块-platform
#author:Blood_Zero #coding:utf- import platform print dir(platform) #获取platform函数功能 platform.archite ...
- 【NOI题解】【bzoj题解】NOI2008 bzoj1063 道路设计
@ACMLCZH学长出的毒瘤题T3.再也不是“善良”的出题人了. 题意:bzoj. 题解: 经典的树形DP题目,屡见不鲜了,然而我还是没有写出来. 这一类的题目有很多,例如这里的C题. 主要套路是把对 ...
- ubuntu 18.04 安装 flash
下载源码包, 解压 sudo cp Downloads/flash_player_npapi_linux.x86_64/libflashplayer.so /usr/lib/mozilla/plugi ...
- Once you eliminate all the other factors,the only thing remaining must be the truth.
Once you eliminate all the other factors,the only thing remaining must be the truth. 一旦你排除了杂因,剩下的一定是 ...
- 【CTF WEB】文件包含
文件包含 题目要求: 请找到题目中FLAG 漏洞源码 <meta charset='utf-8'> <center><h1>文件阅读器</h1>< ...
- 使用RegSetValueEx修改注册表时遇到的问题(转)
原文转自 http://blog.csdn.net/tracyzhongcf/article/details/4076870 1.今天在使用RegSetValueEx时发现一个问题: RegSetVa ...
- Linux机器如何在公司内网配置代理
一.通过上网认证 必须在图形界面下使用浏览器(如Firefox)完成上网认证过程. 请先确保本机已经可以正常访问公司内部网络. Firefox上配置代理: 1)打开Firefox首选项,[高级]-[网 ...
- NuGet服务器搭建教程
本文主要来自网络,进行整理而成,相关文章如下: http://diaosbook.com/Post/2012/12/15/setup-private-nuget-server https://www. ...
- Nagios Openstack Plugin
Some simple example for checking Openstack services check nova service list #!/bin/sh export OS_PROJ ...
- Git如何设置多个用户
前言 由于我们在使用GitHub时,通常不希望带有公司信息,所以需要独立的Git账户来提交练习代码,本文记录一下如何配置多个Git账户并创建公钥 正文 1.首先进入~/.ssh文件夹 2.然后创建一个 ...