[nowcoder5668I]Sorting the Array

1 #include<bits/stdc++.h>
2 using namespace std;
3 #define N 800005
4 int t,n,m,x,a[N],b[N],id[N],vis[N],ans[N];
5 long long k;
6 int main(){
7 scanf("%d",&t);
8 while (t--){
9 scanf("%d%d%lld",&n,&m,&k);
10 int s=0,nn=0;
11 for(int i=1;i<=n;i++)ans[i]=0;
12 for(int i=1,j=1;i<=n;i++){
13 scanf("%d",&x);
14 if (s>x)ans[i+m-1]=x;
15 else{
16 s=a[++nn]=x;
17 while (ans[j])j++;
18 id[nn]=j++;
19 }
20 }
21 int las=nn;
22 long long sum=1;
23 while (sum<k){
24 las--;
25 sum*=min(nn-las+1,m);
26 }
27 for(int i=1;i<las;i++)ans[id[i]]=a[i];
28 for(int i=las;i<=nn;i++){
29 vis[i]=0;
30 b[i]=min(nn-i+1,m);
31 }
32 for(int i=las;i<=nn;i++)
33 for(int j=las;j<=nn;j++)
34 if (!vis[j]){
35 sum=sum/(b[j]--);
36 if (k<=sum){
37 vis[j]=1;
38 ans[id[i]]=a[j];
39 break;
40 }
41 k-=sum;
42 sum*=b[j];
43 }
44 for(int i=1;i<=n;i++)printf("%d ",ans[i]);
45 printf("\n");
46 }
47 }
[nowcoder5668I]Sorting the Array的更多相关文章
- Leetcode: Matchsticks to Square && Grammar: reverse an primative array
Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...
- Scala入门之Array
/** * 大数据技术是数据的集合以及对数据集合的操作技术的统称,具体来说: * 1,数据集合:会涉及数据的搜集.存储等,搜集会有很多技术,存储现在比较经典的是使用Hadoop,也有很多情况使用Kaf ...
- Majority Element in an Array
Problem Statement Given a large array of non-negative integer numbers, write a function which determ ...
- PHP 根据对象属性进行对象数组的排序(usort($your_data, "cmp");)(inside the class: usort($your_data, array($this, "cmp")))
PHP 根据对象属性进行对象数组的排序(usort($your_data, "cmp");)(inside the class: usort($your_data, array($ ...
- CSharpGL(36)通用的非托管数组排序方法
CSharpGL(36)通用的非托管数组排序方法 如果OpenGL要渲染半透明物体,一个方法是根据顶点到窗口的距离排序,按照从远到近的顺序依次渲染.所以本篇介绍对 UnmanagedArray< ...
- Thinking in Java——笔记(16)
Arrays Why arrays are special There are three issues that distinguish arrays from other types of con ...
- 小白科普之JavaScript的数组
一.与其他语言数据的比较 相同点:有序列表 不同点:js的数组的每一项可以保存任何类型的数据:数组的大小是可以动态调整的 二.数组创建的两种方法 1) var colors = new ...
- javaapi中的排序
有的时候需要对数组里的element进行排序.当然可以自己编写合适的排序方法,但既然java包里有自带的Arrays.sort排序方法,在 数组元素比较少的时候为何不用? Sorting an Arr ...
- Cheatsheet: 2013 09.01 ~ 09.09
.NET Multi Threaded WebScraping in CSharpDotNetTech .NET Asynchronous Patterns An Overview of Projec ...
随机推荐
- 编程模仿MySql客服端
写在前面 通过自己编写的Java代码程序,去模仿实现MySql客服端的简单功能,最终以控制台操作,很像在Dos窗口通过命令操作MySql数据库. 关键问题 在编写过程中遇到的一些小问题和一些值得留心注 ...
- pytest执行时mian函数传参
在代码中执行pytest可以通过main函数 加参数来指定运行规则时,参数需要放在列表或者元祖中 # pytest.main(["--html=report.html"]) # p ...
- GIS应用|快速开发REST数据服务
随着计算机的快速发展,GIS已经在各大领域得到应用,和我们的生活息息相关, 但是基于GIS几大厂商搭建服务,都会有一定的门槛,尤其是需要server,成本高,难度大,这里介绍一种在线GIS云平台,帮你 ...
- logging的基本使用
logging模块打印log的时候主要有一下几个,级别顺序:CRITICAL>ERROR>WARNING>INFO>DEBUG: 1.日志输出到file: import log ...
- programmercarl——数组——二分查找
二分查找,在经过: 34--https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-arr ...
- Shadertoy 教程 Part 1 - 介绍
Note: This series blog was translated from Nathan Vaughn's Shaders Language Tutorial and has been au ...
- 软件工程个人博客作业-软件案例分析:VS与VS Code
项目 内容 本作业属于北航 2020 年春软件工程 博客园班级连接 本作业是本课程个人项目作业 作业要求 我在这个课程的目标是 提高软件开发能力.团队协作能力 这个作业在哪个具体方面帮助我实现目标 提 ...
- Noip模拟77 2021.10.15
T1 最大或 $T1$因为没有开$1ll$右移给炸掉了,调了一年不知道为啥,最后实在不懂了 换成$pow$就过掉了,但是考场上这题耽误了太多时间,后面的题也就没办法好好打了.... 以后一定要注意右移 ...
- 字符串匹配 ?kmp : hash
给定一个模式串S,以及一个模板串P,所有字符串中只包含大小写英文字母以及阿拉伯数字. 模板串P在模式串S中多次作为子串出现. 求出模板串P在模式串S中所有出现的位置的起始下标. 输入格式 第一行输入整 ...
- centos 下安装docker
官方文档比较累赘,简化就三步 1.安装依赖 yum -y install gcc gcc-c++ yum-utils device-mapper-persistent-data lvm2 2.添加re ...