分析:
map中默认按key值从小到大排序,所以要用greater<>使其改为从大到小排序;
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
map<int,int,greater<int>>m;//按键从大到小排序
for(int i=1;i<=n;i++){
int a;
cin>>a;
m[abs(i-a)]++;//key值为abs(i-a)处,value值加一
}
for(auto it=m.begin();it!=m.end();it++){
if(it->second!=1)//有相等的差时才输出
cout<<it->first<<" "<<it->second<<endl;
}
return 0;
}