一、离散化:

https://www.cnblogs.com/2018zxy/p/10104393.html

二、逆序数

AC代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = ;
struct Node{
LL data;
int val;
}cur[maxn];
LL a[maxn];
bool cmp(Node A,Node B)
{
return A.data<B.data;
}
int lowbit(int x)
{
return x&(-x);
}
void update(int x)
{
while(x<maxn-)
{
a[x]++;
x+=lowbit(x);
}
}
int sum(int x)
{
int ans=;
while(x>)
{
ans+=a[x];
x-=lowbit(x);
}
return ans;
}
int main(void)
{
int n,i;
while(~scanf("%d",&n)&&n)
{
memset(a,,sizeof(a));
for(i=;i<=n;i++)
{
scanf("%lld",&cur[i].data);cur[i].val=i;
}
sort(cur+,cur++n,cmp);
LL ans=;
for(i=;i<=n;i++)
{
update(cur[i].val);
ans+=i-sum(cur[i].val);
}
printf("%lld\n",ans);
}
return ;
}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = ;
struct Node{
LL data;
int val;
}cur[maxn];
LL a[maxn];
bool cmp(Node A,Node B)
{
return A.data<B.data;
}
int lowbit(int x)
{
return x&(-x);
}
void update(int x)
{
while(x<maxn-)
{
a[x]++;
x+=lowbit(x);
}
}
int sum(int x)
{
int ans=;
while(x>)
{
ans+=a[x];
x-=lowbit(x);
}
return ans;
}
int main(void)
{
int n,i;
while(~scanf("%d",&n)&&n)
{
memset(a,,sizeof(a));
for(i=;i<=n;i++)
{
scanf("%lld",&cur[i].data);cur[i].val=i;
}
sort(cur+,cur++n,cmp);
LL ans=;
for(i=n;i>=;i--)
{
ans+=sum(cur[i].val);
update(cur[i].val);
}
printf("%lld\n",ans);
}
return ;
}

poj--2299(树状数组+离散化)的更多相关文章

  1. POJ 2299 树状数组+离散化求逆序对

    给出一个序列 相邻的两个数可以进行交换 问最少交换多少次可以让他变成递增序列 每个数都是独一无二的 其实就是问冒泡往后 最多多少次 但是按普通冒泡记录次数一定会超时 冒泡记录次数的本质是每个数的逆序数 ...

  2. Ultra-QuickSort (POJ 2299)树状数组+离散化

    题目链接 Description In this problem, you have to analyze a particular sorting algorithm. The algorithm ...

  3. poj 2299 树状数组求逆序数+离散化

    http://poj.org/problem?id=2299 最初做离散化的时候没太确定可是写完发现对的---由于后缀数组学的时候,,这样的思维习惯了吧 1.初始化as[i]=i:对as数组依照num ...

  4. poj 2299 树状数组求逆序对数+离散化

    Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 54883   Accepted: 20184 ...

  5. POJ 2299树状数组求逆序对

    求逆序对最常用的方法就是树状数组了,确实,树状数组是非常优秀的一种算法.在做POJ2299时,接触到了这个算法,理解起来还是有一定难度的,那么下面我就总结一下思路: 首先:因为题目中a[i]可以到99 ...

  6. Ultra-QuickSort POJ - 2299 树状数组求逆序对

    In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a seque ...

  7. POJ 2299 【树状数组 离散化】

    题目链接:POJ 2299 Ultra-QuickSort Description In this problem, you have to analyze a particular sorting ...

  8. hdu4605 树状数组+离散化+dfs

    Magic Ball Game Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  9. BZOJ_5055_膜法师_树状数组+离散化

    BZOJ_5055_膜法师_树状数组+离散化 Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然 ...

  10. POJ 2299 Ultra-QuickSort(树状数组+离散化)

    http://poj.org/problem?id=2299 题意:给出一组数,求逆序对. 思路: 这道题可以用树状数组解决,但是在此之前,需要对数据进行一下预处理. 这道题目的数据可以大到999,9 ...

随机推荐

  1. 关于后台执行JS代码总结

    方法一.FineUI的 pagecontext对象 string js="functionName();"; PageContext.RegisterStartUpScript(j ...

  2. Watcher、ZK状态、事件类型 ,权限

    zookeeper有watch事件,是一次性触发的,当watch监视的数据发生变化时,通知设置了该watch的client,即watcher. 同样,其watcher是监听数据发送了某些变化,那就一定 ...

  3. 专项测试——移动app安装包检测

    一.背景和现状 安装包的重要性无需多提,针对安装包质量控制越来越严格和规范,包括证书.文件大小.安装成功率等,APP的证书及混淆是影响APP的安装成功率及代码安全性的很大因素,随着功能迭代,安装包也会 ...

  4. 802.1X技术介绍

    1.802.1X IEEE802 LAN/WAN委员会为解决无线局域网网络安全问题,提出了802.1X协议.后来,802.1X协议作为局域网端口的一个普通接入控制机制在以太网中被广泛应用,主要解决以太 ...

  5. 利用xlrd模块读取excel利用json模块生成相应的json文件的脚本

    excel的格式如下 python代码如下,这里最难的就是合并单元格的处理 import xlrd import json excel_obj = xlrd.open_workbook("t ...

  6. 解决自定义classloader后无法使用maven install

    @上篇博客中探讨了web项目利用自定义classloader进行解密,利用的是编译后的文件直接运行程序一切正常 今天博主在探讨加密后进行混淆时,打包程序报程序包org.apache.catalina. ...

  7. Python数据分析--Pandas知识点(一)

    本文主要是总结学习pandas过程中用到的函数和方法, 在此记录, 防止遗忘 1. 重复值的处理 利用drop_duplicates()函数删除数据表中重复多余的记录, 比如删除重复多余的ID. im ...

  8. 字符串加u的特殊需求

    #coding:utf-8 L = ['a','b','c'] S = [] for i in L: tmp = str(i).decode('utf-8') S.append(tmp) print ...

  9. c#devexpres TreeList 最简单显示动态值的应用

    为了让数据显示在行内,也为熟练一下devexpress treelist  控件, 查找了很多,最多的是先把数据放在datatable  表里边, 然后赋值给treelist的datasource 的 ...

  10. 团队合作之项目NABCD

    小组组长 :毛松林 组员  :张浩,谢诗语 N 我们小组要开发的项目是“高校自习室查询APP”,作为一个大学生,自学是一件很重要的能力,大学的老师不可能还像高中的老师那样整天逼着你学习,爱学不学,不学 ...