题目:http://www.fjutacm.com/Problem.jsp?pid=3087

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define lowbit(x) x&(-x)
int c[], n;
long long F[], a[];
void updata(int i, int v)
{
while(i<=n)
{
c[i]+=v;
i+=lowbit(i);
}
}
int getsum(int i)
{
int sum=;
while(i>)
{
sum+=c[i];
i-=lowbit(i);
}
return sum;
}
int main( )
{
int i, j, T;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
long long ans=;
memset(c, ,sizeof(c));
n++;
a[]=;
for(i=; i<=n; i++)
{
scanf("%lld", &a[i]);
a[i]+=a[i-];
}
for(i=; i<=n; i++)
{
a[i]=a[i]*+i;///防止数字重复
F[i]=a[i];
}
sort(a+, a+n+);
for(i=; i<=n; i++)
F[i]=lower_bound(a+, a++n, F[i])-a;///寻找该数字在的位置,那个位置就是改位置新的值
for(i=; i<=n; i++)
{
ans+=getsum(F[i]);
updata(F[i], );
}
printf("%lld\n", ans);
}
}

辣鸡代码

离散化&&逆序数对的更多相关文章

  1. BZOJ 3289 Mato的文件管理(莫队+离散化求逆序数)

    3289: Mato的文件管理 Time Limit: 40 Sec  Memory Limit: 128 MB Submit: 2171  Solved: 891 [Submit][Status][ ...

  2. CF 61E 树状数组+离散化 求逆序数加强版 三个数逆序

    http://codeforces.com/problemset/problem/61/E 题意是求 i<j<k && a[i]>a[j]>a[k] 的对数 会 ...

  3. poj 2299 Ultra-QuickSort(树状数组求逆序数+离散化)

    题目链接:http://poj.org/problem?id=2299 Description In this problem, you have to analyze a particular so ...

  4. HDU 6318 - Swaps and Inversions - [离散化+树状数组求逆序数][杭电2018多校赛2]

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=6318 Problem Description Long long ago, there was an ...

  5. Ultra-QuickSort---poj2299 (归并排序.逆序数.树状数组.离散化)

    题目链接:http://poj.org/problem?id=2299 题意就是求把数组按从小到大的顺序排列,每次只能交换相邻的两个数, 求至少交换了几次 就是求逆序数 #include<std ...

  6. 51nod 1019 逆序数(逆序数+离散化)

    在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序.一个排列中逆序的总数就称为这个排列的逆序数.   如2 4 3 1中,2 1,4 3,4 1,3 1是 ...

  7. HDU 1394 树状数组+离散化求逆序数

    对于求逆序数问题,学会去利用树状数组进行转换求解方式,是很必要的. 一般来说我们求解逆序数,是在给定一串序列里,用循环的方式找到每一个数之前有多少个比它大的数,算法的时间复杂度为o(n2). 那么我们 ...

  8. codeforces_459D_(线段树,离散化,求逆序数)

    链接:http://codeforces.com/problemset/problem/459/D D. Pashmak and Parmida's problem time limit per te ...

  9. HDU3465--Life is a Line(树状数组求逆序数,离散化)

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s ...

随机推荐

  1. 数据输出保存生成word文档

    ob_start(); //打开缓冲区 $header_str = '<html xmlns:o="urn:schemas-microsoft-com:office:office&qu ...

  2. Oracle判断字段中是否包含中文(若有,取出该中文的方法)

    一.问题说明 在处理数据的时候,需要判断某个字段字符串中是否有中文,若有则取出中文. 二.解决办法 首先如何判断某个字段字符串中是否有中文.这里介绍三种方法: 1.采用ASCIISTR函数 说明:AS ...

  3. 学习websocket-SignalR,MVC中使用SignalR打造酷炫实用的即时通讯

    http://www.cnblogs.com/Leo_wl/p/4793284.html http://www.fangsi.net/archives/1144.html

  4. bzoj2818 Gcd(欧拉函数)

    Description 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. Input 一个整数N Output 如题 Sample Input 4 Sam ...

  5. ans_rproxy 说明

    ans_rproxy 说明 网络IP资源分配 Windows2008R2:        IP: 172.16.204.50/24        Gateway: 172.16.204.1      ...

  6. bzoj5055: 膜法师(BIT)

    大水题WA了两发T T 记录一下a[i]的前缀和,a[i]*a[j]就是sigma(a[j]*sumi[j-1]) 记录一下a[i]*a[j]的前缀和,a[i]*a[j]*a[k]就是sigma(a[ ...

  7. C# Emgu CV学习笔记二之图像读写的两种方法

    http://blog.csdn.net/marvinhong/article/details/6800450 图像显示在控件loadPictureBox上 方法一 //读取图像001.jpg Int ...

  8. 2018-2019 ACM-ICPC 沈阳赛区 K. Let the Flames Begin

    K. Let the Flames Begin 题目链接:https://codeforces.com/gym/101955/problem/K 题意: n个人围成一个圈,然后依次从1开始报数,报到k ...

  9. Dell 戴尔预装Windows8改成Windows7

    UEFI模式启动: 添加启动方式,正确路径为: 另外: Ubuntu启动gpt由gpt10变为gpt9 dd

  10. python学习(十)元类

    python 可以通过`type`函数创建类,也可通过type判断数据类型 import socket from io import StringIO import sys class TypeCla ...