[BZOJ4989] [Usaco2017 Feb]Why Did the Cow Cross the Road(树状数组)


传送门

发现就是逆序对

可以树状数组求出

对于旋转操作,把一个序列最后面一个数移到开头,假设另一个序列的这个数在位置x,那么对答案的贡献 (n x) + (x 1)

#include <cstdio>#include <cstring>#include <iostream>#define N 200011#define LL long longusing namespace std;int n;int a[N], b[N], pos1[N], pos2[N];LL c[N], ans = 1ll * N * N;inline int read()inline void add(int x)inline LL query(int x)inline void solve()ans = min(ans, sum);for(i = n; i > 1; i)}int main()

  



上一篇:[BZOJ4993||4990] [Usaco2017 Feb]Why Did the Cow Cross the Road II(DP + 线段树)

下一篇:[BZOJ4994] [Usaco2017 Feb]Why Did the Cow Cross the Road III(树状数组)


树状数组
Copyright © 2002-2019 k262电脑网 www.k262.cn 皖ICP备2020016292号
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!QQ:251442993 热门搜索 网站地图