PivotOJ

Gift Exchange

시간 제한: 2500ms메모리 제한: 1024MB출처: JOI 2023-2024 본선BOJ 31626

문제

JOI Academy has NN students, numbered from 11 to NN.

A gift exchange party is planned to be held soon at JOI Academy. Each student has prepared a gift to bring there, and the value of the gift that student ii (1 &le; i &le; N) will bring is AiA_i. Students are unwilling to receive a gift whose value is too less than that of their own gift. Specifically, student ii will be dissatisfied if they receive a gift with a value strictly less than BiB_i. Here, Bi<AiB_i < A_i always holds.

However, some of the NN students may not actually participate in the party. President KK, the director of JOI Academy, is considering QQ possible groups of students as a group to participate in the gift exchange party, jj-th (1 &le; j &le; Q) of which consists of RjLj+1R_j - L_j + 1 students Lj,Lj+1,,RjL_j , L_j + 1,\dots , R_j.

For some group of two or more students, if it is possible to exchange gifts within the group without anyone receiving their own gift or getting dissatisfied, that group is said to be gift exchangeable. More formally, a group of mm students (m &ge; 2) p1,p2,,pmp_1, p_2, \dots , p_m is gift exchangeable if and only if there exists a sequence q1,q2,,qmq_1, q_2, \dots , q_m which is a permutation of p1,p2,,pmp_1, p_2, \dots , p_m and satisfies each of the following conditions. Here, qkq_k (1 &le; k &le; m) represents the number of student who gives their gift to student pkp_k.

  • For all kk (1 &le; k &le; m),pkqkp_k \ne q_k.
  • For all kk (1 &le; k &le; m),A_{q_k} &ge; B_{p_k}.

President K is keen to make the gift exchange party successful, and thus examining whether each of the QQ groups is gift exchangeable or not.

Write a program which, given information of students and groups, determines whether each of the QQ groups is gift exchangeable or not.

입력

Read the following data from the standard input.

NN

A1A_1 A2A_2 \cdots ANA_N

B1B_1 B2B_2 \cdots BNB_N

QQ

L1L_1 R1R_1

L2L_2 R2R_2

\vdots

LQL_Q RQR_Q

출력

Write QQ lines to the standard output. On the jj-th line (1 &le; j &le; Q), output Yes if the jj-th group is gift exchangeable, and No otherwise.

예제

예제 1

입력
4
3 8 5 7
2 6 1 4
3
3 4
1 3
1 4
출력
Yes
No
Yes

예제 2

입력
3
5 6 3
1 4 2
1
1 3
출력
Yes

예제 3

입력
5
3 4 6 9 10
1 2 5 7 8
3
1 5
1 2
2 4
출력
No
Yes
No

예제 4

입력
10
2 5 8 10 12 14 16 17 19 20
1 4 7 6 11 13 9 3 18 15
8
2 9
1 6
2 8
2 4
1 2
1 6
7 10
5 8
출력
No
No
Yes
No
No
No
Yes
Yes
코드를 제출하려면 로그인하세요.