#include<bits/stdc++.h>
using namespace std;
#define _ int v, int tl, int tr, int l, int r
#define tm (tl+tr >> 1)
#define sol v+v,tl,tm,l,r
#define sag v+v+1,tm+1,tr,l,r
#define mp make_pair
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef pair < ll , ll > pp;
const int mod = 1e9 + 7;
const int N = 1e6 + 6;
ll H[N],A[N],B[N],L[N],R[N],n,i,l,r,x,mn,mx;
ll minimum_walk(vector < int > p , int s){
memset(H , 0 , sizeof H);
x = 0;
n = p.size();
for(i=0;i<n;i++){
x += abs(p[i] - i);
if(H[i]) continue;
l = r = i;
for(x=i; !H[x] ; x = p[x]){
H[x] = 1;
l = min(l , i);
r = max(r , i);
}
A[l] = r;
B[r] = l;
}
for(mx=r=-1,i=0;i<n;i++){
if(i > r && p[i] != i) mx = max(mx , i);
r = max(r , A[i]);
R[i] = r;
}
for(mn=l=n,i=n-1; i>=0 ;i--){
if(i < r && p[i] != i) mn = min(mn , i);
l = min(l , B[i]);
L[i] = l;
}
return x + 2 * (max(0LL , mx-R[s]) + max(0LL , L[s] - mn));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
8192 KB |
3rd lines differ - on the 1st token, expected: '6', found: '10' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
8192 KB |
3rd lines differ - on the 1st token, expected: '6', found: '10' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
8192 KB |
3rd lines differ - on the 1st token, expected: '6', found: '10' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
8288 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '3145' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
8192 KB |
3rd lines differ - on the 1st token, expected: '6', found: '10' |
2 |
Halted |
0 ms |
0 KB |
- |