RobloxOA #9
Implement a Rate Limiter
估计中等可在线判题
Rate-limit requests by key. The original problem allows fixed-window or sliding-window, requiring only consistency with the examples; this site explicitly uses a fixed window: the window number is floor(timestamp/window), and each key may have at most limit requests allowed within one window number. Rejected requests do not consume quota.
输入格式
The first line contains window limit q; then q lines of timestamp key. Added by this site: timestamp is a non-negative integer and non-decreasing, and key contains no spaces; 1≤q≤200000, 1≤window≤10^9, 1≤limit≤10^5.
输出格式
For each request, output ALLOW or REJECT, separated by spaces.
样例 1
输入:
10 2 6
1 alice
2 alice
3 alice
11 alice
12 alice
12 bob
输出:
ALLOW ALLOW REJECT ALLOW ALLOW ALLOW
样例 2
输入:
5 1 5
1 u
1 u
2 u
6 u
6 u
输出:
ALLOW REJECT REJECT ALLOW REJECT
样例 3
输入:
3 2 4
0 x
1 x
2 x
3 x
输出:
ALLOW ALLOW REJECT ALLOW