离散化加 求逆序数:

求逆序数的方法 一个是归并排序  一个是树状数组

#include<bits/stdc++.h>
using namespace std;
int n;
struct node
{
int v;
int id;
}s[];
int c[];
bool cmp(node a,node b)
{
return a.v<b.v;
}
int lowbit(int i)
{
return i&-i;
}
int update(int x,int v)
{
while(x<=n)
{
c[x]+=v;
x+=lowbit(x);
} }
int sum(int x)
{
int ans=;
while(x>)
{
ans+=c[x];
x-=lowbit(x);
}
return ans;
}
int main()
{
while(scanf("%d",&n)==)
{
memset(s,,sizeof(s));
memset(c,,sizeof(c));
for(int i=;i<=n;i++)
{
s[i].id=i;
scanf("%d",&s[i].v);
}
sort(s+,s+n+,cmp);
long long ans=;
for(int i=;i<=n;i++)
{
update(s[i].id,);
ans+=i-sum( s[i].id );
}
printf("%lld\n",ans);
}
return ;
}

Frosh Week HDU3743(逆序数)的更多相关文章

  1. Frosh Week(归并排序求逆序数)

    H - Frosh Week Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Desc ...

  2. HDU 3743 Frosh Week(归并排序求逆序数)

    归并排序求逆序数 #include <iostream> #include <cstdio> using namespace std; #define maxn 1000005 ...

  3. HDU3465 树状数组逆序数

    Life is a Line Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)T ...

  4. HDU 1394 Minimum Inversion Number(最小逆序数 线段树)

    Minimum Inversion Number [题目链接]Minimum Inversion Number [题目类型]最小逆序数 线段树 &题意: 求一个数列经过n次变换得到的数列其中的 ...

  5. 递归O(NlgN)求解逆序数

    导言 第一次了解到逆序数是在高等代数课程上.当时想计算一个数列的逆序数直觉就是用两重循环O(n^2)暴力求解.现在渐渐对归并算法有了一定的认识,因此决定自己用C++代码小试牛刀. 逆序数简介 由自然数 ...

  6. FZU 2184 逆序数还原

    传送门 Description 有一段时间Eric对逆序数充满了兴趣,于是他开始求解许多数列的逆序数(对于由1...n构成的一种排列数组a,逆序数即为满足i<j,ai>aj的数字对数),但 ...

  7. HDU 1394 Minimum Inversion Number(最小逆序数/暴力 线段树 树状数组 归并排序)

    题目链接: 传送门 Minimum Inversion Number Time Limit: 1000MS     Memory Limit: 32768 K Description The inve ...

  8. poj 1007:DNA Sorting(水题,字符串逆序数排序)

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 80832   Accepted: 32533 Des ...

  9. POJ 2299 Ultra-QuickSort 逆序数 树状数组 归并排序 线段树

    题目链接:http://poj.org/problem?id=2299 求逆序数的经典题,求逆序数可用树状数组,归并排序,线段树求解,本文给出树状数组,归并排序,线段树的解法. 归并排序: #incl ...

随机推荐

  1. VC++中LogFont设置字体(转)

    LOGFONT是Windows内部字体的逻辑结构,主要用于设置字体格式,其定义如下:typedef struct tagLOGFONTA{LONG lfHeight;LONG lfWidth;LONG ...

  2. JavaScript之小工具之日志log()[兼容]

    function log(){ try{ console.log.apply(console,arguments); }catch(e){ try{ opera.postError.apply(ope ...

  3. CDH集群中YARN的参数配置

    CDH集群中YARN的参数配置 前言:Hadoop 2.0之后,原先的MapReduce不在是简单的离线批处理MR任务的框架,升级为MapReduceV2(Yarn)版本,也就是把资源调度和任务分发两 ...

  4. Mybatis进阶学习笔记——动态代理方式开发Dao接口、Dao层(推荐第二种)

    1.原始方法开发Dao Dao接口 package cn.sm1234.dao; import java.util.List; import cn.sm1234.domain.Customer; pu ...

  5. FPN 学习笔记

    通常,利用网络对物体进行检测时,浅层网络分辨率高,学到的是图片的细节特征,深层网络,分辨率低,学到的更多的是语义特征. 1).通常的CNN使用如下图中显示的网络,使用最后一层特征图进行预测 例如VGG ...

  6. windows安装anaconda 报错failed to create anacoda menu ?

    windows安装anaconda 报错failed to create anacoda menu ? 装了无数次,每次都是 failed to create anacoda menu然后无选择忽略, ...

  7. Linux内核驱动基础(一)常用宏定义【转】

    转自:http://blog.csdn.net/tommy_wxie/article/details/9427081 一: __init和__initdata  : __exit和__exitdata ...

  8. OA协同办公软件

    OA协同办公软件: 泛微软件. 九思软件. 华天动力. 万户OA.:北京万户网络技术有限公司创立于1998年2月,是北京华宇软件股份有限公司(股票简称:“华宇软件”,股票代码:300271)的全资子公 ...

  9. CROSSUI桌面工具 分布加载模块(Distributed UI Module) 与 主模块Module 之间数据传输!

    CROSSUI 基于 NW,如何在模Module 之间(主index.js and module1.js)传输数据?  http://www.crossui.com/Forum/post577.htm ...

  10. Go语言学习之路(持续更新中)

    菜鸟 Go语言教程 教程(RUNOOB.COM):http://www.runoob.com/go/go-tutorial.html Go全球官网:https://golang.org/ (2018- ...