← 返回 citadel 的题目列表Token Expiry and Reset Management Problem
类型:online_judge
citadel
Authentication Token Problem
Upon user login, a token is issued. If the expiryLimit is exceeded, it becomes invalid unless reset within the validity period, in which case the deadline is extended.
Valid tokens can be reset repeatedly, but the reset operation is ignored for expired or non-existent tokens. Expired tokens can no longer be used.
Command Format:
[type, token_id, T]
Where:
type 0 (create): Create a token, setting expiry to T + expiryLimit
type 1 (reset): Extend token expiry to T + expiryLimit
Start with no tokens and process requests sequentially to determine how many remain valid at the maximum time point.
Example Input:
expiryLimit = 4
commands = [[0, 1, 1], [0, 2, 2], [1, 1, 5], [1, 2, 7]]
- `[0, 1, 1]`: At `T = 1`, create `token_id = 1` with expiry `1 + 4 = 5`.
- `[0, 2, 2]`: At `T = 2`, create `token_id = 2` with expiry `2 + 4 = 6`.
- `[1, 1, 5]`: At `T = 5`, reset `token_id = 1`. Still valid (`T ≤ 5`), so new expiry `5 + 4 = 9`.
- `[1, 2, 7]`: At `T = 7`, reset `token_id = 2`, but it expired at `T = 6`, thus ignored.
At T = 7, only token_id = 1 is valid, so return 1.
Example
Input
4
[[0, 1, 1], [0, 2, 2], [1, 1, 5], [1, 2, 7]]