#C9514. User Session Manager

    ID: 53616 Type: Default 1000ms 256MiB

User Session Manager

User Session Manager

This problem simulates a session manager for an e-commerce platform. The system supports three operations:

  • login <user> <time>: A user logs in at an absolute time. Before logging in, the system clears any sessions that have expired. An active session expires if the difference between the current time (provided as the parameter in case of login, or accumulated via tick operations) and the user's last activity is \(\geq 5\) time units.
  • logout <user>: The user logs out and his/her session is removed immediately.
  • tick <time>: Advances the system clock by the specified number of time units and removes any sessions that have expired.
  • get: Outputs the list of currently active sessions in lexicographically (alphabetically) sorted order. The usernames should be printed on one line separated by a single space. If no active sessions remain, output an empty line.

Note that when a user logs in, its login time is used to check for expiry immediately before logging in (i.e. sessions where current_time - last_active \ge 5 are removed). The tick operation updates the global current time accordingly and performs a similar cleanup using the updated time.

The input is processed from standard input (stdin) and the results of the get operations are printed to standard output (stdout).

inputFormat

The first line of input contains an integer N representing the number of operations.

The next N lines each contain one of the following commands:

  • login <user> <time>
  • logout <user>
  • tick <time>
  • get

All time values are integers. It is guaranteed that the commands are provided in a valid order.

outputFormat

For each get command in the input, output a single line containing the space-separated list of active sessions sorted in lexicographical order. If no active sessions exist, output an empty line.

## sample
5
login user1 1
get
tick 3
get
tick 2
get
user1

user1 user1

</p>