• [I] Sona

  • 时间限制: 5000 ms 内存限制: 65535 K
  • 问题描述
  • 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
    
  • 提示
  • 来源
  • XadillaX
  • 操作

显示春菜