手画几下序列的变换后发现逆序对数是恒定的,故只需对第 $0$ 年求逆序对即可.
树状数组会 $TLE$ 的很惨,需要用到归并排序来求逆序对.
其实就是省掉了一个离散化的时间,估计能比树状数组快一半的时间.

#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 2000004
#define ll long long
#define setIO(s) freopen(s".in", "r" , stdin)
using namespace std;
namespace IO
{
char *p1,*p2,buf[100000];
#define nc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
int readint() {int x=0; char c=nc(); while(c<48) c=nc(); while(c>47) x=(((x<<2)+x)<<1)+(c^48),c=nc(); return x;}
ll readll() {ll x=0; char c=nc(); while(c<48) c=nc(); while(c>47) x=(((x<<2)+x)<<1)+(c^48),c=nc(); return x;}
};
ll re = 0;
int a[N], bu[N], n ;
void solve(int l , int r)
{
if(l == r) return ;
int mid = (l + r) >> 1, tmp = 0, tl = l, tr = mid + 1;
solve(l, mid), solve(mid + 1, r);
while(tl <= mid && tr <= r)
{
if(a[tl] <= a[tr]) bu[++ tmp] = a[tl], ++tl;
else bu[++ tmp] = a[tr], ++tr , re += (ll) mid - tl + 1;
}
while(tl <= mid) bu[++ tmp] = a[tl], ++tl;
while(tr <= r) bu[++tmp] = a[tr], ++tr;
for(int i = 1; i <= tmp ; ++ i) a[l + i - 1] = bu[i];
}
int main()
{
using namespace IO;
// setIO("input");
int i , j;
ll oo;
n = readint();
for(i = 1 ; i <= n ; ++ i) a[i] = readint();
oo = readll();
solve(1, n), printf("%lld\n", re);
return 0;
}

  

最新文章

  1. 深入理解CSS过渡transition
  2. linux内核分析作业3:跟踪分析Linux内核的启动过程
  3. delphi 弹出选择目录窗口
  4. Android属性动画之ObjectAnimator控制
  5. zabbix 微信报警
  6. cygwin 的不同文件类型显示不同的颜色
  7. PHP实现Restful风格的API
  8. 自己用反射写的一个request.getParameter工具类
  9. 【EF】 proxy
  10. ZooKeeper 安装部署及hello world
  11. 网络操作与AFNetworking
  12. UVA 297 Quadtrees(四叉树建树、合并与遍历)
  13. 如何在windows下载和安装Apache
  14. 从UUID想到的
  15. 应对不同格式 轻松转换PDF、WORD、PPT、TXT常用文件
  16. WebDriver元素等待机制
  17. VC++ 实现程序重启
  18. RocketMQ安装教程
  19. mysql匿名登录 导致创建不了数据库
  20. OSPF详解

热门文章

  1. 【VS开发】文件夹和文件选择EditBrowe控件使用
  2. 【VS开发】动态添加的ActiveX控件如何响应事件
  3. python关键字以及含义,用法
  4. Centos(64位)安装Hbase详细步骤
  5. 线程间的协作(wait/notify/sleep/yield/join)(五)
  6. 在SQL Server 中创建外键
  7. 自带的simple认证
  8. Linux下面误删除文件使用extundelete工具恢复介绍
  9. Java第二周总结报告
  10. CF 1140B Good String