#P10436. JOI Card Exchange

    ID: 12444 Type: Default 1000ms 256MiB

JOI Card Exchange

JOI Card Exchange

JOI is enthusiastic about collecting cards from a card game. In this game, each card has two integers denoting its strength and cost. JOI brings N cards, numbered from 1 to N, where the i-th card has strength \(S_i\) and cost \(V_i\).

There are two machines at the card exchange center. When you insert two cards \(A\) and \(B\) into one of the machines, you obtain a new card \(C\) defined as follows:

  • If you use the first machine, then \(C\)'s strength is \(\max(A_S, B_S)\) and its cost is \(\max(A_V, B_V)\).
  • If you use the second machine, then \(C\)'s strength is \(\min(A_S, B_S)\) and its cost is \(\min(A_V, B_V)\).

JOI lines up his N cards in the order from card 1 to card N. Then he will perform exactly \(N-1\) operations. In each operation, he picks two adjacent cards and uses one of the machines to combine them into a new card. The new card replaces the two chosen cards in the lineup. After \(N-1\) operations, only one card remains. Its strength and cost depend on the choices of operations.

JOI has a list of M desired cards he wishes to obtain. The j-th desired card is represented by a pair \((T_j, W_j)\) (\(1 \le j \le M\)). Write a program that, given the information on the initial cards and the list of desired cards, determines for each desired card whether it is possible to obtain that card by some sequence of \(N-1\) operations.

inputFormat

The input is given in the following format:

N
S_1 V_1
S_2 V_2
\(\vdots\)
S_N V_N
M
T_1 W_1
T_2 W_2
\(\vdots\)
T_M W_M

Here, N is the number of cards. The next N lines describe the cards, with the i-th card having strength \(S_i\) and cost \(V_i\). M is the number of desired cards, and each of the following M lines contains two integers \(T_j\) and \(W_j\) representing a desired card's strength and cost.

outputFormat

For each of the M desired cards (in the order given), output a line containing Yes if it is possible to obtain that card using exactly \(N-1\) operations, or No otherwise.

sample

2
1 2
3 4
2
1 2
3 4
Yes

Yes

</p>