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 [题解] 把每只骆驼在第一个人.第二个人.第三个人的位置找出来,然后做三维偏序即可. ...
随机推荐
- 文本聚类——Kmeans
上两篇文章分别用朴素贝叶斯算法和KNN算法对newgroup文本进行了分类測试.本文使用Kmeans算法对文本进行聚类. 1.文本预处理 文本预处理在前面两本文章中已经介绍,此处(略). 2.文本向量 ...
- 【Access2007】Access2007的打开方式
Access2007提供了多种打开方式 仅仅读与非仅仅读就不用说了,就是能编辑与不可以编辑的差别 是否以独占的方式打开是Access2007的打开方式的核心 这里什么都没有写的打开是指以"共 ...
- C#给指定doc文件写入宏
private void InsertMacro() { Word.Application oWord; Word.Document oDoc; VBIDE.VBComponent oModule; ...
- 【C语言】求两个数中不同的位的个数
//求两个数中不同的位的个数 #include <stdio.h> int count_different(int a, int b) { int count = 0; int c = a ...
- uboot 命令
1.清除前一次的编译结果: make distclean 2.配置makefile:选择开发板 make smdk6410_config 3.编译 make 注意::编译时,打开的文档文件,目录都要 ...
- Tomcat appears to still be running with PID 19564. Start aborted
产生原因:tomcat 异常关闭, 或强行终止导致(如断电等....) 如你所见 . tomcat 在linux 关, 关不了. 开开不了. 疯狂百度一个小时以后,大致产生问题的原因是,LINUX ...
- 流迭代器 + 算法灵活控制IO流
前言 标准算法配合迭代器使用太美妙了,使我们对容器(数据)的处理更加得心应手.那么,能不能对IO流也使用标准算法呢?有人认为不能,他们说因为IO流不是容器,没有迭代器,故无法使用标准算法.他们错了,错 ...
- 使用UIWebView载入本地或远程server上的网页
大家都知道,使用UIWebView载入本地或远程server上的网页,sdk提供了三个载入接口: - (void)loadRequest:(NSURLRequest *)request; - (voi ...
- Comparison method violates its general contract! 异常原因
项目运行期间出现Comparison method violates its general contract!异常,网上查阅了一下,原因还是比较明确的: Collections.sort(list, ...
- Riak Core Guide 2
Learn Riak Core Step By Step 2 Riak Core, The Coordinator What is a Coordinator? 顾名思义. Coordinator即使 ...