#P4396. [AHOI2013] 作业
[AHOI2013] 作业
Description
It is already 2 a.m. After finishing some Codeforces problems, Xiao A pulled out the English test paper. The English homework is not much; it takes exactly one hour to finish. Then there is math homework that also takes one hour, followed by chemistry, physics, Chinese, and so on, each of which also takes one hour. Xiao A feels enormous pressure.
At this moment, Xiao A ran into a very nasty math problem: given a sequence of length and several queries, each query is on an interval of the sequence (from the -th number to the -th number). First, you need to count how many numbers in this interval are greater than or equal to and less than or equal to . Second, you need to count how many distinct values are greater than or equal to and less than or equal to and appear in this interval.
Facing testdata of tens of thousands in scale, Xiao A is almost desperate and can only ask you, the expert, for help. Please help him.
Input Format
The first line contains two integers .
The next positive integers, each not exceeding , form the sequence.
Then there are lines. Each line contains four integers ; see the statement for their meanings.
Output Format
Output lines, one for each query. For each query, output two numbers: the number of elements in the interval whose values lie in , and the number of distinct values that are greater than or equal to and less than or equal to and appear in this interval (see the sample).
3 4
1 2 2
1 2 1 3
1 2 1 1
1 3 1 3
2 3 2 3
2 2
1 1
3 2
2 1
Hint
. All read numbers are positive integers in .
Translated by ChatGPT 5
京公网安备 11011102002149号