311027: CF1923C. Find B

Memory Limit:256 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Find Btime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

An array $a$ of length $m$ is considered good if there exists an integer array $b$ of length $m$ such that the following conditions hold:

  1. $\sum\limits_{i=1}^{m} a_i = \sum\limits_{i=1}^{m} b_i$;
  2. $a_i \neq b_i$ for every index $i$ from $1$ to $m$;
  3. $b_i > 0$ for every index $i$ from $1$ to $m$.

You are given an array $c$ of length $n$. Each element of this array is greater than $0$.

You have to answer $q$ queries. During the $i$-th query, you have to determine whether the subarray $c_{l_{i}}, c_{l_{i}+1}, \dots, c_{r_{i}}$ is good.

Input

The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases.

The first line of each test case contains two integers $n$ and $q$ ($1 \le n, q \le 3 \cdot 10^5$) — the length of the array $c$ and the number of queries.

The second line of each test case contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 10^9$).

Then $q$ lines follow. The $i$-th of them contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the borders of the $i$-th subarray.

Additional constraints on the input: the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$; the sum of $q$ over all test cases does not exceed $3 \cdot 10^5$.

Output

For each query, print YES if the subarray is good. Otherwise, print NO.

You can output each letter of the answer in any case (upper or lower). For example, the strings yEs, yes, Yes, and YES will all be recognized as positive responses.

ExampleInput
1
5 4
1 2 1 4 5
1 5
4 4
3 4
1 3
Output
YES
NO
YES
NO

Output

题目大意:
题目描述了一个“良好”数组的概念。一个长度为m的数组a被认为是良好的,如果存在一个长度也为m的整数数组b,使得以下条件成立:
1. a数组的元素和等于b数组的元素和,即 $\sum_{i=1}^{m} a_i = \sum_{i=1}^{m} b_i$;
2. 对于每个索引i(从1到m),$a_i$ 不等于 $b_i$;
3. 对于每个索引i(从1到m),$b_i$ 大于0。

给定一个长度为n的数组c,每个元素都大于0。需要回答q个查询。在第i个查询中,要确定子数组 $c_{l_{i}}, c_{l_{i}+1}, \dots, c_{r_{i}}$ 是否是良好的。

输入输出数据格式:
输入:
- 第一行包含一个整数t(1 ≤ t ≤ 10^4),表示测试用例的数量。
- 每个测试用例的第一行包含两个整数n和q(1 ≤ n, q ≤ 3 × 10^5),分别表示数组c的长度和查询的数量。
- 每个测试用例的第二行包含n个整数 $c_1, c_2, \dots, c_n$(1 ≤ $c_i$ ≤ 10^9)。
- 接下来q行,每行包含两个整数 $l_i$ 和 $r_i$(1 ≤ $l_i$ ≤ $r_i$ ≤ n),表示第i个子数组的边界。
- 输入的附加约束条件:所有测试用例中n的总和不超过3 × 10^5;所有测试用例中q的总和不超过3 × 10^5。

输出:
- 对于每个查询,如果子数组是良好的,则输出YES,否则输出NO。
- 答案的每个字母可以是任何大小写形式。例如,yEs、yes、Yes和YES都会被识别为肯定回答。题目大意: 题目描述了一个“良好”数组的概念。一个长度为m的数组a被认为是良好的,如果存在一个长度也为m的整数数组b,使得以下条件成立: 1. a数组的元素和等于b数组的元素和,即 $\sum_{i=1}^{m} a_i = \sum_{i=1}^{m} b_i$; 2. 对于每个索引i(从1到m),$a_i$ 不等于 $b_i$; 3. 对于每个索引i(从1到m),$b_i$ 大于0。 给定一个长度为n的数组c,每个元素都大于0。需要回答q个查询。在第i个查询中,要确定子数组 $c_{l_{i}}, c_{l_{i}+1}, \dots, c_{r_{i}}$ 是否是良好的。 输入输出数据格式: 输入: - 第一行包含一个整数t(1 ≤ t ≤ 10^4),表示测试用例的数量。 - 每个测试用例的第一行包含两个整数n和q(1 ≤ n, q ≤ 3 × 10^5),分别表示数组c的长度和查询的数量。 - 每个测试用例的第二行包含n个整数 $c_1, c_2, \dots, c_n$(1 ≤ $c_i$ ≤ 10^9)。 - 接下来q行,每行包含两个整数 $l_i$ 和 $r_i$(1 ≤ $l_i$ ≤ $r_i$ ≤ n),表示第i个子数组的边界。 - 输入的附加约束条件:所有测试用例中n的总和不超过3 × 10^5;所有测试用例中q的总和不超过3 × 10^5。 输出: - 对于每个查询,如果子数组是良好的,则输出YES,否则输出NO。 - 答案的每个字母可以是任何大小写形式。例如,yEs、yes、Yes和YES都会被识别为肯定回答。

加入题单

上一题 下一题 算法标签: