#include<bits/stdc++.h>
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=2e5+100;
const int ub=1e6;
const ll INF=1e18;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){
if(y==0) return x;
return gcd(y,x%y);
}
int n,qq;
///主席树
int root[maxn],sum[maxn*20],ch[maxn*20][2],tot=0;
void update(int old,int &cur,int l,int r,int pos){
cur=++tot;
ch[cur][0]=ch[old][0],ch[cur][1]=ch[old][1];
sum[cur]=sum[old]+1;
if(l==r) return ;
int mid=l+r>>1;
if(pos<=mid) update(ch[old][0],ch[cur][0],l,mid,pos);
else update(ch[old][1],ch[cur][1],mid+1,r,pos);
}
int query(int old,int cur,int l,int r,int L,int R){
if(L<=l&&r<=R) return sum[cur]-sum[old];
int mid=l+r>>1,ans=0;
if(L<=mid) ans+=query(ch[old][0],ch[cur][0],l,mid,L,R);
if(mid<R) ans+=query(ch[old][1],ch[cur][1],mid+1,r,L,R);
return ans;
}
int Q(int x1,int y1,int x2,int y2){
if(x1>x2||y1>y2) return 0;
return query(root[x1-1],root[x2],1,n,y1,y2);
}
int q[10];
int main(){
ios::sync_with_stdio(false);
cin>>n>>qq;
rep(i,1,n+1){
int x;cin>>x;
update(root[i-1],root[i],1,n,x);
}
rep(i,0,qq){
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
q[1]=Q(1,1,x1-1,y1-1),q[2]=Q(x1,1,x2,y1-1),q[3]=Q(x2+1,1,n,y1-1);
q[4]=Q(1,y1,x1-1,y2),q[5]=Q(x1,y1,x2,y2),q[6]=Q(x2+1,y1,n,y2);
q[7]=Q(1,y2+1,x1-1,n),q[8]=Q(x1,y2+1,x2,n),q[9]=Q(x2+1,y2+1,n,n);
ll ans=0,tmp=1LL*q[5]*(q[5]-1)/2;
ans+=1LL*q[1]*(q[5]+q[6]+q[8]+q[9]);
ans+=1LL*q[2]*(q[4]+q[5]+q[6]+q[7]+q[8]+q[9]);///2
ans+=1LL*q[3]*(q[4]+q[5]+q[7]+q[8]);
ans+=1LL*q[4]*(q[2]+q[3]+q[5]+q[6]+q[8]+q[9]);///4
ans+=1LL*q[5]*(n-q[5]);
ans+=1LL*q[6]*(q[1]+q[2]+q[4]+q[5]+q[7]+q[8]);///6
ans+=1LL*q[7]*(q[5]+q[6]+q[2]+q[3]);
ans+=1LL*q[8]*(q[1]+q[2]+q[3]+q[4]+q[5]+q[6]);///8
ans+=1LL*q[9]*(q[1]+q[2]+q[4]+q[5]);
ans>>=1,ans+=tmp;
cout<<ans<<"\n";
}
return 0;
}