report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
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 ```
Square root decomposition
Frequency
Tree query
Inversions query
Nearest vertex
Dominating color
String occurences 3
Inversions query 2
Pair
Sparse update
Tree
Range query
String concatenation
Subarray distance
Chameleon
Knapsack
Bit counting
Subsequence queries
Sub-subsequence
Delete numbers
Mode
Marisa is happy
Inversions query 3
Upperbound
23 path
Yet another square root decomposition problem
Marisa plays poker
Wonderful world
Topic
Data structure
Rating 1900
Source AHOI
Solution (2) Solution