当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6406:Taotao Picks Apples

题目描述
There is an apple tree in front of Taotao's house. When autumn comes, $n$ apples on the tree ripen, and Taotao will go to pick these apples.

When Taotao picks apples, Taotao scans these apples from the first one to the last one. If the current apple is the first apple, or it is strictly higher than the previously picked one, then Taotao will pick this apple; otherwise, he will not pick.

Given the heights of these apples $h_1, h_2, \cdots, h_n$, you are required to answer some independent queries. Each query is two integers $p, q$, which asks the number of apples Taotao would pick, if the height of the $p$-th apple were $q$ (instead of $h_p$). Can you answer all these queries?
输入解释
The first line of input is a single line of integer $T$ $(1 \leq T \leq 10)$, the number of test cases.

Each test case begins with a line of two integers $n, m$ $(1 \leq n, m \leq 10^5)$, denoting the number of apples and the number of queries. It is then followed by a single line of $n$ integers $h_1, h_2, \cdots, h_n$ $(1 \leq h_i \leq 10^9)$, denoting the heights of the apples. The next $m$ lines give the queries. Each of these $m$ lines contains two integers $p$ $(1 \leq p \leq n)$ and $q$ $(1 \leq q \leq 10^9)$, as described in the problem statement.
输出解释
For each query, display the answer in a single line.
输入样例
1
5 3
1 2 3 4 4
1 5
5 5
2 3
输出样例
1
5
3
提示
For the first query, the heights of the apples were 5, 2, 3, 4, 4, so Taotao would only pick the first apple.

For the second query, the heights of the apples were 1, 2, 3, 4, 5, so Taotao would pick all these five apples.

For the third query, the heights of the apples were 1, 3, 3, 4, 4, so Taotao would pick the first, the second and the fourth apples.
来自杭电HDUOJ的附加信息
Recommend chendu

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6406

最后修改于 2020-10-25T23:31:03+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/2000MS(Java/Others) 131072/131072K(Java/Others)