HDU 5775 Bubble Sort
对于一个数,可以记录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的更多相关文章
- HDU 5775 Bubble Sort(冒泡排序)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 5775 Bubble Sort (线段树)
Bubble Sort 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5775 Description P is a permutation of t ...
- hdu 5775 Bubble Sort 树状数组
Bubble Sort 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5775 Description P is a permutation of t ...
- 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 ...
- 【归并排序】【逆序数】HDU 5775 Bubble Sort
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5775 题目大意: 冒泡排序的规则如下,一开始给定1~n的一个排列,求每个数字在排序过程中出现的最远端 ...
- HDU 5775:Bubble Sort(树状数组)
http://acm.hdu.edu.cn/showproblem.php?pid=5775 Bubble Sort Problem Description P is a permutation ...
- Bubble Sort (5775)
Bubble Sort Problem Description P is a permutation of the integers from 1 to N(index starting from ...
- Java中的经典算法之冒泡排序(Bubble Sort)
Java中的经典算法之冒泡排序(Bubble Sort) 神话丿小王子的博客主页 原理:比较两个相邻的元素,将值大的元素交换至右端. 思路:依次比较相邻的两个数,将小数放在前面,大数放在后面.即在第一 ...
- Bubble Sort [ASM-MIPS]
# Program: Bubble sort # Language: MIPS Assembly (32-bit) # Arguments: 5 unordered numbers stored in ...
随机推荐
- win7安装omnetpp-4.6
最近做毕设要用omnet仿真系统,就试着在win7上装了一下,分享一下经验咯.因为lz经常刷机,所以安装过程都是从头再来的,费话不多说.下面是安装过程: (1) 安装jdk,我就百度一下,然后找 ...
- 关于Windows Boot Manager、Bootmgfw.efi、Bootx64.efi、bcdboot.exe 的详解
1. http://bbs.wuyou.com/forum.php?mod=viewthread&tid=303679&fromuid=396698
- perl-Thread-Queue for openwrt
在centos7下运行 openwrt trunk的时候提示需要perl-thread-queue. yum install perl-thread-queue,提示没有这个文件.百度和google, ...
- cuckoo相关
Q1:pefile is out of date 现象:ERROR: Your version of pefile is out of date. Please update to the late ...
- (转载)#include机制,#ifndef...#define...#endif防止重复引用,声明,定义等概念
一.来自百度知道的问题:全局变量可以声明定义在头文件中? 答案: 注意头文件中不可以放变量的定义!!!一般情况下头文件中只放变量的声明,因为头文件要被其他文件包含(即#include).如果把定义放到 ...
- 浅谈angularJS指令的属性
restrict – 这个属性用来指定指令在HTML中如何使用(指令的四种表示方式).我们使用 ‘AE’,这个指令可以被当作新的HTML元素或者属性来使用.如果要允许指令被当作class来使用,我们将 ...
- Oracle中 union 和 union all 的区别
如果我们需要将两个select语句的结果作为一个整体显示出来,我们就需要用到union或者union all关键字. union(或称为联合)的作用是将多个结果合并在一起显示出来. union和uni ...
- Xcode-之Alcatraz
一.说明: Alcatraz 是一款 Xcode的插件管理工具,可以用来管理XCode的 插件.模版以及颜色配置的工具. 二.安装 1.github地址:https://github.com/alca ...
- 淘淘商城_day01_课堂笔记
今日大纲 聊聊电商行业 电商行业发展 11.11 2015双11: 2016年: 预测:2017年的双11交易额将达到:1400亿 电商行业技术特点 淘淘商城简介 淘淘商城的前身 电商行业的概念 B2 ...
- 第一百一十二节,JavaScript浏览器检测
JavaScript浏览器检测 学习要点: 1.navigator对象 2.客户端检测 由于每个浏览器都具有自己独到的扩展,所以在开发阶段来判断浏览器是一个非常重要的步骤.虽然浏览器开发商在公共接口方 ...