#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
vector<int> sum[MAXN << 2];
int n, q;
void add(int x, int v) {
  while (x <= n) {
    sum[x].push_back(v);
    x += x & -x;
  }
}
int query(int x, int v) {
  int ans = 0;
  while (x > 0) {
    ans += lower_bound(sum[x].begin(), sum[x].end(), v + 1) - sum[x].begin();
    x -= x & -x;
  }
  return ans;
}
long long int c2(int x) { return 1LL * x * (x - 1) / 2; }
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1, v; i <= n; i++) {
    scanf("%d", &v);
    add(v, i);
  }
  int l, d, r, u;
  while (q--) {
    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 int 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;
}
