当前位置:网站首页>【集训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;
}
边栏推荐
猜你喜欢
多商户商城系统功能拆解25讲-平台端分销申请
为什么刀具数据库无法打开?
如何知道电脑开机记录?
2022-08-09 mysql/stonedb-子查询性能提升-概论
Live Preview | ICML 2022 11 first-author scholars share online neural network, graph learning and other cutting-edge research
金仓数据库 KingbaseGIS 使用手册(6.3. 几何对象创建函数)
伦敦银行情中短线的支撑和阻力位
2022-08-09 mysql/stonedb-subquery performance improvement-introduction
2022-08-09 mysql/stonedb-慢SQL-Q16分析
iNFTnews | 迪士尼如何布局Web3
随机推荐
Mysql/stonedb - slow SQL - 2022-08-09 Q16 analysis
Leetcode 701. 二叉搜索树中的插入操作
【诗歌】枕上诗书
LiveData : Transformations.map and Transformations.switchMap usage
[Interface Test] Decoding the request body string of the requests library
杭电多校-Counting Stickmen-(思维+组合数+容斥)
Filament - Material basic graphics drawing
[Cloud Native] This article explains how to add Tencent Crane to Kubevela addon
【哲理】事教人
ALV报表总结2022.8.9
【诗歌】最高级的惩罚就是沉默
Live Preview | ICML 2022 11 first-author scholars share online neural network, graph learning and other cutting-edge research
iNFTnews | 迪士尼如何布局Web3
直播间搭建,按钮左滑出现删除等操作按钮
测试2年,当时身边一起入行的朋友已经月薪20k了,自己还没过万,到底差在了哪里?
H5实现分享功能
联盟链技术应用的难点
打包报错 AAPT: error: failed to read PNG signature: file does not start with PNG signature.
首席信息官如何将可持续性和技术结合起来
tiup cluster scale-out