题目 这道题目我一开始是这么写的
#include <iostream>
#include <algorithm>
#include <cctype>
using namespace std;
#pragma GCC optimize(2)
const int N = 1e5+10;
long long n, m;
long long a[N], pos[N];
inline long long read(){
int f = 1;
long long x = 0;
char c = getchar();
while (!isdigit(c))
{
f = c == '-' ? -1 : 1;
c = getchar();
}
while (isdigit(c))//一边读入一边取模
{
x = ((x << 1) + (x << 3) + (c ^ 48)) % (n * (n - 1));
c = getchar();
}
return f * x;
}
int main(){
//输入
cin >> n;
m = read();
for (int i = 1;i <= n;i++) cin >> a[i];
//处理
int t = m / (n - 1), left = m % (n - 1);
if (t != 0)
{
for (int i = 1;i <= n;i++)//统计错位造成的影响
{
a[i] = (a[i] + t) % n ? (a[i] + t) % n : n;
}
}
for (int i = 1;i <= n;i++) pos[a[i]] = i;
for (int i = 1;i <= left;i++)//模拟
{
int p1 = n - (i - 1) % (n - 1), p2 = n - (i - 1) % (n - 1) - 1;
swap(a[pos[p1]],a[pos[p2]]);
swap(pos[p1],pos[p2]);
}
//输出
for (int i=1;i<=n;i++) cout<<a[i]<<" ";
return 0;
}
在Dev C++上编译完全正确不会报错 但是到洛谷上就编译失败了(Compile Error) 结果我把手动开的O2删了就没事了
#include <iostream>
#include <algorithm>
#include <cctype>
using namespace std;
//#pragma GCC optimize(2)
const int N = 1e5+10;
long long n, m;
long long a[N], pos[N];
inline long long read(){
int f = 1;
long long x = 0;
char c = getchar();
while (!isdigit(c))
{
f = c == '-' ? -1 : 1;
c = getchar();
}
while (isdigit(c))//一边读入一边取模
{
x = ((x << 1) + (x << 3) + (c ^ 48)) % (n * (n - 1));
c = getchar();
}
return f * x;
}
int main(){
//输入
cin >> n;
m = read();
for (int i = 1;i <= n;i++) cin >> a[i];
//处理
int t = m / (n - 1), left = m % (n - 1);
if (t != 0)
{
for (int i = 1;i <= n;i++)//统计错位造成的影响
{
a[i] = (a[i] + t) % n ? (a[i] + t) % n : n;
}
}
for (int i = 1;i <= n;i++) pos[a[i]] = i;
for (int i = 1;i <= left;i++)//模拟
{
int p1 = n - (i - 1) % (n - 1), p2 = n - (i - 1) % (n - 1) - 1;
swap(a[pos[p1]],a[pos[p2]]);
swap(pos[p1],pos[p2]);
}
//输出
for (int i=1;i<=n;i++) cout<<a[i]<<" ";
return 0;
}
什么鬼啊!!!