#P3781. 小B的询问

小B的询问

题目描述

小B有一个序列,包含N个1~K之间的整数。他一共有M个询问,每个询问给定一个区间[L..R],求Sigma(c(i)^2)的值,其中i的值从1到K,其中c(i)表示数字i在[L..R]中的重复次数。小B请你帮助他回答询问。

输入格式

第一行,三个整数N、M、K。
第二行,N个整数,表示小B的序列。
接下来的M行,每行两个整数L、R。

输出格式

M行,每行一个整数,其中第i行的整数表示第i个询问的答案。

6 4 3
1 3 2 1 1 3
1 4
2 6
3 5
5 6
6
9
5
2

数据范围与约定

<span style="font-size:10.5pt;mso-bidi-font-size:12.0pt;<br />

font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:

"Times New Roman";mso-bidi-font-family:"Times New Roman";mso-ansi-language:

EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA">对于全部的数据,</span><span lang="EN-US" style="font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman";

mso-fareast-font-family:宋体;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;

mso-bidi-language:AR-SA">1<=N</span><span style="font-size:10.5pt;

mso-bidi-font-size:12.0pt;font-family:宋体;mso-ascii-font-family:"Times New Roman";

mso-hansi-font-family:"Times New Roman";mso-bidi-font-family:"Times New Roman";

mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA">、</span><span lang="EN-US" style="font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman";

mso-fareast-font-family:宋体;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;

mso-bidi-language:AR-SA">M</span><span style="font-size:10.5pt;mso-bidi-font-size:

12.0pt;font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family:

"Times New Roman";mso-bidi-font-family:"Times New Roman";mso-ansi-language:

EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA">、</span><span lang="EN-US" style="font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman";

mso-fareast-font-family:宋体;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;

mso-bidi-language:AR-SA">K<=50000</span>