多校4 5775 Bubble Sort

本文探讨了冒泡排序过程中每个元素从初始位置到最终排序位置的变化情况,通过使用树状数组记录并计算每个元素到达最左端和最右端位置的差值。



Bubble Sort

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 963    Accepted Submission(s): 568


Problem Description
P is a permutation of the integers from 1 to N(index starting from 1).
Here is the code of Bubble Sort in C++.
for(int i=1;i<=N;++i)
    for(int j=N,t;j>i;—j)
        if(P[j-1] > P[j])
            t=P[j],P[j]=P[j-1],P[j-1]=t;

After the sort, the array is in increasing order. ?? wants to know the absolute values of difference of rightmost place and leftmost place for every number it reached.
 

Input
The first line of the input gives the number of test cases T; T test cases follow.
Each consists of one line with one integer N, followed by another line with a permutation of the integers from 1 to N, inclusive.

limits
T <= 20
1 <= N <= 100000
N is larger than 10000 in only one case.
 

Output
For each test case output “Case #x: y1 y2 … yN” (without quotes), where x is the test case number (starting from 1), and yi is the difference of rightmost place and leftmost place of number i.
 

Sample Input
2 3 3 1 2 3 1 2 3
 

Sample Output
Case #1: 1 1 2 Case #2: 0 0 0
Hint
In first case, (3, 1, 2) -> (3, 1, 2) -> (1, 3, 2) -> (1, 2, 3) the leftmost place and rightmost place of 1 is 1 and 2, 2 is 2 and 3, 3 is 1 and 3 In second case, the array has already in increasing order. So the answer of every number is 0.
 



题意:问排序过程中,每个元素到达最左端和最右端位置的差。

思路:查询树状数组。每次加进去一个元素,就差一下他前面有几个,这样就知道之前比他小的有几个,减一下就是后面比他小的,也就是他需要右偏的次数即最右端,最左端可能是他最初的位置也可能是他应该在的位置。

代码:

#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <set>
 
using namespace std;

int P[100000 + 10],ans[100000 + 10];
long long sum[100000 + 10];
long long pm[100000 + 10];

int lowbit(int x)
{
    return x&-x;
}
long long premin(int x)
{
     long long s = 0;
     while(x)
     {
             s += sum[x];
             x -= lowbit(x);
     }
     return s;
} 
int main()
{
    int t;
    scanf("%d",&t);
    int cas = t;
    while(t--)
    {
         int n;
         scanf("%d",&n);
         memset(sum,0,sizeof sum);
         for(int i = 1; i <= n; i++)
         {
                 scanf("%d",&P[i]);
                 ans[P[i]] = i;          //记录每个元素最初的位置
                 int temp = P[i];
                 while(temp <= n)
                 {
                       sum[temp] += 1;
                       temp += lowbit(temp);        //向后更新
                 }
                 pm[P[i]] = premin(P[i]);             //算他之前的和即原位置前面比他小的元素的个数
         }
         printf("Case #%d:",cas-t);
         for(int i = 1; i <= n; i++)
              printf(" %d",ans[i]+(i-pm[i])-min(ans[i],i)); 
         printf("\n");
    }
    return 0;
}


胚胎实例分割数据集 一、基础信息 • 数据集名称:胚胎实例分割数据集 • 图片数量: 训练集:219张图片 验证集:49张图片 测试集:58张图片 总计:326张图片 • 训练集:219张图片 • 验证集:49张图片 • 测试集:58张图片 • 总计:326张图片 • 分类类别: 胚胎(embryo):表示生物胚胎结构,适用于发育生物学研究。 • 胚胎(embryo):表示生物胚胎结构,适用于发育生物学研究。 • 标注格式:YOLO格式,包含实例分割的边形标注,适用于实例分割任务。 • 数据格式:图片来源于相关研究领域,格式为常见图像格式,细节清晰。 二、适用场景 • 胚胎发育AI分析系统:构建能够自动分割胚胎实例的AI模型,用于生物学研究中的形态变化追踪和量化分析。 • 医学与生物研究:在生殖医学、遗传学等领域,辅助研究人员进行胚胎结构识别、分割和发育阶段评估。 • 学术与创新研究:支持计算机视觉与生物医学的交叉学科研究,推动AI在胚胎学中的应用,助力高水平论文发表。 • 教育与实践培训:用于高或研究机构的实验教学,帮助学生和从业者掌握实例分割技术及胚胎学知识。 三、数据集优势 • 精准与专业性:实例分割标注由领域专家完成,确保胚胎轮廓的精确性,提升模型训练的可靠性。 • 任务专用性:专注于胚胎实例分割,填补相关领域数据空白,适用于细粒度视觉分析。 • 格式兼容性:采用YOLO标注格式,易于集成到主流深度学习框架中,简化模型开发与部署流程。 • 科学价值突出:为胚胎发育研究、生命科学创新提供关键数据资源,促进AI在生物学中的实际应用。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值