DP (Small)
InterviewTime limit2sMemory limit1024 MB
For each queried problem, find the longest sequence ending at it where both the problem numbers and the difficulties strictly increase.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Array
- Solved
- No attempts yet
Problem
This problem differs from DP (Large) in the limits on the number of problems, the number of queries, and the difficulty values.
DP is short for DYNAMIC Porani.
DYNAMIC Porani likes to solve problems in a DYNAMIC way. A DYNAMIC solution means solving as many problems as possible while both the problem numbers and the difficulties increase.
During vacation, Porani received a list of recommended problems from a senior to improve his algorithm skills. Lazy Porani does not want to solve every problem. When the senior tells him to solve a certain problem, find how many problems he must solve in total to solve them DYNAMICally, including that problem.
Input
The first line contains two integers () and (), separated by a space.
The second line contains non-negative integers (; ), the difficulty of each problem in order of problem number, separated by spaces. Problem numbers are consecutive positive integers starting from 1.
From the third line, lines follow, each containing a problem number (; ) that the senior asked Porani to solve. The problem numbers in the queries are distinct.
Output
Print lines. On line , print the number of problems Porani must solve for the -th instruction from the senior.