#abc293g. G - Triple Index
G - Triple Index
Score : points
问题描述
给定一个长度为 的正整数序列 ,以及关于该序列的 个查询。
对于每个 ,第 个查询提供一对整数 ;
请输出满足以下条件的整数三元组 的数量:
- ,且
- 。
以上为通义千问 qwen-max 翻译,仅供参考。
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.
Sample Input 1
10 4
2 7 1 8 2 8 1 8 2 8
1 10
1 9
2 10
5 5
Sample Output 1
5
2
4
0
For the first query, there are five triplets of integers that satisfy the conditions in the problem statement: , and .
Sample Input 2
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
Sample Output 2
1
0
5
2
0
1
11
55
8
1
update @ 2024/3/10 12:13:03