← 返回 citadel 的题目列表Design Token Expiration Manager
类型:online_judge
Problem: Design a Token Expiration Manager
Design a token manager. Every token has a fixed time-to-live value ttl.
Support the following operations:
generate tokenId currentTime
Generate a new token at currentTime. Its expiration time is currentTime + ttl.
renew tokenId currentTime
If tokenId exists and is not expired at currentTime, update its expiration time to currentTime + ttl.
If the token does not exist or has already expired, ignore the operation.
count currentTime
Return the number of tokens that are not expired at currentTime.
If a token expires at expireTime, it is considered expired when currentTime >= expireTime.
Input Format
The first line contains two integers:
ttl q
where ttl is the token time-to-live and q is the number of operations.
The next q lines contain operations in one of the following formats:
generate tokenId currentTime
renew tokenId currentTime
count currentTime
Output Format
For each count operation, print one integer on its own line.
Constraints
1 <= ttl <= 10^9
1 <= q <= 10^5
1 <= currentTime <= 10^9
currentTime is non-decreasing
tokenId consists of letters and digits, with length at most 20
Example
Input:
5 6
generate aaa 1
renew aaa 2
count 6
generate bbb 7
renew aaa 8
count 10
Output:
1
1
Example
Input
5 6
generate aaa 1
renew aaa 2
count 6
generate bbb 7
renew aaa 8
count 10
Output
1
1