主题

主题

 
   

[1457] Sona

原题:https://ac.2333.moe/Problem/view.xhtml?id=1457

问题描述

Sona, Maven of the Strings. Of cause, she can play the zither.

Sona can't speak but she can make fancy music. Her music can attack, heal, encourage and enchant.

There're an ancient score(乐谱). But because it's too long, Sona can't play it in a short moment. So Sona decide to just play a part of it and revise it.

A score is composed of notes. There are 109 kinds of notes and a score has 105 notes at most.

To diversify Sona's own score, she have to select several parts of it. The energy of each part is calculated like that:

Count the number of times that each notes appear. Sum each of the number of times' cube together. And the sum is the energy.

You should help Sona to calculate out the energy of each part.

输入

This problem contains several cases. And this problem provides 2 seconds to run.

The first line of each case is an integer N (1 ≤ N ≤ 10^5), indicates the number of notes.

Then N numbers followed. Each number is a kind of note. (1 ≤ NOTE ≤ 10^9)

Next line is an integer Q (1 ≤ Q ≤ 10^5), indicates the number of parts.

Next Q parts followed. Each part contains 2 integers Li and Ri, indicates the left side of the part and the right side of the part.

输出

For each part, you should output the energy of that part.

样例输入

8

1 1 3 1 3 1 3 3

4

1 8

3 8

5 6

5 5

样例输出

128

72

2

1


题目大意:

给出一个长度为n的序列,给出m个询问,每一次询问查询每种数字出现次数的立方的和。


个人解法:

莫队维护桶,移动的时候更新一下就好了。

然而BNUTOJ的G++十分诡异……sqrt不转double判CE……这是多老的编译器了?


代码如下:

https://code.csdn.net/snippets/2307144

 
 
评论