题意:求逆序数

和POJ那题求逆序数的一样,不过这题离散化之后,要去一下重,然后要开到long long

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int a[maxn];
int c[maxn];//树状数组 struct node{
int x;
int id;
} p[maxn]; int cmp(node n1,node n2){
return n1.x < n2.x;
} int lowbit(int x){ return x &(-x);} __int64 sum(int x){
__int64 ret=;
while(x > ){
ret+=c[x];x-=lowbit(x);
}
return ret;
} void add(int x,int d){
while(x < maxn){
c[x]+=d;x+=lowbit(x);
}
} int main(){
int n;
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&p[i].x),p[i].id=i;
sort(p+,p+n+,cmp); for(int i=,j=;i<=n;i++){
if(i== || p[i].x != p[i-].x) j++;
a[p[i].id] = j;
} memset(c,,sizeof(c));
__int64 ans=;
for(int i=;i <=n;i++ ) {
add(a[i],);
ans += i - sum(a[i]);
}
printf("%I64d\n",ans);
return ;
}

SGU 180 Inversions【树状数组】的更多相关文章

  1. HDU5196--DZY Loves Inversions 树状数组 逆序数

    题意查询给定[L, R]区间内 逆序对数 ==k的子区间的个数. 我们只需要求出 子区间小于等于k的个数和小于等于k-1的个数,然后相减就得出答案了. 对于i(1≤i≤n),我们计算ri表示[i,ri ...

  2. Codeforces Round #301 (Div. 2) E . Infinite Inversions 树状数组求逆序数

                                                                    E. Infinite Inversions               ...

  3. Infinite Inversions(树状数组+离散化)

    思路及代码参考:https://blog.csdn.net/u014800748/article/details/45420085 There is an infinite sequence cons ...

  4. SGU180:Inversions(树状数组)

    There are N integers (1<=N<=65537) A1, A2,.. AN (0<=Ai<=10^9). You need to find amount o ...

  5. 逆序对__归并排序__树状数组 Inversions SGU - 180

    There are N integers (1<=N<=65537) A1, A2,.. AN (0<=Ai<=10^9). You need to find amount o ...

  6. SGU 180 Inversions(离散化 + 线段树求逆序对)

    题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=180 解题报告:一个裸的求逆序对的题,离散化+线段树,也可以用离散化+树状数组.因为 ...

  7. Dynamic Inversions 50个树状数组

    Dynamic Inversions Time Limit: 30000/15000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others ...

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

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

  9. CF #301 E:Infinite Inversions(逆序数,树状数组)

    A-Combination Lock  B-School Marks   C-Ice Cave   D-Bad Luck Island   E-Infinite Inversions E:Infini ...

随机推荐

  1. 基于任务的编程模型TAP

    一.引言 在上两个专题中我为大家介绍.NET 1.0中的APM和.NET 2.0中的EAP,在使用前面两种模式进行异步编程的时候,大家多多少少肯定会感觉到实现起来比较麻烦, 首先我个人觉得,当使用AP ...

  2. Oracle学习系类篇(二)

    1.Oracle对表的增删改 1.1添加列 1.2修改列 1.3 删除列 1.4 修改表名称 1.5 修改列名称 1.6 删除主键约束 1.7 添加主键约束 1.8 添加外键约束

  3. 用过的jQuery记录

    var list= $('input:radio[name="name"]:checked').val(); //选择input中单选name为“name”的并且是选中状态的 in ...

  4. Oracle安装后命令行中运行sqlplus / as sysdba出现错误ora-01031:insufficient privileges

    Win10安装Oracle后命令行中运行sqlplus as sysdba出现错误ora-01031insufficient privileges的解决方法 情景描述 错误样例 错误分析 解决方法 情 ...

  5. HDU 2303 The Embarrassed Cryptographer

    The Embarrassed Cryptographer 题意 给一个两个素数乘积(1e100)K, 给以个数L(1e6), 判断K的两个素数是不是都大于L 题解 对于这么大的范围,素数肯定是要打表 ...

  6. mac上virtualbox创建vm需要注意启动顺序

    创建好vm后,需要注意,按照下图,将vm的启动顺序设置成 硬盘,不然,你会一直处于安装的逻辑中

  7. Element源码阅读(2)

    一.element中的指令 在input-number组件中, 用到一个v-repeat-click指令, 主要用于input-number组件的重复点击效果.具体实现在directives中的rep ...

  8. ansible 连通测试

    [root@ftp:/root] > ansible ansible01 -m ping ansible01 | UNREACHABLE! => { "changed" ...

  9. 小试牛刀之sort()排序的实现

    受大学室友的鼓动,我也打算利用公众平台来记录自己的前端知识积累,同时呢,自己总结的东西,总归会有局限性,希望小伙伴能给我指点迷津.知识就是一张巨大的网,作为一名摸不清头绪的入学者,唯一能做的事情就是吐 ...

  10. WinServer-服务器管理器-从入门到放弃

    WIN7 远程服务器管理工具 看看这篇帖子,他们说可以在WIN7上通过服务器管理工具来管理服务器上的软件 https://social.technet.microsoft.com/Forums/zh- ...