#P4396. [AHOI2013] 作业

    ID: 3313 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2013莫队各省省选树状数组安徽块状链表,块状数组,分块

[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 nn and several queries, each query is on an interval of the sequence (from the ll-th number to the rr-th number). First, you need to count how many numbers in this interval are greater than or equal to aa and less than or equal to bb. Second, you need to count how many distinct values are greater than or equal to aa and less than or equal to bb 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 n,mn, m.

The next nn positive integers, each not exceeding 10510^5, form the sequence.

Then there are mm lines. Each line contains four integers l,r,a,bl, r, a, b; see the statement for their meanings.

Output Format

Output mm lines, one for each query. For each query, output two numbers: the number of elements in the interval [l,r][l, r] whose values lie in [a,b][a, b], and the number of distinct values that are greater than or equal to aa and less than or equal to bb 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

N100000,M100000N \le 100000, M \le 100000. All read numbers are positive integers in [1,105][1, 10^5].

Translated by ChatGPT 5