bzoj 4430: [Nwerc2015]Guessing Camels赌骆驼
4430: [Nwerc2015]Guessing Camels赌骆
Description
Input
Output
Sample Input
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
0
Sample output 2
3
#include<stdio.h>
#include<iostream>
using namespace std;
const int N=;
int n,i,a[N],b[N],c[N],t[N],p[N];
long long ans;
void update(int x)
{
while(x<=n)
{
t[x]++;
x+=x&-x;
}
}
int solve(int x)
{
int ans=;
while(x>)
{
ans+=t[x];
x-=x&-x;
}
return ans;
}
int main()
{
scanf("%d",&n);
for(i=;i<=n;i++) scanf("%d",&a[i]);
for(i=;i<=n;i++) scanf("%d",&b[i]);
for(i=;i<=n;i++) scanf("%d",&c[i]);
for(i=;i<=n;i++) p[a[i]]=i;
for(i=n;i>=;i--)
{
ans+=solve(p[b[i]]);
update(p[b[i]]);
}
for(i=;i<=n;i++) p[b[i]]=i,t[i]=;
for(i=n;i>=;i--)
{
ans+=solve(p[c[i]]);
update(p[c[i]]);
}
for(i=;i<=n;i++) p[c[i]]=i,t[i]=;
for(i=n;i>=;i--)
{
ans+=solve(p[a[i]]);
update(p[a[i]]);
}
cout<<((1LL*n*(n-)-ans)>>);
return ;
}
bzoj 4430: [Nwerc2015]Guessing Camels赌骆驼的更多相关文章
- 【BZOJ】4430: [Nwerc2015]Guessing Camels赌骆驼
[题意]给定三个长度为n的排列,求在三个排列中顺序相同的数对个数. [算法]逆序对 [题解]很容易联想到NOIP火柴排队,涉及顺序问题显然和逆序对息息相关. 一个数对如果在三个排列中顺序不同,一定是1 ...
- bzoj4430 [Nwerc2015]Guessing Camels赌骆驼
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4430 [题解] 把每只骆驼在第一个人.第二个人.第三个人的位置找出来,然后做三维偏序即可. ...
- BZOJ 4430 Guessing Camels赌骆驼
[题意概述] 给出三个n的排列,求有多少个数对在三个排列中顺序相同 [题解] 考虑用补集转化的方法,答案为总对数-不满足的对数 一对数不满足条件,当且仅当这对数在两个排列中顺序相同,在另一个排列中的顺 ...
- BZOJ 4430 Guessing Camels
Description Jaap, Jan, and Thijs are on a trip to the desert after having attended the ACM ICPC Worl ...
- bzoj 4428: [Nwerc2015]Debugging调试
4428: [Nwerc2015]Debugging调试 Description Your fancy debugger will not help you in this matter. There ...
- 【容斥原理】【推导】【树状数组】Gym - 101485G - Guessing Camels
题意:给你三个1~n的排列a,b,c,问你在 (i,j)(1<=i<=n,1<=j<=n,i≠j),有多少个有序实数对(i,j)满足在三个排列中,i都在j的前面. 暴力求的话是 ...
- BZOJ 4425: [Nwerc2015]Assigning Workstations分配工作站
难度在于读题 #include<cstdio> #include<algorithm> #include<queue> using namespace std; p ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 越狱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 ...
随机推荐
- FJOI游记(日记向 不定期更新)
emmmm说实话只是突发奇想开个blog记录记录自己的内心想法罢了.. 2017/12/22:刷了一周的计算几何..刷的死去活来..结果还是被D惨了...譬如都不会考,要考我都不会什么的...感觉内心 ...
- linux网络编程之IO函数
Linux操作系统中的IO函数主要有read(),write(),recv(),send(),recvmsg(),sendmsg(),readv(),writev(). 接收数据的recv()函数 # ...
- Linux NAPI/非NAPI
本文主要介绍二层收包流程,包括NAPI与非NAPI方式: NAPI:数据包到来,第一个数据包产生硬件中断,中断处理程序将设备的napi_struct结构挂在当前cpu的待收包设备链表softnet_d ...
- ThinkPHP5 模型 - 事务支持
使用事务之前,先确保数据库的存储引擎支持事务操作. MyISAM:不支持事务,主要用于读数据提高性能 InnoDB:支持事务.行级锁和并发 Berkeley DB:支持事务 ThinkPHP5 使用事 ...
- Qualcomm platform, the commonly used parameters of charger and battery in device tree file
Platform MSM8917 PM8937 PMI8940 Parameters 1 battery charging voltage : qcom,float-voltage-mv = < ...
- monkey测试===Monkey测试结果分析(系列三)转
Monkey测试结果分析 一. 初步分析方法: Monkey测试出现错误后,一般的差错步骤为以下几步: 1. 找到是monkey里面的哪个地方出错 2. 查看Monkey里面出错前的一些事件动作,并手 ...
- mui 选项卡与header文字同步
mui底部tab固定 头部nav可变 <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...
- django中使用第三方包实现定时任务
# 转载请留言联系 在做主页静态化的时候,需要定时生成主页HTML,以保持数据的最新. 定时任务可以用第三方包django-crontab来实现. 附上官方文档:https://pypi.org/pr ...
- ajax登录请求,无法跳转
没有用form提交数据,用的ajax提交.服务器显示已经登录成功,并且返回了成功代码OK.却无法进行跳转: js代码: $("input[type='submit']").on(& ...
- LeetCode Linked List Cyle
Problem Description Given a linked list, determine if it has a cycle in it. Follow up:Can you solve ...