#K43117. Calculate Employee Working Hours

    ID: 27239 Type: Default 1000ms 256MiB

Calculate Employee Working Hours

Calculate Employee Working Hours

You are given a series of log entries that record the login and logout events of employees. Each log entry consists of an employee ID, a timestamp, and an action (either login or logout). For each query, you must calculate the total working hours for a specified employee, but only count the time intervals that fall within the given query period.

If a work session (from login to logout) only partially overlaps with the query period, only the overlapping duration should be considered. The final working hours must be rounded to two decimal places.

The time format used is YYYY-MM-DD HH:MM. You may assume that every login will eventually have a corresponding logout.

Hint: When calculating the overlapping time between two intervals, you can use the formula:

$$\text{overlap} = \max(0, \min(T_{logout}, T_{query\_end}) - \max(T_{login}, T_{query\_start})) $$

inputFormat

The input is given from stdin in the following format:

N
log1
log2
... (N lines of logs)
Q
query1
query2
... (Q lines of queries)

Each log is a string in the format: emp_id YYYY-MM-DD HH:MM action (where action is either login or logout).

Each query is a string in the format: emp_id YYYY-MM-DD HH:MM YYYY-MM-DD HH:MM, which represents the employee ID, the start timestamp, and the end timestamp of the period for which you need to calculate working hours.

outputFormat

For each query, output a single line to stdout representing the total working hours (as a floating point number rounded to two decimal places) for the specified employee within the given time range.

## sample
12
emp1 2023-10-01 09:00 login
emp1 2023-10-01 17:00 logout
emp2 2023-10-01 10:00 login
emp2 2023-10-01 18:00 logout
emp1 2023-10-02 09:00 login
emp1 2023-10-02 17:00 logout
emp2 2023-10-02 10:00 login
emp2 2023-10-02 18:00 logout
emp1 2023-10-03 09:00 login
emp1 2023-10-03 17:00 logout
emp2 2023-10-03 10:00 login
emp2 2023-10-03 18:00 logout
3
emp1 2023-10-01 00:00 2023-10-02 23:59
emp2 2023-10-02 00:00 2023-10-03 23:59
emp1 2023-10-01 00:00 2023-10-01 23:59
16.00

16.00 8.00

</p>