#P10208. Gift Exchange Feasibility

    ID: 12202 Type: Default 1000ms 256MiB

Gift Exchange Feasibility

Gift Exchange Feasibility

JOI Academy has (N) students numbered from (1) to (N). Each student (i) brings a gift with value (A_i), and has a dissatisfaction threshold (B_i) (with (B_i < A_i)). The academy is planning a gift exchange event where each participating student gives their gift to another student. For a group of (m\ (m \ge 2)) students (p_1, p_2, \ldots, p_m), the gift exchange is feasible if there exists a permutation (q_1, q_2, \ldots, q_m) of (p_1, p_2, \ldots, p_m) such that for every (k) with (1 \le k \le m):

  • (q_k \neq p_k), and
  • (A_{q_k} \ge B_{p_k}).

There are (Q) possible combinations of participating students. The (j)-th combination consists of students with indices from (L_j) to (R_j). Your task is to determine for each combination whether a feasible gift exchange exists, i.e. whether there exists a valid permutation meeting the above conditions.

inputFormat

The input is given in the following format:

(N) (Q) (A_1\ A_2\ \ldots\ A_N) (B_1\ B_2\ \ldots\ B_N) (L_1\ R_1) (L_2\ R_2) (\vdots) (L_Q\ R_Q)

where (B_i < A_i) for every (1 \le i \le N).

outputFormat

For each of the (Q) combinations, output a single line containing either "Yes" if a feasible gift exchange exists among the students in that combination, or "No" otherwise.

sample

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

Yes

</p>