100 1
100 50 99 49 98 48 97 47 96 46 95 45 94 44 93 43 92 42 91 41 90 40 89 39 88 38 87 37 86 36 85 35 84 34 83 33 82 32 81 31 80 30 79 29 78 28 77 27 76 26 75 25 74 24 73 23 72 22 71 21 70 20 69 19 68 18 67 17 66 16 65 15 64 14 63 13 62 12 61 11 60 10 59 9 58 8 57 7 56 6 55 5 54 4 53 3 52 2 51 1
9 8 99 93
 2 9
1 2
1 1 1 1
1 1 1 2
1 2 1 2
1 1 2 1
1 1 2 2
1 2 2 2
2 1 2 1
2 1 2 2
2 2 2 2
 10 10
6 5 7 4 8 3 9 2 10 1
8 8 8 8
2 1 2 7
8 4 8 4
3 9 3 9
7 7 7 7
2 10 2 10
6 8 9 8
1 4 1 4
1 5 4 5
8 10 8 10
 10 10
1 10 2 9 3 8 4 7 5 6
4 3 7 10
3 6 8 7
3 2 6 4
1 1 2 8
3 8 10 9
7 3 8 9
4 5 5 9
2 5 6 7
2 5 6 7
1 7 6 10
 10 5
5 10 4 9 3 8 2 7 1 6
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
 10 10
10 9 8 7 6 5 4 3 2 1
8 8 8 8
2 1 2 7
8 4 8 4
3 9 3 9
7 7 7 7
2 10 2 10
6 8 9 8
1 4 1 4
1 5 4 5
8 10 8 10
 7 7
1 2 3 6 7 4 5
3 2 4 6
3 2 5 4
3 6 7 7
1 1 4 4
2 2 7 6
1 2 6 2
1 2 6 7
 10 10
6 1 7 2 8 3 9 4 10 5
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
 10 10
5 1 6 2 8 3 4 10 9 7
8 1 8 1
1 7 2 7
4 3 8 7
3 7 9 7
7 6 7 7
2 3 10 6
6 4 8 7
1 6 4 7
1 2 5 4
8 5 10 10
 10 10
5 6 4 7 3 8 2 9 1 10
8 8 8 8
2 1 2 7
8 4 8 4
3 9 3 9
7 7 7 7
2 10 2 10
6 8 9 8
1 4 1 4
1 5 4 5
8 10 8 10
 10 10
10 5 9 4 8 3 7 2 6 1
8 1 8 1
1 7 2 7
4 3 8 7
3 7 9 7
7 6 7 7
2 3 10 6
6 4 8 7
1 6 4 7
1 2 5 4
8 5 10 10
 10 10
7 5 1 6 10 3 4 8 9 2
4 3 7 10
3 6 8 7
3 2 6 4
1 1 2 8
3 8 10 9
7 3 8 9
4 5 5 9
2 5 6 7
2 5 6 7
1 7 6 10
 10 10
1 2 3 4 5 6 7 8 9 10
8 8 8 8
2 1 2 7
8 4 8 4
3 9 3 9
7 7 7 7
2 10 2 10
6 8 9 8
1 4 1 4
1 5 4 5
8 10 8 10
 10 10
5 1 6 2 8 3 4 10 9 7
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
 10 10
9 8 3 4 5 6 7 2 1 10
8 1 8 1
1 7 2 7
4 3 8 7
3 7 9 7
7 6 7 7
2 3 10 6
6 4 8 7
1 6 4 7
1 2 5 4
8 5 10 10
 10 10
10 1 9 2 8 3 7 4 6 5
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
 10 10
5 1 6 2 8 3 4 10 9 7
9 5 9 5
4 7 4 7
4 8 5 8
9 1 9 4
4 1 4 6
10 9 10 9
3 5 6 5
3 4 10 4
3 2 5 2
7 8 7 8
 6 10
3 6 1 2 5 4
2 6 2 6
2 3 2 5
6 2 6 2
1 5 1 5
3 5 3 5
2 2 2 4
2 4 5 4
5 4 5 4
1 5 6 5
6 2 6 2
 10 10
1 6 2 7 3 8 4 9 5 10
8 8 8 8
2 1 2 7
8 4 8 4
3 9 3 9
7 7 7 7
2 10 2 10
6 8 9 8
1 4 1 4
1 5 4 5
8 10 8 10

                                                            4886
                                                                1
                                                               1
                                                               1
                                                               1
                                                               1
                                                               1
                                                               1
                                                               1
                                                               1
                                                               11
                                                              17
                                                              15
                                                               6
                                                              16
                                                               2
                                                              19
                                                               4
                                                              20
                                                               8
                                                               39
                                                              30
                                                              26
                                                              16
                                                              23
                                                              29
                                                              27
                                                              30
                                                              30
                                                              27
                                                               45
                                                              45
                                                              45
                                                              45
                                                              45
                                                                9
                                                              14
                                                              21
                                                              16
                                                              16
                                                               9
                                                              15
                                                               4
                                                              20
                                                               3
                                                               17
                                                              16
                                                              11
                                                              16
                                                              21
                                                              11
                                                              21
                                                               45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                                3
                                                               8
                                                              37
                                                              27
                                                              21
                                                              38
                                                              29
                                                              21
                                                              23
                                                              24
                                                               16
                                                              17
                                                              12
                                                               6
                                                              16
                                                               2
                                                              23
                                                               4
                                                              20
                                                               8
                                                                8
                                                              10
                                                              38
                                                              26
                                                              21
                                                              38
                                                              31
                                                              20
                                                              21
                                                              19
                                                               38
                                                              30
                                                              25
                                                              17
                                                              24
                                                              28
                                                              29
                                                              32
                                                              32
                                                              25
                                                               23
                                                              17
                                                              12
                                                               6
                                                              27
                                                               2
                                                              23
                                                               7
                                                              24
                                                               8
                                                               45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                                8
                                                              14
                                                              38
                                                              27
                                                              19
                                                              38
                                                              29
                                                              20
                                                              23
                                                              19
                                                               45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                               10
                                                              16
                                                              17
                                                               8
                                                              27
                                                               2
                                                              25
                                                              26
                                                              16
                                                              16
                                                                5
                                                               9
                                                               2
                                                               2
                                                               6
                                                               8
                                                              11
                                                               8
                                                               9
                                                               2
                                                               16
                                                              17
                                                              12
                                                               6
                                                              16
                                                               2
                                                              23
                                                               7
                                                              18
                                                               8

#include <bits/stdc++.h>
using namespace std;
const int Imx = 2147483647;
const long long Lbig = 2e18;
const int mod = 1e9 + 7;
struct fastio {
  char s[100000];
  int it, len;
  fastio() { it = len = 0; }
  inline char get() {
    if (it < len) return s[it++];
    it = 0;
    len = fread(s, 1, 100000, stdin);
    if (len == 0)
      return EOF;
    else
      return s[it++];
  }
  bool notend() {
    char c = get();
    while (c == ' ' || c == '\n') c = get();
    if (it > 0) it--;
    return c != EOF;
  }
} _buff;
inline long long getnum() {
  long long r = 0;
  bool ng = 0;
  char c;
  c = _buff.get();
  while (c != '-' && (c < '0' || c > '9')) c = _buff.get();
  if (c == '-') ng = 1, c = _buff.get();
  while (c >= '0' && c <= '9') r = r * 10 + c - '0', c = _buff.get();
  return ng ? -r : r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline char getreal() {
  char c = _buff.get();
  while (c == ' ' || c == '\n') c = _buff.get();
  return c;
}
int n, m, a[200111];
pair<int, pair<int, int> > cmd[2000111];
int cn;
void addc(int t, int l, int r) { cmd[++cn] = make_pair(t, make_pair(l, r)); }
long long ans[2000111];
struct command {
  int tp, x, y, v, id;
  command(int Tp = 0, int X = 0, int Y = 0, int V = 0, int Id = 0) {
    tp = Tp;
    x = X;
    y = Y;
    v = V;
    id = Id;
  }
  bool operator<(const command &t) const {
    return make_pair(x, y) < make_pair(t.x, t.y);
  }
};
void addbit(int x, int v) {
  for (int i = x; i <= 200005; i += i & (-i)) a[i] += v;
}
long long sumbit(int x) {
  long long ret = 0;
  for (int i = x; i > 0; i -= i & (-i)) ret += a[i];
  return ret;
}
vector<command> v;
void solvev() {
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size();) {
    int r = i;
    while (r < v.size() && v[i].x == v[r].x) r++;
    for (int j = i; j < r; j++) {
      if (v[j].tp == 1) {
        addbit(v[j].y, v[j].v);
      }
    }
    for (int j = i; j < r; j++) {
      if (v[j].tp == 2) {
        ans[v[j].id] += v[j].v * sumbit(v[j].y);
      }
    }
    i = r;
  }
  for (int i = 0; i < v.size();) {
    int r = i;
    while (r < v.size() && v[i].x == v[r].x) r++;
    for (int j = i; j < r; j++) {
      if (v[j].tp == 1) {
        addbit(v[j].y, -v[j].v);
      }
    }
    i = r;
  }
}
const int mxn = 200111;
int xl[mxn], xr[mxn], yl[mxn], yr[mxn];
void solve(int l, int r) {
  if (l == r) return;
  int m = l + r >> 1;
  v.clear();
  for (int i = l; i <= m; i++) {
    int x = cmd[i].second.first, y = cmd[i].second.second;
    if (cmd[i].first == 1) {
      v.push_back(command(1, x, y, 1, i));
    }
  }
  for (int i = m + 1; i <= r; i++) {
    int x = cmd[i].second.first, y = cmd[i].second.second;
    if (x == 0 || y == 0) continue;
    if (cmd[i].first == 3) {
      v.push_back(command(2, x, y, 1, i));
    }
  }
  solvev();
  solve(l, m);
  solve(m + 1, r);
}
long long s[4][4];
int main() {
  n = getnum(), m = getnum();
  for (int i = 1; i <= n; i++) {
    int x;
    x = getnum();
    cmd[++cn] = make_pair(1, make_pair(i, x));
  }
  for (int i = 1; i <= m; i++) {
    xl[i] = getnum(), yl[i] = getnum();
    xr[i] = getnum(), yr[i] = getnum();
    cmd[++cn] = make_pair(3, make_pair(xr[i], n));
    cmd[++cn] = make_pair(3, make_pair(xl[i] - 1, n));
    cmd[++cn] = make_pair(3, make_pair(n, yr[i]));
    cmd[++cn] = make_pair(3, make_pair(n, yl[i] - 1));
    cmd[++cn] = make_pair(3, make_pair(xr[i], yr[i]));
    cmd[++cn] = make_pair(3, make_pair(xl[i] - 1, yr[i]));
    cmd[++cn] = make_pair(3, make_pair(xr[i], yl[i] - 1));
    cmd[++cn] = make_pair(3, make_pair(xl[i] - 1, yl[i] - 1));
  }
  solve(1, cn);
  for (int i = 1; i <= m; i++) {
    memset(s, 0, sizeof(s));
    s[3][3] = n;
    int bs = n + (i - 1) * 8;
    s[2][3] = ans[bs + 1];
    s[1][3] = ans[bs + 2];
    s[3][2] = ans[bs + 3];
    s[3][1] = ans[bs + 4];
    s[2][2] = ans[bs + 5];
    s[1][2] = ans[bs + 6];
    s[2][1] = ans[bs + 7];
    s[1][1] = ans[bs + 8];
    long long sum = 0;
    for (int x = 3; x >= 1; x--) {
      for (int y = 3; y >= 1; y--) {
        s[x][y] = s[x][y] - s[x - 1][y] - s[x][y - 1] + s[x - 1][y - 1];
      }
    }
    sum += 1ll * s[2][2] * (s[2][2] - 1);
    for (int xl = 1; xl <= 3; xl++) {
      for (int yl = 1; yl <= 3; yl++) {
        for (int xr = 1; xr <= 3; xr++) {
          for (int yr = 1; yr <= 3; yr++) {
            if (2 < xl && 2 < xr) continue;
            if (2 > xl && 2 > xr) continue;
            if (2 < yl && 2 < yr) continue;
            if (2 > yl && 2 > yr) continue;
            if (xl == xr && yl == yr) continue;
            sum += 1ll * s[xl][yl] * s[xr][yr];
          }
        }
      }
    }
    putnum(sum / 2), putchar('\n');
  }
  return 0;
}
