#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define g0(x) get<0>(x)
#define g1(x) get<1>(x)
#define g2(x) get<2>(x)
#define mt make_tuple
#define mp make_pair
#define pb push_back
#define int long long
#define f first
#define s second
#define pll pair<long long, long long>
#define iii tuple<int,int,int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,q;cin>>n>>q;
vector<int> v(n+1, 0);
map<int,int> cnt;
for(int i=1;i<=n;i++){
cin>>v[i];
cnt[v[i]]++;
}
vector<pll> ord;
for(auto [a, b] : cnt){
ord.pb({b, a});
}
sort(all(ord));
while(q--){
int L,R;cin>>L>>R;
int ans=0, l=0, r=0;
for(auto [c, val] : ord){
if(l > r) swap(l, r);
int bad=(l+1)*l/2 + (n-l-c+1)*(n-l-c)/2;
int del=(n+1)*(n)/2-bad;
ans += del;
//printf("l %lld, r %lld, bad %lld, del %lld, ans now %lld\n",
// l,r,bad,del,ans);
l += c;
}
cout<<ans;
}
}