Yet Another SequenceProblem code: YASEQ |
All submissions for this problem are available.
You are given the first N terms of a sequence. The remaining terms of the sequence are defined as follows:
A [ i ] = number of j such that 0 ≤ j < i and A[ j ] ≥ i - jThe sequence is indexed starting at 0. The first N terms of the sequence will each be equal to N-1, N, or N+1.
In addition to the first terms of the sequence, you will be given a number of queries. For each query you are to calculate the value of the sequence at that index.
Input
Input will begin with an integer T, the number of test cases. Each test case begins with 2 integers N and Q on a line, followed by a line with N integers (each equal to N-1, N, or N+1), then a line with Q non-negative integers.
Output
For each test case, output Q integers on a line, one per query, indicating the respective element of the sequence.
Sample Input
3 3 4 3 3 3 100 1000 1000000 1 4 11 3 4 4 5 0 1 2 3 4 5 6 7 8 9 10 5 4 5 6 5 6 5 6 14 22 29
Sample Output
3 3 3 3 3 4 4 5 3 4 4 4 4 4 4 5 5 5 5
Constraints
- T≤100
- 0<N≤100000
- 0<Q≤100000
- Each query will be between 0 and 10^15, inclusive
- The sum of N+Q over all test cases will not exceed 500000
| Date: | 2011-09-07 |
| Time limit: | 4s |
| Source limit: | 50000B |
| Languages: | All |
Comments
Loading Comments...
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
Loading Submissions...RECENT ACTIVITY FOR THIS PROBLEM:
Loading Recent Activity...HELP
Program should read from standard input and write to standard output.
After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:
- Accepted
Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark. - Time Limit Exceeded
Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach. - Wrong Answer
Your program compiled and ran succesfully but the output did not match the expected output. - Runtime Error
Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section. - Compilation Error
Your code was unable to compile. When you see this icon, click on it for more information.
If you are still having problems, see a sample solution here.
