시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
3 초 | 256 MB | 72 | 33 | 28 | 41.791% |
There 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.
There are no additional constraints.
5 1 2 3 4 2 2 3 1 1 1 1 1 3 1 4 4 2 4 4 2 1 5 5 3
YES NO NO YES
5 2 3 1 3 1 3 1 2 1 1 1 3 1 2 4 1 3 3 1 4 3 2 5
NO YES NO YES
7 6 3 4 1 2 5 1 1 1 5 1 1 1 1 2 2 3 1 4 1 6 3 4 1 5 3 4 7
YES NO YES