记录编号 |
362722 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[HZOI 2015]偏序 II |
最终得分 |
100 |
用户昵称 |
_Itachi |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
9.638 s |
提交时间 |
2017-01-08 16:17:47 |
内存使用 |
33.92 MiB |
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=50005,_size_=30;
char is[_size_<<20],*pi=is;inline void Rabit_read(int &x){
while(*pi<'!')pi++;x=0;while(*pi>'!')x=(x<<1)+(x<<3)+(*pi++^'0');}
struct Rabit_q1{int i,a,b,c,d;
bool operator < (const Rabit_q1 &x)const{return a<x.a;}}q[maxn],qa[maxn];
struct Rabit_q2{int b,c,d,l;
bool operator < (const Rabit_q2 &x)const{return b<x.b;}}qi[maxn];
struct Rabit_q3{int c,d;bool l;
bool operator < (const Rabit_q3 &x)const{return c<x.c;}}qc[maxn];
int n,ans=0,c[maxn],low[maxn];
inline void Rabit_in(){
Rabit_read(n);int i;
for(i=1;i<=n;i++)Rabit_read(q[i].a),q[i].i=i;
for(i=1;i<=n;i++)Rabit_read(q[i].b),low[i]=i&(-i);
for(i=1;i<=n;i++)Rabit_read(q[i].c);
for(i=1;i<=n;i++)Rabit_read(q[i].d);
}
inline void Rabit_add(int i,int x){
for(;i<=n;i+=low[i])c[i]+=x;}
inline int Rabit_get(int i){
int res=0;for(;i;i-=low[i])res+=c[i];return res;}
inline void Rabit_run3(int l,int r){
if(l==r)return;
int mid=(l+r)>>1,i,cnt=0;
for(i=l;i<=mid;i++)if(qi[i].l==-1)qc[++cnt]=(Rabit_q3){qi[i].c,qi[i].d,true};
for(i=mid+1;i<=r;i++)if(qi[i].l==1)qc[++cnt]=(Rabit_q3){qi[i].c,qi[i].d,false};
sort(qc+1,qc+cnt+1);
for(i=1;i<=cnt;i++)
if(qc[i].l)Rabit_add(qc[i].d,1);
else ans+=Rabit_get(qc[i].d);
for(i=1;i<=cnt;i++)
if(qc[i].l)Rabit_add(qc[i].d,-1);
Rabit_run3(l,mid),Rabit_run3(mid+1,r);
}
inline void Rabit_run2(int l,int r){
if(l==r)return;
int mid=(l+r)>>1,i;
for(i=l;i<=mid;i++)
if(qa[i].i==-1)qi[i]=(Rabit_q2){qa[i].b,qa[i].c,qa[i].d,-1};
else qi[i]=(Rabit_q2){qa[i].b,qa[i].c,qa[i].d,0};
for(i=mid+1;i<=r;i++)
if(qa[i].i==-1)qi[i]=(Rabit_q2){qa[i].b,qa[i].c,qa[i].d,0};
else qi[i]=(Rabit_q2){qa[i].b,qa[i].c,qa[i].d,1};
sort(qi+l,qi+r+1);
Rabit_run3(l,r);
Rabit_run2(l,mid),Rabit_run2(mid+1,r);
}
inline void Rabit_run1(int l,int r){
if(l==r)return;
int mid=(l+r)>>1,i;
for(i=l;i<=mid;i++)qa[i]=q[i],qa[i].i=-1;
for(i=mid+1;i<=r;i++)qa[i]=q[i],qa[i].i=1;
sort(qa+l,qa+r+1);
Rabit_run2(l,r);
Rabit_run1(l,mid),Rabit_run1(mid+1,r);
}
int main(){
freopen("partial_order_two.in","r",stdin);freopen("partial_order_two.out","w",stdout);
fread(is,sizeof(char),sizeof(is),stdin);
Rabit_in();Rabit_run1(1,n);
printf("%d\n",ans);
}