#SRD0000063. Đếm bộ ba chỉ số (Triple Index)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm bộ ba chỉ số (Triple Index)
Triple Index
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given , for each range count index triplets satisfying $$l\le i<j<k\le r,\qquad a_i=a_j=a_k.$$ Different index triplets are counted separately, even if they share the same value.
Array positions are numbered from to . Every query uses an inclusive interval containing both endpoints. Queries do not modify the original array and are independent of one another.
Input
First line contains . The next line contains values . There follow lines .
Output
Print one integer per query line, preserving the original query order.
Subtasks
- Subtask 1 (10 points): ; ; ; .
- Subtask 2 (20 points): ; ; ; .
- Subtask 3 (25 points): ; ; ; .
- Subtask 4 (45 points): ; ; ; .
Examples
Input
10 4
2 7 1 8 2 8 1 8 2 8
1 10
1 9
2 10
5 5
Output
5
2
4
0
Explanation
For , the five triplets are , , , , and . The singleton range has no triplet. In , values and each appear three times, giving triplets. In , value occurs four times, contributing triplets; no other value occurs three times.