莫队
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define LL long long
using namespace std;
int read()
{
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=x*10+c-'0';
c=getchar();
}
return f*x;
}
const int N=1e6+5;
struct query { int l,r,num; } q[N];
int bac[N],a[N],l=1,r,b,co[N],col,next,n,m,k;
LL sum,ans[N];
bool cmp(const query &a,const query &b)
{
if(co[a.l]==co[b.l]) return a.r<b.r;
return a.l<b.l;
}
int main()
{
n=read(); m=read(); k=read(); b=sqrt(n);
for(int i=1;i<=n;i++)
{
if(i==next)
{
col++;
next=n/(n/i)+1;
}
co[i]=col;
}
for(int i=1;i<=n;i++) a[i]=read();
for(int i=1;i<=m;i++)
{
q[i].l=read();
q[i].r=read();
q[i].num=i;
}
sort(q+1,q+m+1,cmp);
for(int i=1;i<=m;i++)
{
while(r<q[i].r)
{
r++;
bac[a[r]]++;
sum+=bac[a[r]]*2-1;
}
while(r>q[i].r)
{
sum-=bac[a[r]]*2-1;
bac[a[r]]--;
r--;
}
while(l<q[i].l)
{
sum-=bac[a[l]]*2-1;
bac[a[l]]--;
l++;
}
while(l>q[i].l)
{
l--;
bac[a[l]]++;
sum+=bac[a[l]]*2-1;
}
ans[q[i].num]=sum;
}
for(int i=1;i<=m;i++) cout<<ans[i]<<"\n";
return 0;
}