QOJ.ac

QOJ

Limite de temps : 3.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#15415. 感染调查

Statistiques

Isaac 是一名专门诊断病毒性疾病的生物学家。病毒通过改变宿主基因组(一个基因序列)来适应自身的需求。Isaac 正在写一篇研究基因组中病毒感染的论文。他有一些样本,并请求你帮助分析它们。

为了简单起见,我们假设病毒基因组按顺序由基因 $1, 2, \dots, n$ 组成。宿主基因组是基因 $1, 2, \dots, n$ 的一个排列:它按顺序由基因 $a_1, a_2, \dots, a_n$ 组成。

考虑一个由基因 $a_l, a_{l+1}, \dots, a_r$ 组成的基因组片段 $[l; r]$。该片段的感染程度通过与病毒基因组共享的最长子序列的长度来衡量。形式化地,感染程度是满足存在 $l \le i_1 < i_2 < \dots < i_k \le r$ 使得不等式 $a_{i_1} < a_{i_2} < \dots < a_{i_k}$ 成立的最大 $k$。

为了分析基因组,Isaac 需要估算 $q$ 个基因组片段的感染程度。为了获得研究经费,Isaac 只需要近似的结果:允许最大 $1.5$ 倍的误差。

输入格式

每个测试点包含多个测试用例。第一行包含测试用例的数量 $t$ ($1 \le t \le 10^4$)。接下来是测试用例的描述。

每个测试用例的第一行包含两个整数 $n$ 和 $q$,分别表示宿主基因组的长度和 Isaac 感兴趣的基因组片段数量 ($1 \le n, q \le 2 \cdot 10^5$)。

第二行包含 $n$ 个互不相同的整数 $a_1, a_2, \dots, a_n$,描述宿主基因组 ($1 \le a_i \le n$)。

接下来的 $q$ 行,每行包含两个整数 $l$ 和 $r$,表示需要估算感染程度的基因组片段的边界 ($1 \le l \le r \le n$)。

保证所有测试用例中 $n$ 的总和不超过 $2 \cdot 10^5$,且所有测试用例中 $q$ 的总和不超过 $2 \cdot 10^5$。

输出格式

对于每个测试用例,输出 $q$ 个正整数,表示对应基因组片段的感染程度。

对于每个基因组片段,设你的答案为 $x$,真实答案为 $y$。如果你的答案与真实答案相差不超过 $1.5$ 倍,即满足 $\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

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.