显示代码纯文本
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn=1000000+10;
int p[maxn];
int A[maxn];
int B[maxn];
int dis[maxn];
int ans[maxn];
inline int abs(int x){
return x<0?-x:x;
}
int main(){
freopen("MrBB1.in","r",stdin);
freopen("MrBB1.out","w",stdout);
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&p[i]);
if(p[i]==1)
continue;
if(i<p[i]){
A[p[i]-i]++;
dis[0]++;
}
else
A[p[i]+n-i]++;
B[n-i+1]++;
}
int cnt=0;
long long ans=0;
long long maxx=0x7fffffff,u=0;
for(int i=1;i<=n;i++){
if(p[i]>i)
cnt++;
ans+=abs(p[i]-i);
}
maxx=ans;
for(int i=1;i<n;i++){
dis[i]=dis[i-1]+B[i]-A[i];
ans+=n-dis[i-1];
ans-=dis[i-1];
ans--;
ans+=p[n-i+1]-1;
ans-=n-p[n-i+1];
if(ans<maxx){
maxx=ans;
u=i;
}
}
cout<<maxx<<' '<<u<<endl;
return 0;
}