#P17154. [ICPC 2017 Xi'an R] Acedia
[ICPC 2017 Xi'an R] Acedia
Problem Description
You are given a sequence of numbers, the -th number is .
You need to answer queries.
Each query is: for each from to , calculate the number of valid pairs in range .
We call a pair valid when:
- For each from to , there exists at least one element in range which is equal to .
- There is no element in range which is equal to or .
Input Format
The input contains multiple test cases.
The first line contains a number denoting the number of test cases.
In each test case:
The first line contains two numbers . .
Then one line contains numbers indicating .
The following lines each contain two numbers denoting a query in range .
Output Format
For each query you need to output numbers. In order to reduce the amount of output, you just need to output each number mod , without space.
For each test case, output lines. The -th line contains a string of length indicating the answers of the -th query.
1
5 5
1 2 4 5 6
1 5
1 2
3 4
3 5
4 5
0110000000
0100000000
0100000000
0010000000
0100000000