#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define L(a) a<<1
#define R(a) a<<1|1
#define P pair<int,int>
#define pii pair<ll,ll>
#define lowbit(x) ((x)&-(x))
#define pi acos(-1.0)
#define gcd(x,y) __gcd(x,y)
#define unq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define mem(x,k) memset(x,k,sizeof x)
const int dx[8]={0,0,1,-1,1,-1,1,-1};
const int dy[8]={1,-1,0,0,-1,1,1,-1};
const int inf = 0x3f3f3f3f;
const int mod =1e9+7;
// const ll inf=9e18;
const double eps = 1e-5;
const int maxn = 5e5+10;
const int N=1e8+10;
const double Pi=3.1415926535;
ll w[maxn];
int block;
ll sum[maxn];
struct node{
int id=0;
int l,r;
bool operator<(const node &a)const{
if(l/block==a.l/block){
if((l/block)&1) return r<a.r;
return r>a.r;
}
return l<a.l;
}
}op[maxn];
ll ans[maxn];
ll b[maxn];
ll cnt;
void solve(ll &a,ll &b){
if(a==0) return;
int temp=gcd(a,b);
a/=temp;
b/=temp;
}
void add(int x){
sum[x]++;
cnt+=sum[x]-1;
}
void del(int x){
cnt-=sum[x]-1;
sum[x]--;
}
int main() {
int n,m;
cin>>n>>m;
block=sqrt(n);
for(int i=1;i<=n;i++) cin>>w[i];
for(int i=1;i<=m;i++){
int l,r;
cin>>op[i].l>>op[i].r;
op[i].id=i;
}
sort(op+1,op+1+m);
int r=0,l=1;
for(int i=1;i<=m;i++){
int L=op[i].l,R=op[i].r;
if(L==R){
ans[op[i].id]=0;
continue;
}
while(l<L) del(w[l++]);
while(l>L) add(w[--l]);
while(r<R) add(w[++r]);
while(r>R) del(w[r--]);
ans[op[i].id]=cnt;
b[op[i].id]=(op[i].r-op[i].l+1)*(op[i].r-op[i].l)/2;
}
for(int i=1;i<=m;i++){
solve(ans[i],b[i]);
if(ans[i]!=0) printf("%lld/%lld\n",ans[i],b[i]);
else printf("0/1\n");
}
}
我的意思是 如果如果当前答案为cnt 然后 a颜色 有k 个 如果再来一个a颜色 cnt+=k