Tax
Statement
Last year N people in one country paid tax. The clerk who manages the tax wants to run K rounds of information gathering while collecting the records of what people paid last year. Each round uses two variables X and Y, which means counting the number of people whose paid tax amount is between X and Y inclusive.
For each of the K rounds, write a program that computes in order the number of people whose paid tax amount is between X and Y inclusive.
For example, suppose the tax amounts paid by N=5 people are as in the table below.
| No. | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| Amount | 7 | 2 | 3 | 5 | 2 |
Next, suppose the information for the K=3 rounds of gathering is as follows. The variables used for a round are given as an [X, Y] array.
| No. | 1 | 2 | 3 |
|---|---|---|---|
| Values | [1, 100] | [3, 5] | [2, 2] |
In this example the correct result for each round of gathering is as follows. The results are 5 people, 2 people and 2 people in order.
| No. | 1 | 2 | 3 |
|---|---|---|---|
| Result | 5 | 2 | 2 |
Input and Output Examples
Example 1
Input
5, 3, [7, 2, 3, 5, 2], [[1, 100], [3, 5], [2, 2]]
Output
[5, 2, 2]
Example 2
Input
6, 4, [9, 8, 1, 5, 5, 5], [[5, 8], [3, 10], [1, 2], [5, 9]]
Output
[4, 5, 1, 5]
Input
First the number of people who paid tax N and the number of gathering rounds K are given. Both N and K are natural numbers between 4 and 100,000.
Next an array arr holding the information about the tax the N people paid is given. The amount each person paid is a natural number between 1 and 1,000,000,000.
Next an array queries holding the information about the K rounds of gathering is given. Specifically it is a two-dimensional array whose row size is N and whose column size is 2. X and Y in each round of gathering are natural numbers between 1 and 1,000,000,000, and X is less than or equal to Y.
Output
For the K rounds of gathering, compute in order the number of people whose paid tax amount is between X and Y inclusive, and return them as a one-dimensional array.
Requirements
- You must write a solution(N, K, arr, queries) function and return the answer
- Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
- The languages you can use are Python and JavaScript
- The memory limit is 256MB. The browser does not measure it, it only states it
- The time limit is set by measuring the setter's reference solution on the same runtime
- On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
- The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
- There are 20 cases, and 2 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
- You have to pass all 20 cases to solve this.
Examples
2 public cases. Judging also uses hidden cases. You have to pass all 20 cases to solve this.
5, 3, [7, 2, 3, 5, 2], [[1, 100], [3, 5], [2, 2]]
[5, 2, 2]
6, 4, [9, 8, 1, 5, 5, 5], [[5, 8], [3, 10], [1, 2], [5, 9]]
[4, 5, 1, 5]
Notes
Background that helps with solving. The rules you have to follow are in the input and output specs and the requirements above.
This is problem 5 of practice test 2 in the original.
Solution
Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.
Submitting requires you to log in. Running against the public cases works without one.
You can test with 2 public cases. Submitting runs the hidden cases too.
People who solved this problem
The time shown is the time spent solving. Input reading time is outside the solver's control, so it is excluded. And since each device reports this value itself, we record which device measured it.
Input read time 660ms (excluded from the ranking)
Log in and you can see the code once you solve this problem.