luogu#P7769. 「CGOI-1」大师选徒

「CGOI-1」大师选徒

Background

Recently, many people have come to the "Ugly Country" to learn bc. The bc masters ac and mc want to choose some students from all students to teach bc skills.

2021.8.29: Added a set of hack.

Problem Description

There are nn students standing in a line, and each student has an ugliness value aia_i. Now ac and mc will each choose a continuous segment of students to teach bc.

Because ac and mc have a very good relationship, the two chosen segments must have the same number of students, and the sum of the ugliness values of students in corresponding positions must all be ss.

(For example, if ac chooses students 11, 22, 33, and mc chooses students 33, 44, 55, then it must satisfy a1+a3=a2+a4=a3+a5=sa_1+a_3=a_2+a_4=a_3+a_5=s.)

However, ac does not know which students mc chooses or what ss is, so he will give several queries. For each query, you need to answer whether, for the given ss and the segment chosen by mc, ac can choose another segment that satisfies the requirements above.

Simplified statement:

Given nn and nn integers a1,a2,,ana_1,\,a_2,\,\dots,\,a_n.

There are qq queries. Each query gives s,l,rs,l,r. Determine whether there exists bb such that for all k[0,rl]k \in [0, r-l], al+k+ab+k=sa_{l+k}+a_{b+k}=s.

Input Format

The first line contains two integers n,qn,\,q, representing the number of students and the number of queries.

The second line contains nn integers. The ii-th number aia_i represents the ugliness value of the ii-th student.

The next qq lines each contain three integers s,l,rs,\,l,\,r, representing the required sum, the index of the first student chosen by mc, and the index of the last student chosen by mc.

Output Format

For each query, if it is possible to choose students that satisfy the conditions, output Yes; otherwise output No. Print one answer per line.

6 4
1 1 3 4 2 1
4 3 3
1 2 2
5 4 6
2 1 2
Yes
No
Yes
Yes
6 4
4 2 2 2 2 1
6 1 1
5 5 6
4 3 5
5 2 2
Yes
No
Yes
No

Hint

Sample Explanation:

For Sample 1:

In the first query, mc chooses the third student, and ac can choose the first student.

In the second query, the ugliness value of the second student chosen by mc is 11, and the total sum is also 11, but there is no student with ugliness value 00, so the condition cannot be satisfied.

In the third query, mc chooses students from the fourth to the sixth. Then ac chooses students from the second to the fourth, and the sums of corresponding positions are a2+a4=a3+a5=a4+a6=5a_2+a_4=a_3+a_5=a_4+a_6=5, which satisfies the condition.

In the fourth query, mc chooses the first and second students, and ac also chooses the first and second students, so the condition is satisfied.


Constraints:

This problem uses bundled testdata.

For all testdata, 1n,q4×1051\le n,\,q\le 4\times10^5, 1ain1\le a_i \le n, 1s2n1\le s\le 2n, 1lrn1\le l\le r\le n.

  • Subtask 0 (10 points): n,q500n,\,q\le 500.
  • Subtask 1 (20 points): n,q8×103n,\,q\le 8\times10^3.
  • Subtask 2 (20 points): All ss are guaranteed to be the same.
  • Subtask 3 (50 points): No special constraints.

Translated by ChatGPT 5