Minimum steps to reach a given index in the Array based on given conditions

#include using namespace std;  vector res(int arr[], int q[], int n, int m){                vector result, v1, v2;              int last_m1 = -1, last_1 = -1;              for (int i = 0; i < n; i++) {        v2.push_back(last_1);        if (arr[i] == 1)            last_1 = i;    }              for (int i = n - 1; i >= 0; i–) {        v1.push_back(last_m1);        if (arr[i] == -1)            last_m1 = i;    }          reverse(v1.begin(), v1.end());          for (int i = 0; i < m; i++) {          if (v1[q[i]] != -1 and v2[q[i]] != -1)            result.push_back(                min(abs(v1[q[i]] - q[i]),                    abs(v2[q[i]] - q[i])));        else if (v1[q[i]] != -1)            result.push_back(                abs(v1[q[i]] - q[i]));        else if (v2[q[i]] != -1)            result.push_back(                abs(v2[q[i]] - q[i]));        else            result.push_back(-1);    }          return result;}  int main(){        int arr[] = { -1, 0, 0, 1, -1, 1,                  1, 0, 0, 1, -1, 0 };    int n = sizeof(arr) / sizeof(arr[0]);          int q[] = { 1, 5, 10 };    int m = sizeof(q) / sizeof(q[0]);          vector x = res(arr, q, n, m);          for (auto y : x)        cout