Range query - MarisaOJ: Marisa Online Judge

Range query

Time limit: 500 ms
Memory limit: 256 MB
Given an array $A$ of $n$ integers, there are $q$ queries, each query being a quadruple $(l, r, a, b)$. Count the number of indices $l \le i \le r$ such that $A_i$ is greater than or equal to $a$ and less than or equal to $b$. Also, count the number of distinct values in the range $[l, r]$ that are greater than or equal to $a$ and less than or equal to $b$. ### Input - The first line contains two integers $n, q$. - The second line contains $n$ integers $A_i$. - The next $q$ lines each contain four integers $l, r, a, b$. ### Output - For each query, print two integers representing the count of indices and the count of distinct values satisfying the conditions. ### Constraints - $1 \le n, q, A_i \le 10^5$. ### Example Input: ``` 3 4 1 2 2 1 2 1 3 1 2 1 1 1 3 1 3 2 3 2 3 ``` Output: ``` 2 2 1 1 3 2 2 1 ```