当前位置:网站首页>【集训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;
}
边栏推荐
- 金仓数据库 KingbaseGIS 使用手册(6.4. 几何对象存取函数)
- 力扣:377. 组合总和 Ⅳ
- 68. qt quick-qml multi-level folding drop-down navigation menu supports dynamic add/unload, support qml/widget loading, etc.
- 力扣:518. 零钱兑换 II
- tiup cluster upgrade
- 【JZOF】82二叉树中和为某一值的路径(一)
- SRv6性能测量
- 首席信息官如何将可持续性和技术结合起来
- 恭喜获奖得主 | 互动有礼获赠 Navicat Premium
- complete knapsack theory
猜你喜欢

完全背包理论

五分钟商学院(基础---商业篇)

How to know the computer boot record?

金仓数据库 KingbaseGIS 使用手册(6.5. 几何对象编辑函数)

Mysql/stonedb - slow SQL - 2022-08-09 Q16 analysis

恭喜获奖得主 | 互动有礼获赠 Navicat Premium

【实用工具系列】MathCAD入门安装及快速上手使用教程
![[Interface Test] Decoding the request body string of the requests library](/img/99/82ef792dacd398a8a62dd94f235a91.png)
[Interface Test] Decoding the request body string of the requests library

什么是平面文件数据库? 如何导入多种格式的文件:DSV、JSON、XML?

matplotlib散点图自定义坐标轴(文字坐标轴)
随机推荐
MQTT X Web:在线的 MQTT 5.0 客户端工具
LeetCode952三部曲之三:再次优化(122ms -> 96ms,超51% -> 超91%)
tiup cluster upgrade
杭电多校-Counting Stickmen-(思维+组合数+容斥)
【JZOF】77按之字形打印二叉树
少儿编程 电子学会图形化编程等级考试Scratch三级真题解析(判断题)2022年6月
Sqlserver限制账户在哪些ip下才可以访问数据库
tiup cluster template
Forbidden (CSRF token missing or incorrect.): /
【实用工具系列】MathCAD入门安装及快速上手使用教程
多线程是同时执行多个线程的吗
Gartner's global integrated system market data tracking, hyperconverged market growth rate is the first
How to know the computer boot record?
Click: 377. Combined Sum Ⅳ
tiup cluster scale-out
68.qt quick-qml多级折叠下拉导航菜单 支持动态添加/卸载 支持qml/widget加载等
【哲理】读书的意义
【JZOF】32从上往下打印二叉树
函数习题(下)
JS--popstate事件--使用/教程/实例