bzoj4430 [Nwerc2015]Guessing Camels赌骆驼
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4430
【题解】
把每只骆驼在第一个人、第二个人、第三个人的位置找出来,然后做三维偏序即可。
排序+cdq分治+BIT
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h> using namespace std; typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 2e5 + ;
const int mod = 1e9+; # define RG register
# define ST static int n, a[M], b[M], c[M], pb[M], pc[M];
ll ans = ; struct pa {
int a, b, c, ans;
pa() {}
pa(int a, int b, int c, int ans) : a(a), b(b), c(c), ans(ans) {}
friend bool operator <(pa a, pa b) {
return a.b < b.b || (a.b == b.b && a.a < b.a) ||
(a.b == b.b && a.a == b.a && a.c < b.c);
}
}p[M], t[M]; struct BIT {
int n, c[M];
# define lb(x) (x&(-x))
inline void set(int _n) {
n = _n;
memset(c, , sizeof c);
}
inline void edt(int x, int d) {
for (; x<=n; x+=lb(x)) c[x] += d;
}
inline int sum(int x) {
int ret = ;
for (; x; x-=lb(x)) ret += c[x];
return ret;
}
inline int sum(int x, int y) {
if(x > y) return ;
return sum(y) - sum(x-);
}
}T; inline void solve(int l, int r) {
if(l == r) return;
int mid = l+r>>, t1n = l-, t2n = mid;
for (int i=l; i<=r; ++i)
if(p[i].a <= mid) t[++t1n] = p[i];
else t[++t2n] = p[i];
for (int i=l; i<=r; ++i) p[i] = t[i];
int j=l;
for (int i=mid+; i<=r; ++i) {
while(j<=mid && p[j].b <= p[i].b) T.edt(p[j].c, ), j++;
p[i].ans += T.sum(p[i].c);
}
for (int i=l; i<j; ++i) T.edt(p[i].c, -);
solve(l, mid);
solve(mid+, r);
} int main() {
cin >> n; T.set(n);
for (int i=; i<=n; ++i) scanf("%d", a+i);
for (int i=; i<=n; ++i) scanf("%d", b+i), pb[b[i]] = i;
for (int i=; i<=n; ++i) scanf("%d", c+i), pc[c[i]] = i;
for (int i=; i<=n; ++i) p[i] = pa(i, pb[a[i]], pc[a[i]], );
// for (int i=1; i<=n; ++i) printf("%d %d %d\n", p[i].a, p[i].b, p[i].c);
sort(p+, p+n+);
solve(, n);
for (int i=; i<=n; ++i) ans += p[i].ans;
cout << ans;
return ;
}
bzoj4430 [Nwerc2015]Guessing Camels赌骆驼的更多相关文章
- 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 ...
- 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 ...
- 【容斥原理】【推导】【树状数组】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 ...
- 越狱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 ...
- 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) 对于有公共点的管道建边, ...
随机推荐
- 破解PHPStrom 10 and Pycharm
注册时选择 License server http://idea.lanyus.com/ 然后点击OK Pycharm -- License server http://idea.lanyus.com ...
- C/C++-左值、右值及引用
目录 1.左值and右值 2.引用 3.左值引用的用途 4.std::move和std::swap C和C++中定义了引用类型(reference type),存在左值引用(lvalue refere ...
- WEBSTORM中html文件运行之后出现乱码的问题解决
出现如下问题: 解决方案: 1.点击"文件编码" 2.选择GBK 3.点击Reload. 4.此时,源代码中的中文字体会变成乱码,把这些乱码重新输入成原先的中文.然后运行html文 ...
- Activiti工作流(二)——入门Demo及数据库
上篇博客简单介绍了Activiti流程图的使用,这篇博客我们就根据这个流程图来完成这一个流程. 下图是Activiti的系统服务结构图,在后面的流程中,我们会用到其中的功能组件,如Repositor ...
- To Chromium之版本管理
Git. 1.由于想直接submit到Chromium的官方Branch需要申请权限,目前拿不到,所以打算snapshot一个chromium版本. 本地搭建一个git的server/client,方 ...
- QThread中的互斥、读写锁、信号量、条件变量
该文出自:http://www.civilnet.cn/bbs/browse.php?topicno=78431 在gemfield的<从pthread到QThread>一文中我们了解了线 ...
- JConsole本地连接失败
一.问题描述 笔者在使用JDK自带的JConsole小工具连接Myeclipse里面注册的MBean时,报如下错: 二.解决办法 添加JVM运行参数: -Dcom.sun.management.jmx ...
- Python 错误和异常处理
#常见的异常 class Human: #属性 sex = 'man' age = 18 #方法 def run(self): print('跑啊~~~') #实例化对象 #zw = Human() ...
- json数据中的某一个字段进行快速排序quicksort
快速排序(Quicksort)是对冒泡排序的一种改进,是一种分而治之算法归并排序的风格. 核心的思想就是通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小 ...
- appendTo()方法和append()方法
appendTo() 方法在被选元素的结尾(仍然在内部)插入指定内容.