对于一个数,可以记录3个位置:初始位置,终点位置,最右边的位置。

初始位置和终点位置容易计算。最多边的位置即为初始状态下该数的位置+该数之后还有多少数比该数小。

三个位置中的min即为leftpos,max即为rightpos

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
char c = getchar(); while(!isdigit(c)) c = getchar();
int x = ;
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} const int maxn=+;
int n,a[maxn],c[maxn],p[maxn],L[maxn],R[maxn]; int lowbit(int x) { return x&(-x); }
void update(int x) { while(x<=n) c[x]+=,x+=lowbit(x); }
int get(int x) {int res=; while(x) res=res+c[x],x-=lowbit(x); return res;} int main()
{
int T; scanf("%d",&T); int cas=;
while(T--)
{
scanf("%d",&n); memset(c,,sizeof c);
for(int i=;i<=n;i++)
scanf("%d",&a[i]),L[a[i]]=min(i,a[i]),R[a[i]]=max(i,a[i]);
for(int i=;i<=n;i++)
{
int x=get(a[i]-); x=a[i]--x; update(a[i]);
L[a[i]]=min(L[a[i]],i+x), R[a[i]]=max(R[a[i]],i+x);
} printf("Case #%d:",cas++);
for(int i=;i<=n;i++) printf(" %d",abs(L[i]-R[i]));
printf("\n");
}
return ;
}

HDU 5775 Bubble Sort的更多相关文章

  1. HDU 5775 Bubble Sort(冒泡排序)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  2. HDU 5775 Bubble Sort (线段树)

    Bubble Sort 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5775 Description P is a permutation of t ...

  3. hdu 5775 Bubble Sort 树状数组

    Bubble Sort 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5775 Description P is a permutation of t ...

  4. HDU 5775 Bubble Sort(线段树)(2016 Multi-University Training Contest 4 1012)

    原址地址:http://ibupu.link/?id=31 Problem Description P is a permutation of the integers from 1 to N(ind ...

  5. 【归并排序】【逆序数】HDU 5775 Bubble Sort

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5775 题目大意: 冒泡排序的规则如下,一开始给定1~n的一个排列,求每个数字在排序过程中出现的最远端 ...

  6. HDU 5775:Bubble Sort(树状数组)

    http://acm.hdu.edu.cn/showproblem.php?pid=5775 Bubble Sort Problem Description   P is a permutation ...

  7. Bubble Sort (5775)

    Bubble Sort Problem Description   P is a permutation of the integers from 1 to N(index starting from ...

  8. Java中的经典算法之冒泡排序(Bubble Sort)

    Java中的经典算法之冒泡排序(Bubble Sort) 神话丿小王子的博客主页 原理:比较两个相邻的元素,将值大的元素交换至右端. 思路:依次比较相邻的两个数,将小数放在前面,大数放在后面.即在第一 ...

  9. Bubble Sort [ASM-MIPS]

    # Program: Bubble sort # Language: MIPS Assembly (32-bit) # Arguments: 5 unordered numbers stored in ...

随机推荐

  1. 各种ps特效的网址

    粉笔字效果:http://www.jb51.net/photoshop/280740.html

  2. IIS 7如何实现http重定向https

    转自[http://blog.csdn.net/xuhuojun/article/details/6137154] 在不少的企业当中,网站设计出于安全的考虑使用了https协议,但同时公司也开放了80 ...

  3. iOS上传AppStore被拒原因及处理方案

    1.后台运行GPS 1.1 原文: Performance - 2.5.4 Your app declares support for location in the UIBackgroundMode ...

  4. date格式化

    Linux: [ghsea@localhost ~]date +%Y:%m:%d [ghsea@localhost ~]date +%Y-%m%d [ghsea@localhost ~]date +% ...

  5. HSDFS fs命令

    fs命令 -help [cmd]  //显示命令的帮助信息 -ls(r) <path>  //显示当前目录下所有文件 -du(s) <path>  //显示目录中所有文件大小 ...

  6. Asp.Net MVC2.0 Url 路由入门---实例篇

    本篇主要讲述Routing组件的作用,以及举几个实例来学习Asp.Net MVC2.0 Url路由技术. 接着上一篇开始讲,我们在Global.asax中注册一条路由后,我们的请求是怎么转到相应的Vi ...

  7. Struts2 stracture

  8. WPF关于“在“System.Windows.Markup.StaticResourceHolder”上提供值时引发了异常。”问题解决办法

    在WPF中添加样式,在MainWindow.xaml使用自定义按钮FButton时报错,报错信息如下: "System.Windows.Markup.XamlParseException&q ...

  9. z-index研究

    文章来源: http://www.neoease.com/css-z-index-property-and-layering-tree/ 总结: 1.z-index只有在设置position:rela ...

  10. ajax格式,需要指定交互的data类型

    思路 先打印所有返回值 console.log(d);  {''status'':999} 再查看返回值,能否转换为json dataType:'json',    //大小写敏感. datatype ...