bzoj4430
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的更多相关文章
- bzoj4430 [Nwerc2015]Guessing Camels赌骆驼
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4430 [题解] 把每只骆驼在第一个人.第二个人.第三个人的位置找出来,然后做三维偏序即可. ...
随机推荐
- Oracle-31-对视图DML操作
一.对视图进行DML操作 1.创建一个视图v_person create or replace noforceview v_person as select *from person where id ...
- android4.4 evaluateJavascript 到android2.X上不能调用的问题
android4.4上想用js注入的话.不能用旧的loadUrl()方法,每次load都会将页面又一次刷新一次. 可是在2.X的系统版本号上,evaluateJavascript 方法会报异常.解决的 ...
- 【每日Scrum】第四天(4.14) TD学生助手Sprint1站立会议
TD学生助手Sprint1站立会议(4.14) 任务看板 站立会议内容 组员 昨天 今天 困难 签到 刘铸辉 (组长) 今天早晨静姐调整了下界面和配色,下午和宝月兄一起做了GPS功能显示,暂时只能显示 ...
- 储存技术(SLC、MLC、TLC和QLC的NAND闪存技术)和Optane Memory
1.转载:Optane Memory 2.构成SSD的主要IC有主控芯片和NAND闪存,SLC.MLC和TLC三者都是闪存的类型 需要说明的闪存的寿命指的是写入(擦写)的次数,不是读出的次数,因为读取 ...
- hdu5387(2015多校8)--Clock(模拟)
题目链接:点击打开链接 题目大意:给出一个时间,问在钟表上这个时间的时候.时针和分针的角度,时针和秒针的角度.分针和秒针的角度.假设不是整数以分数的形式输出. 假设依照最小的格来算,那么: 1s对于秒 ...
- Unity3D总结:关于射线碰撞
方法一:Physics.Raycast 光线投射 1.static function Raycast (origin : Vector3, direction : Vector3, distance ...
- 自己动手写CPU之第七阶段(5)——流水线暂停机制的设计与实现
将陆续上传本人写的新书<自己动手写CPU>,今天是第28篇.我尽量每周四篇 China-pub的预售地址例如以下(有文件夹.内容简单介绍.前言): http://product.china ...
- restframework-总结
1. 规范 - 版本控制 - 部署专用的域名(防止跨域攻击) - 因为restframework又称为面向资源的编程所以url名词需要用专业的名词去表示 - 请求方式method - url上可以传递 ...
- 更新 手淘 flexible 布局 rem 单位适配问题
详见链接 https://github.com/amfe/lib-flexible
- Continuous Integration with Selenium
I have seen a lot of queries from people who basically want to know how to blend Selenium, Maven, an ...