PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000012. Sức mạnh của đoạn mảng (Powerful array)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Sức mạnh của đoạn mảng (Powerful array)
Powerful array
Source: Codeforces Version: Phuoc Hung OJ Extended
Problem Statement
For a range , let be the frequency of value in that range. Its power is over all values present. Compute the power of every queried range. Answers may require a 64-bit integer.
Input
The first line contains . The second line has positive integers . The next lines contain .
Output
Print lines, one answer per query in the original order.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Examples
Input
3 2
1 2 1
1 2
1 3
Output
3
6
Explanation
Range has , . Its power is .