에 오신 것을 환영합니다 내 Luogu 공간 .
[제목] 효과
시퀀스, 각 쿼리 \ ([L, R] \ ) 각 자릿수의 숫자의 제곱 및 발생의 범위.
[설명]
모 팀 .
모 팀 타이틀 아주 템플릿입니다.
출시 \ ((N- 형 + 1) ^ 2 ^ 2N = 2N + 1 \) (숫자에 발생의 n 수)
많은 기여가 발생하는 방법에 대한 답변의 수를 나타납니다 또 하나의 수를 의미한다.
로 차단 \ (\의 SQRT {N} \ ) 가.
[코드]
// output format !!
// long long !!
#include <bits/stdc++.h>
#define H puts("HYX")
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int MAXN = 50000+10;
int bol;
struct Q{
int l, r, id;
bool operator<(Q a)const{
return (r/bol==a.r/bol) ? l<a.l : r<a.r;
}
}q[MAXN];
int n, m, k;
int cnt[MAXN], s[MAXN];
LL ans, Ans[MAXN];
int main(){
scanf("%d%d%d", &n, &m, &k);
bol = sqrt(n);
for(int i=1; i<=n; ++i) scanf("%d", s+i);
for(int i=1; i<=m; ++i) scanf("%d%d", &q[i].l, &q[i].r), q[i].id = i;
std::sort(q+1, q+m+1);
int L = 1, R = 0;
for(int i=1; i<=m; ++i){
while(R-1 >= q[i].r) ans -= 1ll*cnt[s[R]]*2-1, --cnt[s[R--]];
while(R+1 <= q[i].r) ans += 1ll*cnt[s[++R]]*2+1, ++cnt[s[R]];
while(L+1 <= q[i].l) ans -= 1ll*cnt[s[L]]*2-1, --cnt[s[L++]];
while(L-1 >= q[i].l) ans += 1ll*cnt[s[--L]]*2+1, ++cnt[s[L]];
Ans[q[i].id] = ans;
}
for(int i=1; i<=m; ++i) printf("%lld\n", Ans[i]);
return 0;
}