This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//  ~ Be Name Khoda ~  //
#include "books.h"
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops,Ofast")
using namespace std;
typedef long long ll;
#define pb       push_back
#define mp       make_pair
#define all(x)   x.begin(), x.end()
#define fi       first
#define se       second
const int maxn  =  1e6   + 10;
const int maxn5 =  1e6   + 10;
const int maxnt =  1.2e6 + 10;
const int maxn3 =  1e3   + 10;
const int mod   =  1e9   + 7;
const ll  inf   =  1e18;
ll ans = 0;
int req[maxn5];
int num = 0, av[maxn5], cnt = 0;
long long minimum_walk(std::vector<int> per, int s) {
	int n = per.size();
	int mx = s, mn = s;
	for(int i = 0; i < n; i++){
		req[min(i, per[i])]++;
		req[max(i, per[i])]--;
		ans += abs(per[i] - i);
		if(i != per[i]){
			mn = min(mn, i);
			mx = max(mx, i);
		}
	}
	if(mn == n)
		return 0;
	int emp = 0, cur = 0;
	for(int i = mn; i < mx - 1; i++){
		cur += req[i];
		if(!cur)
			emp++;
	}
	return ans + 2 * emp;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |