복도마다 특정 열쇠가 필요한 일렬의 방들이 있고 각 방에 열쇠가 흩어져 있을 때, 열쇠 없이 x번 방에서 출발해 y번 방으로 갈 수 있는지 묻는 질의에 답한다.
어려움8그리디투 포인터누적 합구현아직 제출이 없습니다시간 제한3초메모리 제한256 MBThere is a wide mansion near JOI-kun’s house. The mansion has N rooms located in a row from east to west. The i-th room from the eastmost room is called the room i. For each i with 1 ≤ i ≤ N −1, the room i and the room i + 1 are connected by a corridor. We can pass corridors in both directions. We need a key to enter a corridor from a room. Each key has a number called the type. More than one keys can have the same type.
From the room i or the room i + 1, we need a key of type Ci to enter a corridor between them.
There are Bi keys in the room i. Their types are Ai, j (1 ≤ j ≤ Bi). If JOI-kun enters a room, he will pick up all the keys in that room. After that, he can use them to enter corridors.
JOI-kun can use keys as many times as he wants. Sometimes, he gets several keys of the same type. But, he has no special advantage to have several keys of the same type compared with the case where he has only one key of that type.
To deal with the situation where he gets lost in the mansion, JOI-kun plans to write a program which answers the following queries:
Your task is to write a program which answers the above queries, instead of JOI-kun.
Given information of the mansion and the queries, write a program which determines, for each query, whether he can move from a room to another room assuming he is now in the mansion without any keys.
Read the following data from the standard input.
Write Q lines to the standard output. The k-th line (1 ≤ k ≤ Q) of the Q lines contains YES if he can move from the room Xk to the room Yk assuming he is now in the room Xk without any keys. Otherwise, it contains NO.