#C6100. Session Duration and Overlap Calculator

    ID: 49824 Type: Default 1000ms 256MiB

Session Duration and Overlap Calculator

Session Duration and Overlap Calculator

You are given a sequence of events representing user logins and logouts, each with an associated timestamp. Each session is formed by pairing a login event with the subsequent logout event. The duration of a session is defined as \( logout\_time - login\_time \). Two sessions are considered overlapping if the time period of one intersects with the time period of another.

Your task is to compute:

  • The total duration calculated as the sum of durations of all valid sessions.
  • The overlapping sessions. Each session is identified by its 1-based index corresponding to the order of the login events. If no sessions overlap, output the string "no overlap".

Important:

  • If a logout event appears when there is no corresponding login event, or if there remain unmatched login events after processing, the program should report an error by outputting Unmatched login events and terminate.

inputFormat

The input is read from stdin and is formatted as follows:

  • The first line contains an integer n, the number of events.
  • The next n lines each contain a string and an integer separated by space. The string is either "login" or "logout" and the integer represents the timestamp.

outputFormat

If the events form valid sessions:

  • The first line of output should contain the total duration (an integer).
  • The second line should contain either the string "no overlap" if there are no overlapping sessions, or the overlapping session pairs. Each pair should be output as two integers (representing the session indices) separated by a space. If there are multiple pairs, separate them with a semicolon and a space (i.e. pair1; pair2; ...).

If an error occurs (i.e. unmatched events), output the line Unmatched login events and terminate.

## sample
4
login 1
login 3
logout 5
logout 6
7

1 2

</p>