#include <bits/stdc++.h>
using namespace std;
struct node1 {
  int ls, rs, sum;
} tree[20 * 200100];
int root[200100];
int n, q, tot;
long long C2(long long x) { return ((x) * (x - 1) / 2); }
void insert(int &x, int y, int l, int r, int pos) {
  tot++;
  x = tot;
  tree[x] = tree[y];
  tree[x].sum++;
  if (l == r) return;
  int mid = (l + r) / 2;
  if (pos <= mid)
    insert(tree[x].ls, tree[y].ls, l, mid, pos);
  else
    insert(tree[x].rs, tree[y].rs, mid + 1, r, pos);
}
int get(int x, int y, int l, int r, int ll, int rr) {
  if (ll <= l && r <= rr) return (tree[y].sum - tree[x].sum);
  int mid = (l + r) / 2, ret = 0;
  if (ll <= mid) ret += get(tree[x].ls, tree[y].ls, l, mid, ll, rr);
  if (rr > mid) ret += get(tree[x].rs, tree[y].rs, mid + 1, r, ll, rr);
  return ret;
}
int main() {
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) {
    int pos;
    scanf("%d", &pos);
    insert(root[i], root[i - 1], 1, n, pos);
  }
  for (int i = 1; i <= q; i++) {
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    long long ans = C2(n);
    if (y1 > 1) ans -= C2(get(root[0], root[n], 1, n, 1, y1 - 1));
    if (y2 < n) ans -= C2(get(root[0], root[n], 1, n, y2 + 1, n));
    if (x1 > 1) ans -= C2(get(root[0], root[x1 - 1], 1, n, 1, n));
    if (x2 < n) ans -= C2(get(root[x2], root[n], 1, n, 1, n));
    if (x1 > 1 && y1 > 1)
      ans += C2(get(root[0], root[x1 - 1], 1, n, 1, y1 - 1));
    if (x1 > 1 && y2 < n)
      ans += C2(get(root[0], root[x1 - 1], 1, n, y2 + 1, n));
    if (x2 < n && y1 > 1) ans += C2(get(root[x2], root[n], 1, n, 1, y1 - 1));
    if (x2 < n && y2 < n) ans += C2(get(root[x2], root[n], 1, n, y2 + 1, n));
    printf("%I64d\n", ans);
  }
  return 0;
}
