#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, q;
struct node {
  int val = 0;
  node *l = nullptr, *r = nullptr;
} * root[N];
node *update(node *old, int l, int r, int pos) {
  node *ret = new node();
  if (l == r) {
    ret->val = old->val + 1;
  } else {
    int mid = (l + r) / 2;
    if (pos <= mid) {
      ret->l = update(old->l, l, mid, pos);
      ret->r = old->r;
    } else {
      ret->l = old->l;
      ret->r = update(old->r, mid + 1, r, pos);
    }
    ret->val = ret->l->val + ret->r->val;
  }
  return ret;
}
int query(node *now, int l, int r, int ll, int rr) {
  if (ll > rr) {
    return 0;
  }
  if (l >= ll && r <= rr) {
    return now->val;
  }
  int mid = (l + r) / 2, ret = 0;
  if (ll <= mid) {
    ret += query(now->l, l, mid, ll, rr);
  }
  if (rr > mid) {
    ret += query(now->r, mid + 1, r, ll, rr);
  }
  return ret;
}
long long f(int x) { return 1ll * x * (x - 1) / 2; }
void read(int &x) {
  x = 0;
  char c = getchar();
  for (; c < '0' || c > '9'; c = getchar())
    ;
  for (; '0' <= c && c <= '9'; c = getchar()) {
    x = x * 10 + c - '0';
  }
}
int main() {
  read(n);
  read(q);
  root[0] = new node();
  root[0]->l = root[0]->r = root[0];
  int x;
  for (int i = 1; i <= n; i++) {
    read(x);
    root[i] = update(root[i - 1], 1, n, x);
  }
  int l, d, r, u;
  while (q--) {
    read(l);
    read(d);
    read(r);
    read(u);
    long long ans = f(n);
    ans -= f(query(root[n], 1, n, 1, d - 1)) +
           f(query(root[n], 1, n, 1, n) - query(root[r], 1, n, 1, n)) +
           f(query(root[n], 1, n, u + 1, n)) +
           f(query(root[l - 1], 1, n, 1, n));
    ans += f(query(root[l - 1], 1, n, 1, d - 1)) +
           f(query(root[n], 1, n, 1, d - 1) - query(root[r], 1, n, 1, d - 1)) +
           f(query(root[n], 1, n, u + 1, n) - query(root[r], 1, n, u + 1, n)) +
           f(query(root[l - 1], 1, n, u + 1, n));
    printf("%lld\n", ans);
  }
}
