当前位置:网站首页>ARC110F Esoswap
ARC110F Esoswap
2022-07-22 04:24:00 【心怀凉月】
ARC110F Esoswap
由于 0 ∼ n − 1 0\sim n-1 0∼n−1 的特殊性,每次固定询问一个位置,询问 n n n 次一定会得到 0 0 0,且每次在这个位置上的数不会重复( 0 0 0 除外)。
于是考虑倒序将数固定,正序会出现问题。
然后把倒序排列转为正序排列。
具体地,先把 1 1 1 交换到位置 n − 1 n-1 n−1,然后将在 0 0 0 位置上的数与 1 1 1 交换,然后 1 1 1 一直往右移动到 n − 2 n-2 n−2,重复上面操作即可。
操作数 O ( n 2 ) \mathcal O(n ^2) O(n2)。
#include<cstdio>
//using namespace std;
typedef long long ll;
#define ha putchar(' ')
#define he putchar('\n')
inline int read() {
int x = 0;
char c = getchar();
while (c < '0' || c > '9')
c = getchar();
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return x;
}
inline void write(int x) {
if (x > 9)
write(x / 10);
putchar(x % 10 + 48);
}
void swap(int &a, int &b)
{
int t = a;
a = b, b = t;
}
const int _ = 107;
int n, a[_], id[_], as[200010];
void sol(int x) {
as[++as[0]] = x;
swap(id[a[x]], id[a[(x + a[x]) % n]]);
swap(a[x], a[(x + a[x]) % n]);
}
signed main() {
n = read();
for (int i = 0; i < n; ++i) a[i] = read(), id[a[i]] = i;
while (a[n - 1] != 0) sol(n - 1);
for (int i = n - 1; i >= 0; --i)
while (a[i] != n - 1 - i) sol(i);
sol(id[1]);
for(int i = n - 1; i > 1; --i)
{
sol(id[i]);
while(a[i - 1] != 1) sol(id[1]);
}
for (int i = 0; i <= as[0]; ++i) write(as[i]), he;
return 0;
}
边栏推荐
- Popular science | how to create a Dao?
- mysql中not like的简化写法
- SQL Server2008 database query admin password
- mysql通过开启全局日志进行定位排查慢sql
- A 15-year-old ABAP veteran's suggestion: understanding these basic knowledge is beneficial to ABAP development
- [SSM]SSM整合②(功能模块的开发)
- The LAAS solution of elephant swap has risen rapidly and built a new defi2.0 protocol
- Leetcode 234. 回文链表
- Android面试:2022请收好这份网易Android开发和抖音电商Android工程师的面经
- Purchase instructions for pull-up device and waist cushion
猜你喜欢
[ssm]ssm integration ② (development of functional modules)
The two supply chain centers of HEMA launched the "background" of innovative research and development of multi format commodities
screen命令使用
Classic books of Orthodontics
Vulkan official example interpretation subchannel
A few minutes before work, express quick start
MP query criteria
NFT exchange contract development tutorial (solidity & hardhat)
MP查询条件
Alternet scripting, user interface design function
随机推荐
MySQL starts the global log to locate and troubleshoot slow SQL
How does the red team play
计算机网络之DNS面试题
SQL Server2008 database query admin password
Android interview: 2022 please keep this experience of Netease Android development and Tiktok e-commerce Android engineers
[unity project practice] game architecture
C# 上传图片至共享文件夹
MP查询条件
Fastjson 代码执行 CVE-2022-25845
JVM memory model: classification and acquisition of class loaders
进程和线程面试问题
PXE network installation
【Leetcode周赛--哈希表数对】6164.数位和相等数对的最大和
嵌入式IDE原理 OpenOCD介绍 以及stlink如何连接stm32板子
图计算-图简介
学生如何提高专业英文阅读能力丨传道授业
Repair the problem of adding device groups and editing exceptions on easycvr platform
Diversified distribution methods of NFT
分布式调度问题
The LAAS solution of elephant swap has risen rapidly and built a new defi2.0 protocol