题意:求逆序数

和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. SQLSERVER 链接服务器

    1. 执行代码 EXEC sp_addlinkedserver @server='XLZFSqlServer', --链接服务器别名 @srvproduct='', @provider='SQLOLE ...

  2. SQL Server-聚焦聚集索引对非聚集索引的影响

      前言 在学习SQL 2012基础教程过程中会时不时穿插其他内容来进行讲解,相信看过SQL Server 2012 T-SQL基础教程的童鞋知道前面写的所有内容并非都是摘抄书上内容,如若是这样那将没 ...

  3. LeetCode(96)Unique Binary Search Trees

    题目如下: Python代码: def numTrees(self, n): """ :type n: int :rtype: int """ ...

  4. Dynamic programming language

    动态改变运行时结构 Dynamic programming language, in computer science, is a class of high-level programming la ...

  5. 第六章 Python之迭代器与生成器

    迭代器 迭代:迭代是一个重复的过程,每次重复即一次迭代,并且每次迭代的结果是下一次重复的初始值 l=['a','b','c'] count=0 while count < len(l): pri ...

  6. [置顶] openHAB 体系结构与编程模型 (2) --- Web Application Servlet 源码结构

    || || || || || || demo.items Group All Group gGF (All) Group gFF (All) Group gC (All) Group Outdoor ...

  7. # quill-image-extend-module :实现vue-quill-editor图片上传,复制粘贴,拖拽

    改造vue-quill-editor: 结合element-ui上传图片到服务器 quill-image-extend-module vue-quill-editor的增强模块, 功能: 提供图片上传 ...

  8. vue无缝滚动的插件开发填坑分享

    写插件的初衷 1.项目经常需要无缝滚动效果,当时写jq的时候用用msClass这个老插件,相对不上很好用. 2.后来转向vue在vue-awesome没有找到好的无缝滚动插件,除了配置swiper可以 ...

  9. Django - 表与ORM操作

    Django - 表与ORM操作 一. 模板语言 模板中也有自己的语言, 该语言可以实现数据展示 - {{ 变量 }} - 循环 {% for i in all_publisher %} {{ for ...

  10. 《你又怎么了我错了行了吧团队》第七次作业:团队项目完善&编码

    <你又怎么了我错了行了吧团队>第七次作业:团队项目完善&编码 项目 内容 这个作业属于哪个课程 软件工程 这个作业的要求在哪里 实验十一 团队名称 你又怎么了我错了行了吧 作业学习 ...