#P2161. Meeting Room Reservation System

    ID: 15442 Type: Default 1000ms 256MiB

Meeting Room Reservation System

Meeting Room Reservation System

PP Building has a single auditorium which can be reserved for meetings by companies or organizations. Most meetings require several consecutive days (some only need one day). However, since there is only one auditorium, the reserved time intervals must not overlap. In particular, if a meeting is scheduled from day \(s\) to day \(e\), then any other meeting must satisfy either \(e < s'\) or \(e' < s\) (i.e. the previous meeting ends strictly before the next meeting starts). For example, if a meeting is scheduled from day 10 to day 15, then a subsequent meeting can only start on day 16 or later.

Due to economic considerations, sometimes the management might cancel one or several previously accepted reservations in order to accept a new reservation. Your task is to implement a system that processes two types of operations:

  • A operation: A new reservation request for the period from start day to end day arrives. In doing so, all existing reservations that conflict (i.e. whose time intervals overlap with the new reservation) are cancelled. The system should output the number of reservations cancelled because of this new request.
  • B operation: The system should output the current total number of valid (i.e. non-cancelled) reservations.

All dates are given as integers. Two intervals \([s, e]\) and \([s', e']\) do not conflict if \(e < s'\) or \(e' < s\); otherwise, they conflict. Note that when processing an A operation the new reservation is always added (even if it conflicts with previously reserved intervals, which are then cancelled).

inputFormat

The first line contains an integer (Q) representing the number of operations. Each of the following (Q) lines represents an operation. An operation is either in the form:

A start end

or

B

For an "A" operation, start and end are integers denoting the reservation period. For a "B" operation, simply output the total number of currently valid reservations.

outputFormat

For each operation that requires an output (i.e. both A and B operations), output the corresponding integer on a separate line. For an "A" operation, output the number of cancelled reservations. For a "B" operation, output the current number of valid reservations.

sample

3
A 10 15
B
B
0

1 1

</p>