传送门: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赌骆驼的更多相关文章

  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. 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. 人工智能,图片识别,与GUI编程

    GUI编程: https://sourceforge.net/projects/pyqt/ 百度aip图片识别 https://pypi.python.org/pypi/baidu-aip

  2. luogu2387 [NOI2014]魔法森林

    这题和水管局长很像,枚举 \(a\) 的边然后维护关于 \(b\) 的最小生成树就可以了. 1A呐>_< #include <algorithm> #include <i ...

  3. 云计算之路-阿里云上:Web服务器请求到达量突降

    今天下午遇到了自使用阿里云以来首次遇到的新情况——http.sys的ArrivalRate突降(说明请求到达IIS的请求数量少了),而且SLB中的3台ECS都出现了这个问题. 1. 10.161.24 ...

  4. 在 Ubuntu 16.04 LTS 上安装 Python 3.6.0

    原文连接:https://segmentfault.com/a/1190000007912666 最近 Python 3 发布了新版本 Python 3.6.0,好像又加入了不少黑魔法!- 由于暂时不 ...

  5. 阿里云SLB上http强制跳转到https问题处理

    背景: 最近一客户有一个需求,需要将外网所有http访问请求强制跳转到https,公网出口使用阿里云SLB,证书放在SLB上,SLB后端实例为ECS(webserver)web服务使用nginx, 网 ...

  6. 关于2018年东南大学Robomaster算法组工作的总结

    笔者在写作时,为东南大学机器人俱乐部下Robomaster大赛SUPER NOVA战队算法组的负责人之一(这名字写起来好长).而SUPER NOVA战队则于2018年5月19日正式结束了中部分区赛,获 ...

  7. 【读书笔记】2_增强学习中的Q-Learning

    本文为Thomas Simonini增强学习系列文章笔记或读后感,原文可以直接跳转到medium系列文章. 主要概念为: Q-Learning,探讨其概念以及用Numpy实现 我们可以将二维游戏想象成 ...

  8. Python 把两个列表遍历为一个

    两个list, 有对应关系,希望同时完成遍历 用迭代器迭代的方法也不是不可以,python提供了更直观的方法: 可以使用zip把两个list打包 , 类似: list1 = [1,2,3,4] lis ...

  9. Pro Git - 笔记3

    Git Branching Branches in a Nutshell Branches in a Nutshell let’s assume that you have a directory c ...

  10. ByteArrayInputStream/ByteArrayOutputStream 学习

    ByteArrayInputStream: byte[] buff = new byte[1024]; ByteArrayInputStream bAIM = new ByteArrayInputSt ...