TCCC '24 November P1 - Library Conundrum

View as PDF

Submit solution

Points: 3
Time limit: 1.5s
Memory limit: 256M

Author:
Problem type

A library in a small town has all of its N books in a massive stack due to the laziness of the librarians.

Regardless, many readers come and go every day, with M readers on this particular day. When the readers borrow books, they always take the topmost books. When the readers return books, they always put their books on top of the stack. Each book has a number assigned to it, with the books in the original stack being numbered 1 to N from bottom to top. Different books can have the same number.

Bob plans to visit the library, but, being a picky reader, he wants to know what number the topmost book has. He will only visit if the number is a multiple of a specified integer K. Help Bob figure out if he should go!

Input specification

The first line will contain N (1\le N\le 10^5), the number of books originally in the stack, M (1\le M\le 10^3), the number of readers, and K (1 \le K \le 100).

The next M lines begin with a character c_i, which will either be B (borrow) or R (return). If it's a borrow, it will be followed by an integer b_i (1\le b_i\le 100) denoting how many books the reader borrowed. If it's a return, it will be followed by an integer r_i (1\le r_i\le 100), followed by r_i integers n_i (1\le n_i\le 10^6), denoting the numbers of the books returned, in the order they are placed.

It is guaranteed that no one will borrow more books than possible.

Output specification

Print YES if the number of the top book is a multiple of K and NO otherwise.

Sample Input

10 3 5
B 3
B 4
R 2 8 5

Sample Output

YES

Explanation for Sample Output

The number of the topmost book is 5, which is divisible by 5.


Comments

There are no comments at the moment.