#P14608. [NWRRC 2025] Infection Investigation
[NWRRC 2025] Infection Investigation
题目描述
Isaac is a biologist who specializes in diagnosing viral diseases. The virus modifies the host genome (a sequence of genes) by altering it to suit its own needs. Isaac is writing a paper investigating viral infection in genomes. He has some samples and asks you to help analyze them.
For simplicity, we will assume that the viral genome consists of genes in this order. The host genome is a permutation of genes : it consists of genes in this order.
Consider a genomic segment consisting of genes . The infection level of this segment is measured as the length of the longest subsequence of genes shared with the viral genome. Formally, the infection level is the maximum such that there exist for which the inequalities hold.
To analyze the genome, Isaac needs to estimate the infection levels of genomic segments. To secure the funding, Isaac only needs approximate results: an error factor of up to is allowed.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains two integers and , denoting the host genome length and the number of genomic segments Isaac is interested in ().
The second line contains distinct integers , describing the host genome ().
Each of the following lines contains two integers and , denoting the boundaries of a genomic segment for which the infection level should be estimated ().
It is guaranteed that the sum of over all test cases does not exceed , and the sum of over all test cases does not exceed .
输出格式
For each test case, print positive integers, denoting the infection levels of the corresponding genomic segments.
For each genomic segment, let your answer be and let the true answer be . Your answer will be considered correct if it differs from the true answer by a factor of at most , that is, if .
2
10 4
3 5 8 4 6 7 1 10 2 9
1 7
7 10
1 10
3 4
8 2
1 2 3 4 5 6 7 8
1 8
1 8
4
3
5
1
6
12
京公网安备 11011102002149号