#include <bits/stdc++.h>
#include "books.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
int n;
const int N = (int)1e6 + 10;
int lef[N], rig[N];
bool vis[N];
long long minimum_walk(vector<int> p, int s) {
n = p.size();
int id;
int low, high;
ll sol = 0;
for(int i = 0 ; i < n; i ++ ){
sol += abs(p[i] - i);
if(!vis[i]){
vector<int> cyc;
id = i;
while(!vis[id]){
vis[id]=true;
cyc.push_back(id);
id=p[id];
}
low = n-1;
high = 0;
for(auto x : cyc){
low = min(low, x);
high = max(high, x);
}
for(auto x : cyc){
lef[x] = low;
rig[x] = high;
}
}
}
int mx = 0;
for(int i = 0 ; i < n; i ++ ){
if(low[i] > mx){
sol += 2;
}
mx = max(mx, rig[i]);
}
return sol;
}
Compilation message
books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:47:17: error: invalid types 'int[int]' for array subscript
47 | if(low[i] > mx){
| ^