#K84382. Session Manager
Session Manager
Session Manager
You are tasked with implementing a SessionManager
that manages user sessions for a web application. Each session is identified by a unique session id and has an associated timestamp. The program must support the following operations:
- create session_id timestamp: Create a session with the given
session_id
andtimestamp
(an integer). If the session already exists, do nothing. - update session_id new_timestamp: Update the timestamp of an existing session identified by
session_id
tonew_timestamp
. - delete session_id: Delete the session identified by
session_id
if it exists. - count start_timestamp end_timestamp: Count and output the number of sessions whose timestamp lies in the inclusive interval \( [start\_timestamp,\ end\_timestamp] \).
The input will consist of a series of operations. You must process each operation in order and for each count
operation, output the result on a new line.
Note: All timestamps are integers. The conditions for counting use the inequality
\( start\_timestamp \leq timestamp \leq end\_timestamp \).
inputFormat
The first line contains an integer n
representing the number of operations.
Each of the next n
lines contains an operation in one of the following formats:
create session_id timestamp
update session_id new_timestamp
delete session_id
count start_timestamp end_timestamp
outputFormat
For each count
operation, output the number of active sessions within the specified time frame on a new line.
9
create abc123 100
create def456 200
create ghi789 150
count 100 250
update abc123 300
count 100 350
delete ghi789
count 100 350
count 300 450
3
3
2
1
</p>