#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200500;
typedef int node;
const int neutro = 0;
struct RMQ {
  int sz;
  node t[4 * MAXN];
  node &operator[](int p) { return t[sz + p]; }
  void init(int n) {
    sz = 1 << (32 - __builtin_clz(n));
    for (int i = (0); i < (int)(2 * sz); i++) t[i] = neutro;
  }
  void updall() {
    for (int i = ((int)sz) - 1; i >= 0; i--) {
      t[i] = (t[2 * i] + t[2 * i + 1]);
    }
  }
  node get(int i, int j) { return get(i, j, 1, 0, sz); }
  node get(int i, int j, int n, int a, int b) {
    if (j <= a || i >= b) return neutro;
    if (i <= a && b <= j) return t[n];
    int c = (a + b) / 2;
    return (get(i, j, 2 * n, a, c) + get(i, j, 2 * n + 1, c, b));
  }
  void set(int p, node val) {
    for (p += sz; p > 0 && t[p] != val;) {
      t[p] = val;
      p /= 2;
      val = (t[p * 2] + t[p * 2 + 1]);
    }
  }
} rmq;
struct query {
  int pos, lim, id, ans;
  bool rf;
};
bool operator<(query a, query b) { return a.pos < b.pos; }
int n, m, A[MAXN];
long long ANS[MAXN], am[MAXN][4];
vector<int> P;
vector<query> L, R;
int main() {
  while (scanf("%d %d", &n, &m) >= 1) {
    P.resize(n);
    for (int i = (0); i < (int)(n); i++) {
      scanf("%d", &P[i]);
      P[i]--;
    }
    for (int i = (0); i < (int)(m); i++) {
      int xl, yl, xr, yr;
      scanf("%d %d %d %d", &xl, &yl, &xr, &yr);
      xl--;
      xr--;
      yl--;
      yr--;
      ANS[i] = (long long)xl * (xl - 1) / 2 +
               (long long)(n - xr - 2) * (n - xr - 1) / 2 +
               (long long)yl * (yl - 1) / 2 +
               (long long)(n - yr - 2) * (n - yr - 1) / 2;
      L.push_back({xl - 1, yl, i, 0, 0});
      L.push_back({xl - 1, yr + 1, i, 0, 1});
      R.push_back({xr + 1, yl, i, 0, 0});
      R.push_back({xr + 1, yr + 1, i, 0, 1});
    }
    sort(L.begin(), L.end());
    sort(R.begin(), R.end());
    reverse(R.begin(), R.end());
    rmq.init(n);
    int p;
    p = 0;
    for (int i = (0); i < (int)(n); i++) rmq[i] = 0;
    rmq.updall();
    while (p < 2 * m && L[p].pos == -1) p++;
    for (int i = (0); i < (int)(n); i++) {
      rmq.set(P[i], 1);
      while (p < 2 * m && L[p].pos == i) {
        L[p].ans = (L[p].rf ? rmq.get(L[p].lim, n) : rmq.get(0, L[p].lim));
        p++;
      }
    }
    p = 0;
    for (int i = (0); i < (int)(n); i++) rmq[i] = 0;
    rmq.updall();
    while (p < 2 * m && R[p].pos == n) p++;
    for (int i = ((int)n) - 1; i >= 0; i--) {
      rmq.set(P[i], 1);
      while (p < 2 * m && R[p].pos == i) {
        R[p].ans = (R[p].rf ? rmq.get(R[p].lim, n) : rmq.get(0, R[p].lim));
        p++;
      }
    }
    for (int i = (0); i < (int)(2 * m); i++) {
      am[L[i].id][L[i].rf] = L[i].ans;
      am[R[i].id][2 + R[i].rf] = R[i].ans;
    }
    for (int i = (0); i < (int)(m); i++) {
      for (int j = (0); j < (int)(4); j++) {
        ANS[i] -= (long long)am[i][j] * (am[i][j] - 1) / 2;
      }
      ANS[i] = (long long)n * (n - 1) / 2 - ANS[i];
    }
    for (int i = (0); i < (int)(m); i++) printf("%lld\n", ANS[i]);
  }
  return 0;
}
