CF1793F.Rebrending

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Kostya and Zhenya — the creators of the band "Paper" — after the release of the legendary album decided to create a new band "Day movers", for this they need to find two new people.

They invited nn people to the casting. The casting will last qq days. On the iith of the days, Kostya and Zhenya want to find two people on the segment from lil_i to rir_i who are most suitable for their band. Since "Day movers" are doing a modern art, musical skills are not important to them and they look only at other signs: they want the height difference between two people to be as small as possible.

Help them, and for each day, find the minimum difference in the growth of people from the casting on this segment!

科斯佳和热尼亚——乐队“Paper”的创始人——在发布传奇专辑后,决定组建一支新乐队“Day movers”,为此他们需要招募两名新成员。

他们邀请了 nn 个人参加试镜。试镜将持续 qq 天。在第 ii 天,科斯佳和热尼亚希望在区间 [li,ri][l_i, r_i] 内选出两人,使其最符合乐队的要求。由于“Day movers”致力于现代艺术,音乐技能对他们而言并不重要,他们只关注其他特征:他们希望所选两人的身高差尽可能小。

请帮助他们,对每一天,求出该区间内所有试镜者身高的最小差值!

输入格式

In the first line you are given two integers nn and qq (2≤n≤3⋅105,1≤q≤1062 \leq n \leq 3 \cdot 10^5, 1 \leq q \leq 10^6) — the number of people who came to the casting and the number of casting days.

In the second line, you are given nn integers a1,a2,a3,…,ana_1, a_2, a_3, \ldots, a_n (1≤ai≤n1 \leq a_i \leq n) — the growth of each of the candidates.

It is also guaranteed that all aia_i are different.

The following qq lines each contains two integers lil_i and rir_i (1≤li<ri≤n1 \leq l_i \lt r_i \leq n) — a segment of people on the iith day of casting.

第一行给出两个整数 nn 和 qq(2≤n≤3⋅1052 \leq n \leq 3 \cdot 10^5,1≤q≤1061 \leq q \leq 10^6)—— 分别表示参加试镜的人数和试镜天数。

第二行给出 nn 个整数 a1,a2,a3,…,ana_1, a_2, a_3, \ldots, a_n(1≤ai≤n1 \leq a_i \leq n)—— 表示每位候选人的身高。

同时保证所有 aia_i 互不相同。

接下来的 qq 行,每行包含两个整数 lil_i 和 rir_i(1≤li<ri≤n1 \leq l_i \lt r_i \leq n)—— 表示第 ii 天试镜的人员区间。

输出格式

Output qq lines. In the ii-th line there should be a minimum height difference between the two candidates on the segment on the ii-th day of casting.

输出 qq 行。第 ii 行应为第 ii 天选角时,该区间内两名候选人之间的最小身高差。

输入输出样例

  • 输入#1

    3 3
    1 3 2
    1 2
    2 3
    1 3

    输出#1

    2
    1
    1
  • 输入#2

    5 3
    4 1 5 3 2
    1 2
    3 4
    2 4

    输出#2

    3
    2
    2
  • 输入#3

    7 4
    2 6 1 7 3 5 4
    4 6
    1 2
    3 6
    1 3

    输出#3

    2
    4
    2
    1

说明/提示

In the first example, the minimum difference on the segment [1,2][1, 2] is 22, on the segment [2,3][2, 3] — 11, on the segment [1,3][1, 3] is also 11.

In the third example, the numbers with the minimum difference on the segment [4,6][4, 6] are 33 and 55 (5−3=25 - 3 = 2). On the segment [1,2][1, 2], the numbers with the minimum difference are 22 and 66 (6−2=46 - 2 = 4). On the segment [3,6][3, 6], the numbers with the minimum difference are 11 and 33 (3−1=23 - 1 = 2). On the segment [1,3][1, 3], the minimum difference is formed by the numbers 11 and 22 (2−1=12 - 1 = 1).

在第一个例子中,区间 [1,2][1, 2] 上的最小差值为 22,区间 [2,3][2, 3] 上为 11,区间 [1,3][1, 3] 上同样为 11。

在第三个例子中,区间 [4,6][4, 6] 上差值最小的两个数是 33 和 55(5−3=25 - 3 = 2);区间 [1,2][1, 2] 上差值最小的两个数是 22 和 66(6−2=46 - 2 = 4);区间 [3,6][3, 6] 上差值最小的两个数是 11 和 33(3−1=23 - 1 = 2);区间 [1,3][1, 3] 上的最小差值由数字 11 和 22 构成(2−1=12 - 1 = 1)。

输入解题思路,AI测评打分。不知道怎么写?

首页