题解:AT_abc013_4 [ABC013D] 阿弥陀
smart_stupid · · 题解
某天闲逛 B 站时看到了疑似用户整活的 AtCoder PV,里面的题我找到了原题。
我觉得这个视频帅爆了,然后就写了宣传片中的题。
思路
我们把
首先,用
现在有了一个循环节的
AC CODE:
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
typedef long double ld;
using namespace std;
int n, m, d, a[200100];
vector<int> p, ans; // 该数组记录单个循环节第 i 列的答案
vector<int> mul(vector<int> &a, vector<int> &b) { // 单次乘法
vector<int> c;
for (auto i : a) {
c.push_back(b[i]);
}
return c;
}
void fpow(ll x) { // 快速幂
for (int i = 0; i <= n; i++) ans.push_back(i);
while (x) {
if (x & 1) {
ans = mul(ans, p);
}
p = mul(p, p), x >>= 1;
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m >> d;
for (int i = 1; i <= m; i++) {
cin >> a[i];
}
for (int i = 0; i <= n; i++) {
p.push_back(i);
}
for (int i = m; i >= 1; i--) {
swap(p[a[i]], p[a[i] + 1]);
}
fpow(d);
for (int i = 1; i <= n; i++) {
cout << ans[i] << '\n';
}
return 0;
}