Logo
(追記) (追記ここまで)

35026번 - Infection Investigation 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 2048 MB256520.833%

문제

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 1,ドル 2, \ldots, n$ in this order. The host genome is a permutation of genes 1,ドル 2, \ldots n$: it consists of genes $a_1, a_2, \ldots, a_n$ in this order.

Consider a genomic segment $[l; r]$ consisting of genes $a_l, a_{l+1}, \ldots, a_r$. 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 $k$ such that there exist $l \le i_1 < i_2 < \dots < i_k \le r$ for which the inequalities $a_{i_1} < a_{i_2} < \dots < a_{i_{k}}$ hold.

To analyze the genome, Isaac needs to estimate the infection levels of $q$ genomic segments. To secure the funding, Isaac only needs approximate results: an error factor of up to 1ドル.5$ is allowed.

입력

Each test contains multiple test cases. The first line contains the number of test cases $t$ (1ドル \le t \le 10^4$). The description of the test cases follows.

The first line of each test case contains two integers $n$ and $q,ドル denoting the host genome length and the number of genomic segments Isaac is interested in (1ドル \le n, q \le 2 \cdot 10^5$).

The second line contains $n$ distinct integers $a_1, a_2, \ldots, a_n,ドル describing the host genome (1ドル \le a_i \le n$).

Each of the following $q$ lines contains two integers $l$ and $r,ドル denoting the boundaries of a genomic segment for which the infection level should be estimated (1ドル \le l \le r \le n$).

It is guaranteed that the sum of $n$ over all test cases does not exceed 2ドル\cdot 10^5,ドル and the sum of $q$ over all test cases does not exceed 2ドル \cdot 10^5$.

출력

For each test case, print $q$ positive integers, denoting the infection levels of the corresponding genomic segments.

For each genomic segment, let your answer be $x$ and let the true answer be $y$. Your answer will be considered correct if it differs from the true answer by a factor of at most 1ドル.5,ドル that is, if $\max\left(\frac{x}{y}, \frac{y}{x}\right) \le 1.5$.

제한

예제 입력 1

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

예제 출력 1

4
3
5
1
6
12

노트

출처

ICPC > Regionals > Northern Eurasia > Northwestern Russia Regional Contest > ICPC 2025-2026 Northwestern Russia Regional Contest I번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /