Input
Output
Sample Input
2 3 1 5 4
- #include"iostream"
- #include"algorithm"
- #include"cstring"
- #include"cstdio"
- using namespace std;
- #define max 65550
- structab
- {
- int value;
- int index;
- }a[max];
- /*bool cmp(const ab &a,const ab &b)
- {
- if(a.value!=b.value)
- return a.value<b.value;
- else
- return a.index<b.index;
- }*/
- bool cmp(const ab&a,const ab&b)
- {
- return a.value<b.value;
- }
- int c[max],b[max];
- int n;
- int lowbit(int x)
- {
- return x&(-x);
- }
- void updata(int x,int d)
- {
- while(x<=n)
- {
- c[x]+=d;
- x+=lowbit(x);
- }
- }
- int getsum(int x)
- {
- int res=0;
- while(x>0)
- {
- res+=c[x];
- x-=lowbit(x);
- }
- return res;
- }
- int main()
- {
- int i;
- scanf("%d",&n);
- for(i=1;i<=n;i++)
- {
- scanf("%d",&a[i].value);
- a[i].index=i;
- }
- sort(a+1,a+1+n,cmp);
- b[a[1].index]=1;
- memset(c,0,sizeof(c));
- //memset(b,0,sizeof(b));
- for(i=2;i<=n;i++)
- {
- if(a[i].value!=a[i-1].value)
- b[a[i].index]=i;
- else
- b[a[i].index]=b[a[i-1].index];
- }
- long long int sum=0;
- for(i=1;i<=n;i++)
- {
- updata(b[i],1);
- sum+=getsum(n)-getsum(b[i]);
- }
- printf("%lld\n",sum);
- return 0;
- }
Inversions的更多相关文章
-
[UCSD白板题] Number of Inversions
Problem Introduction An inversion of a sequence \(a_0,a_1,\cdots,a_{n-1}\) is a pair of indices \(0 ...
-
Codeforces Round #301 (Div. 2) E . Infinite Inversions 树状数组求逆序数
E. Infinite Inversions ...
-
Inversions After Shuffle
Inversions After Shuffle time limit per test 1 second memory limit per test 256 megabytes input stan ...
-
《算法导论》Problem 2-4 Inversions
在Merge Sort的基础上改改就好了. public class Inversions { public static int inversions(int [] A,int p, int r) ...
-
Dynamic Inversions II 逆序数的性质 树状数组求逆序数
Dynamic Inversions II Time Limit: 6000/3000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Other ...
-
Dynamic Inversions 50个树状数组
Dynamic Inversions Time Limit: 30000/15000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others ...
-
[Swift]LeetCode775. 全局倒置与局部倒置 | Global and Local Inversions
We have some permutation Aof [0, 1, ..., N - 1], where N is the length of A. The number of (global) ...
-
[LeetCode] Global and Local Inversions 全局与局部的倒置
We have some permutation A of [0, 1, ..., N - 1], where N is the length of A. The number of (global) ...
-
775. Global and Local Inversions
We have some permutation A of [0, 1, ..., N - 1], where N is the length of A. The number of (global) ...
-
775. Global and Local Inversions局部取反和全局取反
[抄题]: We have some permutation A of [0, 1, ..., N - 1], where N is the length of A. The number of (g ...
随机推荐
-
CSS基础知识真难啊
CSS层叠样式表Cascading Style Sheets CSS派生选择器(上下文选择器): 后代选择器:h1 strong {color:red;}第一个参数和第二个参数之间的代数是可以无限的 ...
-
kylin1.5新特性 new aggregation group
终于啃完并理解了,我果然弱鸡.new aggregation group,是kylin 1.5的新特性:老版本中的agg是需要选中所有可能被使用的纬度字段,以供查询:但存在高纬度的查询需求,例如查询某 ...
-
File的保存与读取
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io ...
-
Error when running Swift3 in REPL
Traceback (most recent call last): File "", line 1, in NameError: name 'run_one_line' is n ...
-
杭电ACM减花布条
这是原题的地址 http://acm.hdu.edu.cn/showproblem.php?pid=2087 Problem Description 一块花布条,里面有些图案,另有一块直接可用的小饰条 ...
-
Thrift安装问题
1.error: Bison version 2.5 or higher must be installed on the system! 哈哈,Bison版本低了吧,用下面的命令 wget ht ...
-
php连接到数据库操作
<?php $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { ?> 要写的内容代码,比如说Ht ...
-
Android Development HandBook-Android Studio 特别篇
开发准备中http://www.cnblogs.com/dev2007/p/4059829.html 主要介绍了基础环境的搭建,开发工具主要是Eclipse,由于Android Studio使用越来越 ...
-
loj2880「JOISC 2014 Day3」稻草人
题目链接:bzoj4237 loj2880 考虑\(cdq\)分治,按\(x\)坐标排序,于是问题变成统计左下角在\([l,mid]\),右上角在\([mid+1,r]\)的矩形数量 我们先考虑固 ...
-
Java内存泄漏相关
之前学习了javaGC的原理机制,有了一定的了解,现在做一个整理总结,便于理解记忆,包括三个问题: 1. java GC是什么时候做的? 2. java GC作用的东西是什么? 3. java GC具 ...