atcoder#ABC293G. [ABC293G] Triple Index
[ABC293G] Triple Index
Score : points
Problem Statement
You are given a length- sequence of positive integers, and queries about the sequence.
For each , the -th query gives you an integer pair ; print the number of integer triplets such that
- , and
- .
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines. For , the -th line should contain the answer to the -th query.
10 4
2 7 1 8 2 8 1 8 2 8
1 10
1 9
2 10
5 5
5
2
4
0
For the first query, there are five triplets of integers that satisfy the conditions in the problem statement: , and .
20 10
2 2 2 2 1 1 2 2 1 1 1 2 1 2 1 2 2 1 2 1
12 16
17 18
12 18
4 9
13 13
2 5
6 13
2 14
7 14
8 12
1
0
5
2
0
1
11
55
8
1