#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, q, a[N];
vector<int> vec[N];
void add(int i, int c) {
  for (; i < N; i += i & -i) vec[i].push_back(c);
}
int query(int i, int R) {
  int res = 0;
  for (; i; i -= i & -i)
    res += lower_bound(vec[i].begin(), vec[i].end(), R + 1) - vec[i].begin();
  return res;
}
long long c2(int x) { return 1LL * x * (x - 1) / 2; }
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    add(a[i], i);
  }
  while (q--) {
    int l, d, r, u;
    scanf("%d%d%d%d", &l, &d, &r, &u);
    int A = query(d - 1, l - 1);
    int B = query(d - 1, r) - A;
    int C = query(d - 1, n) - A - B;
    int D = query(u, l - 1) - A;
    int E = query(u, r) - A - B - D;
    int F = query(u, n) - A - B - C - D - E;
    int G = query(n, l - 1) - A - D;
    int H = query(n, r) - A - B - D - E - G;
    int I = n - A - B - C - D - E - F - G - H;
    long long res = c2(n) - c2(A + B + C) - c2(C + F + I) - c2(G + H + I) -
                    c2(A + D + G) + c2(A) + c2(C) + c2(I) + c2(G);
    printf("%lld\n", res);
  }
  return 0;
}
