cswork / OA打开练习工作台

OpenAIOA #3

Chat Event Counts in Recent Window

估计中等可在线判题

考点(AI 标注)迭代器设计哈希计数双指针滑窗

Process EVENT and COUNT in input order. COUNT u c t counts only previously processed events with the same user and channel whose timestamps lie in the closed interval [t−15,t]. Timestamps are not guaranteed to be increasing, and events that appear later in the input must not be counted early; duplicate events are counted individually.

输入格式

The first line contains q, followed by q lines EVENT user chat timestamp or COUNT user chat timestamp. This site uses 1≤q≤100000; user and chat are 1..20 ASCII letters, digits, or underscores; 0≤timestamp≤10⁹, in minutes.

输出格式

First output the number of COUNT commands p, then output the p query answers in order, one per line. If there is no COUNT, output only 0.

样例 1

输入:

4
EVENT u c 0
EVENT u c 10
COUNT u c 15
COUNT u c 16

输出:

2
2
1

样例 2

输入:

4
EVENT u c 50
EVENT u c 0
COUNT u c 15
COUNT u c 50

输出:

2
1
1

样例 3

输入:

5
COUNT u c 3
EVENT u c 3
EVENT v c 3
EVENT u d 3
COUNT u c 3

输出:

2
0
1

样例说明

In Example 1 the query results are 2, 1; the endpoint 15 minutes earlier is included. In Example 2 the timestamps are out of order and future times are not counted, giving 1, 1. In Example 3 later events do not affect earlier queries, giving 0, 1.