BZOJ 4430 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 c 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?
Input
The input consists of:
- one line with an integer n (2 ≤ n ≤ 200 000), the number of camels;
- one line with n integers a1,...,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.
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
固定一个顺序,查找另一个顺序,贴代码主要是学习一下高效输入。
//(总对数减去不同的)/2;
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define lowbit(x) x&(-x)
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define mem(a) (memset(a,0,sizeof(a)))
int a[][],pos[],vis[],n;
inline int iread(){
int f = , x = ; char ch = getchar();
for(; ch < '' || ch > ''; ch=getchar())f = ch=='-'?-:;
for(; ch <= '' && ch >= ''; ch=getchar())x = x*+ch-'';
return f*x;
}
inline void add(int x)
{
for(int i=x;i<=n;i+=lowbit(i))
{
vis[i]+=;
}
}
inline ll query(int x)
{
ll ans=;
for(int i=x;i;i-=lowbit(i))
{
ans+=vis[i];
}
return ans;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
ll ans=;
for(int i=;i<;i++)
{
for(int j=;j<=n;j++)
{
a[i][j]=iread();
//scanf("%d",&a[i][j]);
}
}
for(int i=;i<;i++)
{
memset(vis,,sizeof(vis));
for(int j=;j<=n;j++)
{
pos[a[i][j]]=j;
}
for(int j=n;j;j--)
{
ans+=query(pos[a[(i+)%][j]]);
add(pos[a[(i+)%][j]]);
}
}
printf("%lld\n",(1ll*n*(n-)-ans)>>);
}
return ;
}
BZOJ 4430 Guessing Camels的更多相关文章
- BZOJ 4430 Guessing Camels赌骆驼
[题意概述] 给出三个n的排列,求有多少个数对在三个排列中顺序相同 [题解] 考虑用补集转化的方法,答案为总对数-不满足的对数 一对数不满足条件,当且仅当这对数在两个排列中顺序相同,在另一个排列中的顺 ...
- bzoj 4430: [Nwerc2015]Guessing Camels赌骆驼
4430: [Nwerc2015]Guessing Camels赌骆 Description Jaap, Jan, and Thijs are on a trip to the desert afte ...
- 【BZOJ】4430: [Nwerc2015]Guessing Camels赌骆驼
[题意]给定三个长度为n的排列,求在三个排列中顺序相同的数对个数. [算法]逆序对 [题解]很容易联想到NOIP火柴排队,涉及顺序问题显然和逆序对息息相关. 一个数对如果在三个排列中顺序不同,一定是1 ...
- bzoj4430 [Nwerc2015]Guessing Camels赌骆驼
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4430 [题解] 把每只骆驼在第一个人.第二个人.第三个人的位置找出来,然后做三维偏序即可. ...
- 【容斥原理】【推导】【树状数组】Gym - 101485G - Guessing Camels
题意:给你三个1~n的排列a,b,c,问你在 (i,j)(1<=i<=n,1<=j<=n,i≠j),有多少个有序实数对(i,j)满足在三个排列中,i都在j的前面. 暴力求的话是 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- Gym101485: NWERC 2015(队内第6次训练)
A .Assigning Workstations 题意:给定N个人的工作时间和工作时长,我们可以假设有无数台工作机器,如果一台机器超过M时间未使用就会关闭,那么我们怎么安排机器的使用,使得需要开启机 ...
- 2015-2016 Northwestern European Regional Contest (NWERC 2015)
训练时间:2019-04-05 一场读错三个题,队友恨不得手刃了我这个坑B. A I J 简单,不写了. C - Cleaning Pipes (Gym - 101485C) 对于有公共点的管道建边, ...
- bzoj 2632 [neerc2011]Gcd guessing game——贪心(存疑)
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2632 官方题解:http://neerc.ifmo.ru/archive/2011/neer ...
随机推荐
- POJ 2570 Fiber Network(最短路 二进制处理)
题目翻译 一些公司决定搭建一个更快的网络.称为"光纤网". 他们已经在全世界建立了很多网站.这 些网站的作用类似于路由器.不幸的是,这些公司在关于网站之间的接线问题上存在争论,这样 ...
- 在Linux的终端中显示BMPString的内容
在上一篇博文中,介绍了怎样在 Windows 的控制台界面下输出 BMPString 的内容,可是那里的方法在 Linux 下不适用.假设将那里的演示样例代码放到 Linux 下运行.输出的结果为乱码 ...
- Maven配置Spring+SpringMVC+MyBatis(3.2.2)Pom 以及 IntelliJ IDEA 怎样打开依赖视图
Maven配置Spring+SpringMVC+MyBatis(3.2.2)Pom 配置原则: 利用依赖,将所需的jar包加载到project中. 先依赖主要jar包 Spring + Spring ...
- hdu 4288 线段树+离线+离散化
http://acm.hdu.edu.cn/showproblem.php?pid=4288 開始的时候,果断TLE,做的方法是,线段树上只维护%5==3的坐标,比方1 2 3 4 5 6 7 假设 ...
- 迷宫求解_数据结构c语言版
#include <iostream> #include <string> #include <cstdio> #include <cstdlib> # ...
- 003.ES2015和ES2016新特性--类.md
JavaScript使用的是基于原型的OO模型,用对象字面量或者函数来实例化对象,用原型链来实现继承. 这样对于数据传统C++.Java的OO范式的开发者来说,会感到比较困惑,于是从ES2015开始逐 ...
- df 显示 100%的问题
问题: 使用 df 命令查看,某个分区使用率已经达到100%,但是用du 命令统计该分区,发现该分区空间剩余10G可用. 实例: 分析: ...
- Qihoo 360 altas 实践
Qihoo 360 altas 实践 简介 Atlas是由 Qihoo 360公司Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目.它在MySQL官方推出的MySQL-Prox ...
- vue项目的一些最佳实践提炼和经验总结
项目组织结构 ajax数据请求的封装和api接口的模块化管理 第三方库按需加载 利用less的深度选择器优雅覆盖当前页面UI库组件的样式 webpack实时打包进度 vue组件中选项的顺序 路由的懒加 ...
- HTML标签和文档结构
HTML标签与文档结构 HTML作为一门标记语言,是通过各种各样的标签来标记网页内容的.我们学习HTML主要就是学习的HTML标签. 那什么是标签呢? #1.在HTML中规定标签使用英文的的尖括号即` ...