CF622C.Not Equal on a Segment

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given array a with n integers and m queries. The i-th query is given with three integers l__i, r__i, x__i.

For the i-th query find any position p__i (l__i ≤ p__i ≤ r__i) so that a__p__i ≠ x__i.

给你一个包含 nn 个整数的数组 aa,以及 mm 个查询。第 ii 个查询由三个整数 li, ri, xil_i,\, r_i,\, x_i 给出。

对于第 ii 个查询,请在区间 [li, ri][l_i,\, r_i] 内找出任意一个位置 pip_i(即满足 li≤pi≤ril_i \leq p_i \leq r_i),使得 api≠xia_{p_i} \neq x_i。

输入格式

The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the number of elements in a and the number of queries.

The second line contains n integers a__i (1 ≤ a__i ≤ 106) — the elements of the array a.

Each of the next m lines contains three integers l__i, r__i, x__i (1 ≤ l__i ≤ r__i ≤ n, 1 ≤ x__i ≤ 106) — the parameters of the i-th query.

第一行包含两个整数 nn、mm(1≤n,m≤2⋅1051 \leq n, m \leq 2 \cdot 10^5)—— 分别表示数组 aa 的元素个数和查询次数。

第二行包含 nn 个整数 aia_i(1≤ai≤1061 \leq a_i \leq 10^6)—— 表示数组 aa 的元素。

接下来的 mm 行,每行包含三个整数 lil_i、rir_i、xix_i(1≤li≤ri≤n1 \leq l_i \leq r_i \leq n,1≤xi≤1061 \leq x_i \leq 10^6)—— 表示第 ii 个查询的参数。

输出格式

Print m lines. On the i-th line print integer p__i — the position of any number not equal to x__i in segment [l__i, r__i] or the value  - 1 if there is no such number.

输出 m 行。在第 i 行输出整数 p__i —— 即区间 [l__i, r__i] 中任意一个不等于 x__i 的数的位置;若不存在这样的数,则输出  - 1。

输入输出样例

  • 输入#1

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

    输出#1

    2
    6
    -1
    4

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

首页