当前位置:网站首页>【集训DAY5】快速排序【模拟】【数学】
【集训DAY5】快速排序【模拟】【数学】
2022-08-09 22:35:00 【VL——MOESR】

思路:
我们直接倒着来判断就行了
#include<iostream>
#include<cstdio>
using namespace std;
const int MAXN = 50000;
int n, k;
int a[MAXN], ans[MAXN], id[MAXN];
int main() {
scanf("%d%d", &n, &k);
for(int i = 1; i <= k; i ++) scanf("%d", &a[i]);
for(int i = 1; i <= n; i ++) id[i] = i;
int l = 1, r = n, wh = 1;
for(int i = 1; i <= n; i ++) {
int x = a[(i - 1) % k + 1] % (n - i + 1) + l;
if(id[x] == wh) {
ans[id[x]] = l;
swap(id[x], id[l]);
l ++;
while(ans[wh]) wh ++;
}
else
{
ans[id[x]] = r;
swap(id[x], id[l]);
swap(id[l], id[r]);
r --;
}
}
for(int i = 1; i <= n; i ++) printf("%d\n", ans[i]);
return 0;
}
边栏推荐
- H5实现分享功能
- Force Buckle: 474. Ones and zeros
- 【Burning】It's time to show your true strength!Understand the technical highlights of the 2022 Huawei Developer Competition in one article
- 力扣:518. 零钱兑换 II
- Pytorch分布式训练/多卡训练DDP——模型初始化(torch.distribute 与 DDP的区别)
- shader学习笔记(五)
- Basic operations of xlrd and xlsxwriter
- LiveData : Transformations.map和 Transformations.switchMap用法
- [Cloud Native] This article explains how to add Tencent Crane to Kubevela addon
- How to know the computer boot record?
猜你喜欢

Redis集群

complete knapsack theory

How to match garbled characters regularly?

Gartner全球集成系统市场数据追踪,超融合市场增速第一

技术盛宴!华云数据携六大议题亮相OpenInfra Days China
![[Cloud Native] This article explains how to add Tencent Crane to Kubevela addon](/img/42/384caec048e02f01461292afc931be.jpg)
[Cloud Native] This article explains how to add Tencent Crane to Kubevela addon

【JZOF】32从上往下打印二叉树

Live Preview | ICML 2022 11 first-author scholars share online neural network, graph learning and other cutting-edge research

一体化伺服电机在三轴钻孔机中的应用

《GB5084-2021》PDF下载
随机推荐
Interfering with BGP routing---community attributes
MVC与MVVM模式的区别
力扣:474.一和零
kubesphere
2022-08-09 mysql/stonedb-子查询性能提升-概论
Gartner's global integrated system market data tracking, hyperconverged market growth rate is the first
国内十大活跃报表 BI 产品深度对比及点评
YGG 经理人杯总决赛已圆满结束,来看看这份文字版总结!
完全背包理论
金仓数据库 KingbaseGIS 使用手册(6.4. 几何对象存取函数)
Redis集群
2021年国内外五大BI厂商——优秀的商业智能工具推荐
MQTT X Web:在线的 MQTT 5.0 客户端工具
基于 RocksDB 实现高可靠、低时延的 MQTT 数据持久化
全球不用交税的国家,为什么不交
直播间搭建,按钮左滑出现删除等操作按钮
HStreamDB v0.9 发布:分区模型扩展,支持与外部系统集成
集合运算样例
Has your phone ever been monitored?
【诗歌】枕上诗书