[Nwerc2015]Guessing Camels赌骆驼

Description
Jaap, Jan, and Thijs are on a trip to the desert after having attended the ACM ICPC World Finals 2015 in Morocco. The trip included a camel ride, and after returning from the ride, their guide invited them to a big camel race in the evening. The camels they rode will also participate and it is customary to bet on the results of the race.
One of the most interesting bets involves guessing the complete order in which the camels will finish the race. This bet offers the biggest return on your money, since it is also the one that is the hardest to get right.
Jaap, Jan, and Thijs have already placed their bets, but the race will not start until an hour from now, so they are getting bored. They started wondering how many pairs of camels they have put in the same order. If camel cc is before camel d on Jaap’s, Jan’s and Thijs’ bet, it means that all three of them put c and d in the same order. Can you help them to calculate the number of pairs of camels for which this happened?
Jaap,Jan和Thijs在摩洛哥参加完ACMICPC2015全球总决赛后去沙漠进行了一次旅行。旅行包括了骑骆驼。在骑完回来之后,他们的向导邀请他们在晚上去看一场盛大的骆驼赛跑。他们骑的骆驼也会参加,而赌比赛的结果是一个习惯。其中一个最有趣的赌涉及猜测完成比赛的骆驼的完整名单。这个赌可以为你赢得最多的钱,因为它也是最难猜对的。
Jaap,Jan和Thijs已经下了注,但比赛要在一个小时后才开始,所以他们觉得很无聊。他们开始想知道有多少对骆驼他们赌了同样的顺序。如果在他们三人的猜测名单中,骆驼c在骆驼d前,就意味着c和d在他们的名单中有相同的顺序。你能帮他们计算有多少对骆驼是这样的吗?
Input
The input consists of:
one line with an integer n ( 2≤n≤200000), the number of camels;
one line with n integers a1,…,ana1,…,an ( 1≤ai≤n for all i ), Jaap’s bet. Here a1 is the camel in the first position of Jaap’s bet, a2 is the camel in the second position, and so on;
one line with Jan’s bet, in the same format as Jaap’s bet;
one line with Thijs’ bet, in the same format as Jaap’s bet.
The camels are numbered 1,…,n . Each camel appears exactly once in each bet.
输入包括:
第一行是一个整数n(2<=n<=200000),骆驼的数量。
第二行有n个整数a1…an(1<=ai<=n),是Jaap的下赌名单。a1是名单中第一位,a2是第二位,等等。
第三行是Jan的名单,格式同上。
第四行是Thijs的名单,格式同上。
骆驼从1到n编号,每头骆驼在一份名单中只出现一次。
Output
Output the number of pairs of camels that appear in the same order in all 3 bets.
输出在三份名单中同样顺序的骆驼有多少对。
Sample Input
Sample input 1
3
3 2 1
1 2 3
1 2 3
Sample input 2
4
2 3 1 4
2 1 4 3
2 4 3 1
Sample Output
Sample output 1
0
Sample output 2
3

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define hash _hash
#define MS(_) memset(_,0,sizeof(_))
template<typename T> inline void read(T &x){x=0; T f=1; char ch=getchar();while(!isdigit(ch)) {if(ch=='-') f=-1; ch=getchar();}while(isdigit(ch))  {x=x*10+ch-'0'; ch=getchar();}x*=f;
}const int MaxN = 300100;
int n;
ll a[MaxN],b[MaxN],c[MaxN],pos[MaxN],hash[MaxN],BIT[MaxN];inline int lowbit(int k){return k&-k;}
inline ll qry(int k){ll res=0;for(;k;k-=lowbit(k))res+=BIT[k];return res;}
inline void mdf(int k){for(;k<=n;k+=lowbit(k))BIT[k]++;}
inline ll cal(ll a[],ll b[]){for(int i=1;i<=n;i++)hash[a[i]]=i;for(int i=1;i<=n;i++)pos[hash[b[i]]]=i;MS(BIT);ll res=0;for(int i=n;i>=1;i--){res += qry(pos[i]-1);mdf(pos[i]);}return res;
}
int main(){read(n);for(int i=1;i<=n;i++)read(a[i]);for(int i=1;i<=n;i++)read(b[i]);for(int i=1;i<=n;i++)read(c[i]);ll ans = cal(a,b)+cal(a,c)+cal(b,c);    printf("%lld\n",1ll*n*(n-1)/2ll-ans/2ll);return 0;
}

[BZOJ4430][Nwerc2015]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. BZOJ 4430 Guessing Camels赌骆驼

    [题意概述] 给出三个n的排列,求有多少个数对在三个排列中顺序相同 [题解] 考虑用补集转化的方法,答案为总对数-不满足的对数 一对数不满足条件,当且仅当这对数在两个排列中顺序相同,在另一个排列中的顺 ...

  4. Guessing Camels

    题目链接:Guessing Camels 把每个数字在分别三个数组出现的位置当成三个维度的下标. 那么问题就变成一个三维偏序了,cdq分治即可. AC代码: #pragma GCC optimize( ...

  5. Gym - 101485G NWERC2015 G Guessing Camels

    本题暴力做听说可以动态树,然而我不会. 3维偏序可以用CDQ分治,寒假学了然而考场上不会写.(菜不成声.jpg) 再间接一点,我们知道是用总数对减去存在逆序的数对. 而逆序就是求两个数列中的两个数字相 ...

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

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

  7. 《骆驼祥子》读书报告

    <骆驼祥子>读书报告 初2024级13班 刘颜嘉 2022年4月3日 引言 钱会把人引进恶劣的社会中去,把高尚的理想撇开,而甘心走入地狱中去. 一.祥子的小传   积极向上去买车 祥子刚到 ...

  8. 为什么“骆驼祥子”的奋斗,跳不出贫穷的“三大恶性循环”?

    <骆驼祥子>就是一个民国的"北漂故事" 编者按:本文来自微信公众号"人神共奋"(ID:tongyipaocha),作者人神共奋,36氪经授权发布. ...

  9. 【仿去哪儿】骆驼动画加载

    简单的实现正在加载的动画,比较粗糙,没有实现后面的旋转地球.图一为去哪儿的截图,图二为本文实现的效果 图1 图2 一.新建LoadView继承自UIView,声明几个方法,这样在项目需要用到时,直接调 ...

最新文章

  1. 马云出 1000 亿做阿里达摩院:产品卖到全球了,他说科学研究也要跟上
  2. JS滚轮事件(mousewheel/DOMMouseScroll)了解
  3. mysql 全面知识点_Mysql知识点整理
  4. 吴恩达深度学习课程deeplearning.ai课程作业:Class 4 Week 1 Convolution model - Application
  5. 既是客户又是供应商清帐配置
  6. hibernate报错 net.sf.json.util.CycleDetectionStrategy$StrictionStrategyRepeatedReferenceAsObject
  7. 【OpenCV函数】轮廓提取;轮廓绘制;轮廓面积;外接矩形
  8. samba 服务器搭建
  9. Mysql disk write 高_优化系列|实例解析MySQL性能瓶颈排查定位 导读 排查过程
  10. 浅谈如何进行测试用例管理
  11. mysql常用功能点
  12. java severlet 例子_Java开发Servlet实例
  13. 22:紧急措施http://noi.openjudge.cn/ch0107/22/
  14. TI CC2530 学习笔记-13-NewBit-CC2530-ADC-内部温度传感器
  15. ajax data=text,jQuery ajax dataType值为text json探索分享
  16. INFOR-CRB开发教程
  17. 关于间皮瘤mesothelioma的相关信息
  18. 通俗理解偏序关系中的八个特殊元(极大、极小、最大、最小元和上界、下界、上确界、下确界)
  19. matlab 回归 工具箱,matlab回归分析工具箱
  20. 0基础学习C语言第十一章:文件读写

热门文章

  1. 制作坦克大战,坦克移动代码
  2. 阿里云服务器能做小程序吗
  3. 合工大计算机录取分数,合肥工业大学适合“捡漏”的专业,录取分数最低
  4. 【C语言】BC102 带空格直角三角形图案(DAY 9)
  5. C语言打印三角形图案
  6. 7-42 打印倒直角三角形图案 (15 分)
  7. misc.imresize
  8. 10款超实用的程序员工具,工具用得好,头发掉的少
  9. 底层嵌入式之NOR FLASH编程
  10. ARM之S5pv210的按键和中断部分