#include <bits/stdc++.h>
using namespace std;
int Gcd(int a, int b) {
  if (b == 0) return a;
  return Gcd(b, a % b);
}
int Lcm(int a, int b) { return a / Gcd(a, b) * b; }
inline long long read() {
  long long f = 1, x = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int maxn = 2e5 + 10;
int sum[maxn << 5], ls[maxn << 5], rs[maxn << 5];
int rt[maxn << 5];
int Node;
void build(int &rt, int l, int r) {
  rt = ++Node;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(ls[rt], l, mid);
  build(rs[rt], mid + 1, r);
}
int modify(int pre, int l, int r, int pos, int v = 1) {
  int now = Node++;
  sum[now] = sum[pre] + v;
  ls[now] = ls[pre];
  rs[now] = rs[pre];
  if (l == r) return now;
  int mid = (l + r) >> 1;
  if (pos <= mid)
    ls[now] = modify(ls[pre], l, mid, pos, v);
  else
    rs[now] = modify(rs[pre], mid + 1, r, pos, v);
  return now;
}
int Query(int pre, int now, int l, int r, int ql, int qr) {
  if (qr < ql) return 0;
  if (ql <= l && r <= qr) {
    return sum[now] - sum[pre];
  }
  int mid = (l + r) >> 1, sum = 0;
  if (ql <= mid) sum += Query(ls[pre], ls[now], l, mid, ql, qr);
  if (qr > mid) sum += Query(rs[pre], rs[now], mid + 1, r, ql, qr);
  return sum;
}
long long calc(long long n) { return n * (n - 1) / 2; }
int main() {
  int n = read(), q = read();
  build(rt[0], 1, n);
  for (int i = 1; i <= n; i++) {
    int y = read();
    rt[i] = modify(rt[i - 1], 1, n, y, 1);
  }
  rt[n + 1] = rt[n];
  while (q--) {
    int x1 = read(), y1 = read(), x2 = read(), y2 = read();
    long long n1 = Query(rt[0], rt[n], 1, n, y2 + 1, n);
    long long n2 = Query(rt[0], rt[n], 1, n, 1, y1 - 1);
    long long n3 = Query(rt[0], rt[x1 - 1], 1, n, 1, n);
    long long n4 = Query(rt[x2], rt[n], 1, n, 1, n);
    long long d1 = Query(rt[0], rt[x1 - 1], 1, n, y2 + 1, n);
    long long d2 = Query(rt[0], rt[x1 - 1], 1, n, 1, y1 - 1);
    long long d3 = Query(rt[x2], rt[n], 1, n, y2 + 1, n);
    long long d4 = Query(rt[x2], rt[n], 1, n, 1, y1 - 1);
    printf("%lld\n", calc(n) - (calc(n1) + calc(n2) + calc(n3) + calc(n4) -
                                calc(d1) - calc(d2) - calc(d3) - calc(d4)));
  }
  return 0;
}
