Hotel Rooms
InterviewTime limit1sMemory limit1024 MB
Given n hotel rooms and a list of reservations, the task is to answer how many rooms in each queried range are still free.
- Level
Easy3 of 10
- Topics
- Segment tree, Array
- Solved
- No attempts yet
Problem
When the UCF Programming Team travels, the coaches would like to get hotel rooms that are close to each other. There is a hotel where rooms are numbered 1 through n, and these rooms are in a straight line. Room 2 is next to Room 1, Room 3 is next to Room 2, and so on. So, it is easier to find a large number of available rooms that are close to each other.
Given the room reservations, determine the availability of rooms to accommodate the UCF Programming Team (a large group).
Input
The first line contains two integers: (), the number of hotel rooms, and (), the number of transactions. Each of the next lines contains one transaction. There are two types of transactions:
- Room Reservation: the line starts with the letter R, followed by one space and a valid room number. This transaction reserves the given room. The room is not already reserved.
- Group Room Availability: the line starts with the letter A, followed by one space, a valid starting room number, one space, and a valid ending room number. This transaction asks how many rooms are available in the given range. The ending room number is not less than the starting room number.
Output
There is no output for the room-reservation transactions. For each group room availability transaction, output a separate line with the total number of available rooms in the requested range.