#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
const int maxm = 1000000 + 10;
const int mod = (int)1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long LINF = (1LL << 60);
const double PI = acos(-1.0);
int tot, n;
int T[maxn], lson[maxn * 30], rson[maxn * 30], seg[maxn * 30];
int build(int l, int r) {
  int root = tot++;
  seg[tot] = 0;
  if (l < r) {
    int mid = (l + r) >> 1;
    lson[root] = build(l, mid);
    rson[root] = build(mid + 1, r);
  }
  return root;
}
int update(int root, int L, int R, int l, int r, int pos) {
  int newroot = tot++;
  seg[newroot] = seg[root] + 1;
  int mid = (l + r) >> 1;
  if (l == r) {
    return newroot;
  } else {
    if (pos <= mid) {
      lson[newroot] = update(lson[root], L, R, l, mid, pos);
      rson[newroot] = rson[root];
    } else {
      lson[newroot] = lson[root];
      rson[newroot] = update(rson[root], L, R, mid + 1, r, pos);
    }
  }
  return newroot;
}
int query(int root, int L, int R, int l, int r) {
  if (L > R) return 0;
  int mid = (l + r) >> 1, ans = 0;
  if (l >= L && r <= R) return seg[root];
  if (L <= mid) ans += query(lson[root], L, R, l, mid);
  if (R > mid) ans += query(rson[root], L, R, mid + 1, r);
  return ans;
}
long long hehe(long long x) { return (x * (x - 1)) >> 1; }
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  T[0] = build(1, n);
  for (int i = 1; i <= n; i++) {
    int y;
    scanf("%d", &y);
    T[i] = update(T[i - 1], 1, n, 1, n, y);
  }
  long long sum = hehe(n);
  for (int i = 1; i <= q; i++) {
    int l, r, u, d;
    scanf("%d%d%d%d", &l, &u, &r, &d);
    int up = query(T[n], 1, u - 1, 1, n), down = query(T[n], d + 1, n, 1, n);
    int left = query(T[l - 1], 1, n, 1, n),
        right = query(T[n], 1, n, 1, n) - query(T[r], 1, n, 1, n);
    int lu = query(T[l - 1], 1, u - 1, 1, n),
        ru = query(T[n], 1, u - 1, 1, n) - query(T[r], 1, u - 1, 1, n);
    int ld = query(T[l - 1], d + 1, n, 1, n),
        rd = query(T[n], d + 1, n, 1, n) - query(T[r], d + 1, n, 1, n);
    printf("%lld\n", sum - (hehe(up) + hehe(down) + hehe(right) + hehe(left)) +
                         hehe(lu) + hehe(ru) + hehe(ld) + hehe(rd));
  }
  return 0;
}
