#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T BM(T p, T e, T M) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T mdINV(T a, T M) {
  return BM(a, M - 2, M);
}
template <class T>
inline T PW(T p, T e) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p);
    p = (p * p);
  }
  return (T)ret;
}
template <class T>
string NTS(T Number) {
  stringstream ss;
  ss << Number;
  return ss.str();
}
template <class T>
T stringtonumber(const string &Text) {
  istringstream ss(Text);
  T result;
  return ss >> result ? result : 0;
}
template <class T>
bool ISLEFT(T a, T b, T c) {
  if (((a.first.first - b.first.first) * (b.second.second - c.second.second) -
       (b.first.first - c.first.first) * (a.second.second - b.second.second)) <
      0.0)
    return 1;
  else
    return 0;
}
vector<int> v[300000 * 5 + 2];
int ar[300000 + 2];
void build(int no, int s, int e) {
  if (s == e) {
    v[no].push_back(ar[s]);
    return;
  }
  int mid = (s + e) >> 1;
  build(no * 2, s, mid);
  build(no * 2 + 1, mid + 1, e);
  v[no] = v[no * 2];
  for (int j = 0; j <= ((int)v[no * 2 + 1].size()) - 1; j++)
    v[no].push_back(v[no * 2 + 1][j]);
  sort(v[no].begin(), v[no].end());
}
int qu(int no, int s, int e, int r1, int r2, int c1, int c2) {
  if (s >= r1 && e <= r2) {
    int first = upper_bound(v[no].begin(), v[no].end(), c2) -
                lower_bound(v[no].begin(), v[no].end(), c1);
    return first;
  }
  int mid = (s + e) >> 1;
  if (mid >= r2)
    return qu(no * 2, s, mid, r1, r2, c1, c2);
  else if (mid < r1)
    return qu(no * 2 + 1, mid + 1, e, r1, r2, c1, c2);
  else {
    return qu(no * 2, s, mid, r1, mid, c1, c2) +
           qu(no * 2 + 1, mid + 1, e, mid + 1, r2, c1, c2);
  }
}
long long int cal(int n, int r1, int r2, int c1, int c2) {
  if (r2 < r1 || c2 < c1) return 0;
  long long int first = qu(1, 1, n, r1, r2, c1, c2);
  first = (first * (first - 1)) / 2;
  return first;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int first;
    scanf("%d", &first);
    ar[first] = i;
  }
  build(1, 1, n);
  long long int res = (long long int)n * ((long long int)n - (long long int)1) /
                      (long long int)2;
  while (m--) {
    int c1, c2, r1, r2;
    scanf("%d%d", &c1, &r1);
    scanf("%d%d", &c2, &r2);
    long long int ans = res;
    ans -= cal(n, 1, r1 - 1, 1, n);
    ans -= cal(n, r2 + 1, n, 1, n);
    ans -= cal(n, 1, n, 1, c1 - 1);
    ans -= cal(n, 1, n, c2 + 1, n);
    ans += cal(n, 1, r1 - 1, 1, c1 - 1);
    ans += cal(n, 1, r1 - 1, c2 + 1, n);
    ans += cal(n, r2 + 1, n, c2 + 1, n);
    ans += cal(n, r2 + 1, n, 1, c1 - 1);
    printf("%lld", ans), printf("\n");
  }
  return 0;
}
