【题意概述】

给出三个n的排列,求有多少个数对在三个排列中顺序相同

【题解】

考虑用补集转化的方法,答案为总对数-不满足的对数

一对数不满足条件,当且仅当这对数在两个排列中顺序相同,在另一个排列中的顺序不同。

统计两两之间不满足偏序条件的数对的个数,那么每对数都被统计了两次

#include<cstdio>
#include<algorithm>
#include<cstring>
#define LL long long
using namespace std;
const int maxn=200010;
int n,a[4][maxn],b[maxn],t[maxn];
LL ans,tmp;
void read(int &k){
k=0; int f=1; char c=getchar();
while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
k*=f;
}
void add(int x){for(;x<=n;x+=(x&-x)) t[x]++;}
int query(int x){int ret=0; for(;x>0;x-=(x&-x)) ret+=t[x]; return ret;}
int main(){
read(n);
for (int j=1;j<=3;j++)
for (int i=1;i<=n;i++) read(a[j][i]);
for (int i=1;i<3;i++)
for (int j=i+1;j<=3;j++){
memset(t,0,sizeof(t)); tmp=0;
for (int k=1;k<=n;k++) b[a[i][k]]=k;
for (int k=1;k<=n;k++) a[j][k]=b[a[j][k]];
for (int k=1;k<=n;k++) tmp+=query(a[j][k]),add(a[j][k]);
ans+=1LL*n*(n-1)/2-tmp;
}
return printf("%lld\n",1LL*n*(n-1)/2-ans/2),0;
}

  

BZOJ 4430 Guessing Camels赌骆驼的更多相关文章

  1. bzoj 4430: [Nwerc2015]Guessing Camels赌骆驼

    4430: [Nwerc2015]Guessing Camels赌骆 Description Jaap, Jan, and Thijs are on a trip to the desert afte ...

  2. 【BZOJ】4430: [Nwerc2015]Guessing Camels赌骆驼

    [题意]给定三个长度为n的排列,求在三个排列中顺序相同的数对个数. [算法]逆序对 [题解]很容易联想到NOIP火柴排队,涉及顺序问题显然和逆序对息息相关. 一个数对如果在三个排列中顺序不同,一定是1 ...

  3. bzoj4430 [Nwerc2015]Guessing Camels赌骆驼

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4430 [题解] 把每只骆驼在第一个人.第二个人.第三个人的位置找出来,然后做三维偏序即可. ...

  4. BZOJ 4430 Guessing Camels

    Description Jaap, Jan, and Thijs are on a trip to the desert after having attended the ACM ICPC Worl ...

  5. 【容斥原理】【推导】【树状数组】Gym - 101485G - Guessing Camels

    题意:给你三个1~n的排列a,b,c,问你在 (i,j)(1<=i<=n,1<=j<=n,i≠j),有多少个有序实数对(i,j)满足在三个排列中,i都在j的前面. 暴力求的话是 ...

  6. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  7. 越狱Season 1-Episode 13: End of the Tunnel

    Season 1, Episode 13: End of the Tunnel -Fernando: The name is John Abruzzi. 名字是John Abruzzi A b r u ...

  8. Gym101485: NWERC 2015(队内第6次训练)

    A .Assigning Workstations 题意:给定N个人的工作时间和工作时长,我们可以假设有无数台工作机器,如果一台机器超过M时间未使用就会关闭,那么我们怎么安排机器的使用,使得需要开启机 ...

  9. 2015-2016 Northwestern European Regional Contest (NWERC 2015)

    训练时间:2019-04-05 一场读错三个题,队友恨不得手刃了我这个坑B. A I J 简单,不写了. C - Cleaning Pipes (Gym - 101485C) 对于有公共点的管道建边, ...

随机推荐

  1. excel 字符串拼接 添加 超链接

    =HYPERLINK("http://"&C2,"http://"&C2)

  2. web中servletcontext和applicationContext

    参看:http://www.cnblogs.com/isisbenben/p/5594323.html servletContext和ApplicationContext有什么区别 servletCo ...

  3. linux内核中的宏ffs(x)

    linux内核中ffs(x)宏是平台相关的宏,在arm平台,该宏定义在 arch/arm/include/asm/bitops.h #define ffs(x) ({ unsigned long __ ...

  4. How to: Specify the Web Server for Web Projects in Visual Studio

    https://msdn.microsoft.com/en-us/library/ms178108(v=vs.120).aspx When you run a Web project in Visua ...

  5. .NET平台下Redis使用(二)【StackExchange.Redis学习】

    Program.cs内容: using Newtonsoft.Json; using StackExchange.Redis; using System; using System.Data; usi ...

  6. 如何看待B站疑似源码泄漏的问题?

    今天突然看到关于B站源码泄漏事.网曝B站整个网站后台工程源码遭泄露,开源项目平台Github上疑似出现了Bilibili网站后台工程,内含部分用户名密码.目前官方还没对此事作出任何回应,所以还无法确定 ...

  7. C# 单例3种写法

    public class Singleton { private static Singleton _instance = null; private Singleton(){} public sta ...

  8. ASP.NET MVC5 之路由器

    这篇博客介绍的很详细 http://www.cnblogs.com/yaozhenfa/p/asp_net_mvc_route_1.html

  9. CSS------选择器-----------选择器的分组、属性选择器

    /*!--选择器的分组--*/ .groupDiv h1,h2,h3,h4{ color: #000000; } /*------------------------属性选择器--*/ [title] ...

  10. es6杂记

    es6杂记 let 和 const let 仅在代码块里有效 { let a = 10; var b = 1; } a // ReferenceError: a is not defined. b / ...