题目链接:http://codeforces.com/problemset/problem/612/B
解题思路:
一开始看错了题意,他要求的是从1-n所耗费的时间,n表示的是数值而不是下标,
实现代码:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <bitset>
using namespace std; #define rep(i,a,b) for (int i=(a),_ed=(b);i<=_ed;i++)
#define per(i,a,b) for (int i=(b),_ed=(a);i>=_ed;i--)
#define pb push_back
#define mp make_pair
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 1000000007
#define LL long long
#define ULL unsigned long long
#define MS0(X) memset((X), 0, sizeof((X)))
#define SelfType int
SelfType Gcd(SelfType p,SelfType q){return q==?p:Gcd(q,p%q);}
SelfType Pow(SelfType p,SelfType q){SelfType ans=;while(q){if(q&)ans=ans*p;p=p*p;q>>=;}return ans;}
#define Sd(X) int (X); scanf("%d", &X)
#define Sdd(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define Sddd(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())
#define all(a) a.begin(), a.end()
#define mem(x,v) memset(x,v,sizeof(x))
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
struct node{
int num,id;
}a[];
bool cmp(const node x,const node y){
return x.num<y.num;
}
int main()
{
LL m,ans=,i;
cin>>m;
for(i=;i<=m;i++){
cin>>a[i].num;
a[i].id = i;
}
sort(a+,a++m,cmp);
for(i=;i<m;i++)
ans+=abs(a[i+].id-a[i].id);
cout<<ans<<endl;
}