bit+容斥原理

我不会cdq分治只能用这个做法

考虑什么情况下不满足,至少有一个顺序不对就不行了,那么不满足的总有两对属性形成逆序对,那么我们用总方案数*2=n*(n-1)减去不符合的*2再/2就是答案

似乎进rank前200了

#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + ;
namespace IO
{
const int Maxlen = N * ;
char buf[Maxlen], *C = buf;
int Len;
inline void read_in()
{
Len = fread(C, , Maxlen, stdin);
buf[Len] = '\0';
}
inline void fread(int &x)
{
x = ;
int f = ;
while (*C < '' || '' < *C) { if(*C == '-') f = -; ++C; }
while ('' <= *C && *C <= '') x = (x << ) + (x << ) + *C - '', ++C;
x *= f;
}
inline void fread(long long &x)
{
x = ;
long long f = ;
while (*C < '' || '' < *C) { if(*C == '-') f = -; ++C; }
while ('' <= *C && *C <= '') x = (x << ) + (x << ) + *C - '', ++C;
x *= f;
}
inline void read(int &x)
{
x = ;
int f = ; char c = getchar();
while(c < '' || c > '') { if(c == '-') f = -; c = getchar(); }
while(c >= '' && c <= '') { x = (x << ) + (x << ) + c - ''; c = getchar(); }
x *= f;
}
inline void read(long long &x)
{
x = ;
long long f = ; char c = getchar();
while(c < '' || c > '') { if(c == '-') f = -; c = getchar(); }
while(c >= '' && c <= '') { x = (x << 1ll) + (x << 3ll) + c - ''; c = getchar(); }
x *= f;
}
} using namespace IO;
int n;
int t[N], a[N], b[N], c[N], pos[N];
void update(int x, int d)
{
for(; x <= n; x += x & -x) t[x] += d;
}
int query(int x)
{
int ret = ;
for(; x; x -= x & -x) ret += t[x];
return ret;
}
long long solve(int *a, int *b)
{
long long ret = ;
for(int i = ; i <= n; ++i)
{
pos[a[i]] = i;
t[i] = ;
}
for(int i = n; i; --i)
{
ret += query(pos[b[i]]);
update(pos[b[i]], );
}
return ret;
}
int main()
{
read_in();
fread(n);
for(int i = ; i <= n; ++i) fread(a[i]);
for(int i = ; i <= n; ++i) fread(b[i]);
for(int i = ; i <= n; ++i) fread(c[i]);
printf("%lld\n", ((long long)n * (long long)(n - ) - solve(a, b) - solve(b, c) - solve(c, a)) >> );
return ;
}

bzoj4430的更多相关文章

  1. bzoj4430 [Nwerc2015]Guessing Camels赌骆驼

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4430 [题解] 把每只骆驼在第一个人.第二个人.第三个人的位置找出来,然后做三维偏序即可. ...

随机推荐

  1. Spring的Scheme位置

    org.springframework.aop.config org.springframework.contex.config org.springframework.ejb.config org. ...

  2. Swift高阶函数介绍(闭包、Map、Filter、Reduce)

    Swift语言有非常多函数式编程的特性.常见的map,reduce,filter都有,初看和python几乎相同,以下简介下 闭包介绍: 闭包是自包括的功能代码块,能够在代码中使用或者用来作为參数传值 ...

  3. 初探IO复用

    前言 在之前的文章中,我具体实现了一个并发回射服务器并给它加载了僵尸子进程的自动清理信号机制.在正常情况下,它已经可以很好地工作了,但它能否合理应对一些特殊情况呢? 问题发现 先来看看当服务器的客户子 ...

  4. Android中通过GPS或NetWork获取当前位置的经纬度

    今天在Android项目中要实现一个通过GPS或NetWork来获取当前移动终端设备的经纬度功能.要实现该功能要用到Android Framework 中的 LocationManager 类.下面我 ...

  5. aop学习总结二------使用cglib动态代理简单实现aop功能

    aop学习总结二------使用cglib动态代理简单实现aop功能 模拟业务需求: 1.拦截所有业务方法 2.判断用户是否有权限,有权限就允许用户执行业务方法,无权限不允许用户执行业务方法 (判断是 ...

  6. Java服务器端 API 错误码设计总结

    1.对于API结果返回,定义BaseResult 类 拥有success,errorCode,errorMsg个3个基本参数,success使用Boolean类型,errorCode使用Integer ...

  7. Detours3.0 文档翻译

    http://blog.csdn.net/buck84/article/details/8289991 拦截二进制函数 Detours库能够在执行过程中动态拦截函数调用.detours将目标函数前几个 ...

  8. 区块链+AI将给区块链带来怎样的改变?

    区块链和人工智能技术都是互联网时代最新.最热的技术,不仅可以改变我们生活,还能产生巨大的财富,为此国家大力支持发展,科技巨头们也纷纷布局.那区块链与人工智能结合,对区块链技术而言会产生什么样的化学反应 ...

  9. virtualbox Units specified don't exist. SHSUCDX can't install.

    version infomatin: virtual box: 5.1.12 platform: win10 x64 target OS: win7 x64 问题 在win10系统上,使用virtua ...

  10. Could not get unknown property 'packageForR' for task ':app:processDebugReso

    butterknife 注解框架的问题 删除项目中的有关butterknife 的 apply plgin.classpath 字段 把注解框架改为最新版本 implementation 'com.j ...