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) 对于有公共点的管道建边, ...
随机推荐
- 【jQuery】 实用 js
[jQuery] 实用 js 1. int 处理 parseInt(") // int 转换 isNaN(page) // 判断是否是int类型 2. string 处理 // C# str ...
- JS 客户端检测
能力检测 能力检测的目标不是识别特定的浏览器,而是识别浏览器的能力. 能力检测需要注意两点: 先检测达成目的的最常用的特性.因为先检测最常用的特性可以保证代码最优化,因为在多数情况下都可以避免测试多个 ...
- Windows Server2003下安装IIS服务脑图
在练习过程中,勾选“ASP.NET”后开始安装时提示要插入安装光盘,但是我安装系统时是用镜像文件在虚拟机里安装的,所以根据提示界面的提示从文件中选择相应文件复制,如下图点击确定,选择iisapp.vb ...
- 【java并发编程实战】第五章:基础构建模块
1.同步容器类 它们是线程安全的 1.1 vector和hashtable. 和Collections.synchronizeXxx()一样.实现方式就是在每个方法里面加入synchronize代码块 ...
- Python目录链接
第1章 就这么愉快的开始吧 课时1:我和python的第一次亲密接触 一.Python3的下载与安装 二.从IDIE启动Python 三.尝试点新的东西 四.为什么会这样? 五.课时01课后习题及答案 ...
- 对TPR(真正例率) 与 FPR(反正例率)的理解
将测试样本进行排序,“最可能”是正例的排在最前面,“最不可能”是正例的排在最后面. 分类过程就相当于在这个排序中以某个“截断点”(见图中阈值)将样本分为两部分,前一部分判作正例,后一部分判作反例. 我 ...
- VC++之运算符重载简单小结
封装继承和多态是面向对象三大基本支柱.在面向对象系统中有两种编译方式:静态联编和动态联编静态联编:也叫早期联编:指系统在编译时就决定如何实现某一动作,提供了执行速度快的优点.动态联编:也叫滞后联编:指 ...
- Linux 远程主机安全配置
开启了新的 Linux 服务器后,首要任务是做安全配置. 首先更新: # ubuntu sudo apt-get update # 获取 apt 源的软件列表 sudo apt-get upgrade ...
- Java串口编程学习1-环境配置(64位Win7)
最近在做zigbee的课程设计,需要Java实现对串口数据的读写操作. 网上找了很多代码,好像都比较过时了,直接拿来用没法跑通……QAQ……然后自己写个教程留底,如有不当之处还请各位路过的大神赐教. ...
- 并查集——poj1988(带权并查集中等)
一.题目回顾 题目链接:Cube Stacking 题意:有n个箱子,初始时每个箱子单独为一列:接下来有p行输入,M, x, y 或者 C, x: 对于M,x,y:表示将x箱子所在的一列箱子搬到y所在 ...