← 返回 roblox 的题目列表Rate Limit by Multiple Request Fields (Per-Field / Multi-Dimensional)
类型:online_judge
Building on Part 1, each request now contains multiple fields (e.g., userId, deviceId, endpoint). You need to rate limit each field separately, with multiple dimensions enforced simultaneously.
For each field dimension:
For the same field value, allow at most limit requests within window seconds.
Decision rule: a request is ALLOWed only if it does not exceed the limit in any dimension; otherwise REJECT.
Design the data structures and interface, and implement processing for a sequence of requests.
Input format (one possible online-judge style)
First line: integers m n
m: number of fields to rate limit
n: number of requests
Next m lines: fieldName window limit
Next n lines: timestamp followed by m field values (in the same order as the rules)
Output format
Print n lines, each being ALLOW or REJECT.
Constraints (suggested)
1 <= m <= 10
1 <= n <= 2e5
Each field value is a string without spaces
Example
Input:
2 6
user 10 2
device 10 3
1 u1 d1
2 u1 d1
3 u1 d1
4 u2 d1
11 u1 d1
12 u1 d1
Output:
ALLOW
ALLOW
REJECT
ALLOW
ALLOW
ALLOW
Example
Input
2 6
user 10 2
device 10 3
1 u1 d1
2 u1 d1
3 u1 d1
4 u2 d1
11 u1 d1
12 u1 d1
Output
ALLOW
ALLOW
REJECT
ALLOW
ALLOW
ALLOW