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 ...
随机推荐
- Aa3.0 事件机制
说明:本文由多处网络文章整理而成,在此未一一注明原文链接,敬请谅解! AS3:事件流机制 事件流 只要发生事件,Flash Player就会调度该事件对象. 如果事件目标不在显示列表中,则Flash ...
- 清除HTML标记
public static string DropHTML(string Htmlstring) { if (string.IsNullOrEmpty(Htmlst ...
- 如何在IIS6,7中部署ASP.NET网站(转载)
查看web.config文件 web.config通常会放在网站的根目录,这个文件中包含了一最重要的网站运行参数.比如: connectionStrings,httpHandlers,httpModu ...
- 12c windows auto installl
--config for oralce_envset ORACLE_HOME=c:\app\oracle\product\12.1.0\dbhome_1set ORACLE_SID=testuatse ...
- 微信超时5s,调用客服接口异步回复消息(PHP)
当用户触发事件,如果不能保证在5s内响应,可以先返回success,然后异步调用返回的信息.代码如下: // 立即返回(异步执行) ignore_user_abort(true);//start=== ...
- LWP::UserAgent介绍3 -> cookie设置
use LWP::UserAgent; use HTTP::Cookies; my $ua = LWP::UserAgent->new; $ua->cookie_jar(HTTP::Coo ...
- overthewire朝花夕拾
bandit: cat特殊字符文件名 - cat ./- 空格 cat "abc def" or cat abc\ def 列出隐藏文件:ll du -ab 递归列出文件大小,以 ...
- 快捷高效的cmd命令
经常在网上逛一些博客看一些技术文章,但是每每看过之后又忘记保存,或者东存一下,西存一下,到需要的时候回过头来,往往都找不到了.所以开通这个博客,把看到的好东西都记录下来,以便回头查看,也能与大家分享分 ...
- LSM树由来、设计思想以及应用到HBase的索引(转)
转自: http://www.cnblogs.com/yanghuahui/p/3483754.html 讲LSM树之前,需要提下三种基本的存储引擎,这样才能清楚LSM树的由来: 哈希存储引擎 是哈 ...
- UEditor+七牛,实现图片直连上传
最近做的项目,涉及到使用富文本编辑器,我选择了百度的UEditor.同时,我们的图片放在七牛云存储上.关于这两者间的集成,我写下一些个人的经验,与大家分享. 图片上传方案 目前来说,Web端基于七牛等 ...