Editorial
Computing completion times
Let be the completion time of the last submission ever inserted into server . When a submission with judging time is inserted into server at time , its start and completion times are
Then update to the new completion time. Because each server processes its queue in FIFO order, the actual queue does not have to be stored.
Different servers work simultaneously, so submission-query order and completion order may differ. Store every completion event in a min-heap ordered by completion time. Before processing a query at time , pop and apply every event whose completion time is at most .
Completion times can become much larger than the input bound on . Many submissions of judging time can wait on one server, so completion times must be stored in 64-bit integers.
Per-problem ranking
The comparison key of a completed submission is
Only the best submissions of each problem are ever needed. For every problem, keep a sorted vector containing at most those records. Insert a newly completed record, sort the vector, and remove the last record if the size becomes .
A record that has already fallen out of the best can never return later, because inserting additional records cannot improve its relative position. Therefore each problem stores only records.
User ranking
For every user , maintain:
- : the current number of solved problems;
- : the time at which the user achieved the current solved count.
The user-ranking key is
Store these keys in a std::set; iterating from the beginning gives the ranking order.
When a user solves a new problem for the first time, remove the old key, increase by one, set to that submission's completion time, and insert the new key.
Multiple submissions by the same user to the same problem must increase the solved count only once. Store completed pairs in a hash set, and update the user ranking only when a pair is inserted for the first time. The duplicate check must be made at completion time, not at submission time: a later submission to the same problem may finish earlier on another server.
Every completed submission is still inserted independently into the per-problem ranking.
Processing queries
For a query at time , first apply all completion events with completion time at most .
- For type , compute the new completion time using the server's last completion time and push the event into the min-heap.
- For type , print the stored best records of the requested problem.
- For type , print at most the first entries of the user-ranking set.
Subtasks
For subtask 1, it is sufficient to rescan and sort all relevant completed submissions for every output query. Since the aggregate is at most , an solution fits.
For subtask 2, there is only one server and no type- query. Completion order equals submission order, so a queue of completion events and the best records of each problem are enough.
For subtask 3, no user ranking is needed. Use a min-heap for completion events and maintain only the best records per problem.
For subtask 4, there is one server, no type- query, and every pair is submitted at most once. A queue of completion events and the user-ranking set are sufficient.
For subtask 5, every pair is unique, so the completed-pair hash set is unnecessary. Maintain the event heap, per-problem top , and user-ranking set.
For the full constraints, add the completed hash set.
Complexity
Each submission is inserted into and removed from the completion-event heap once. User-ranking updates cost , while updating a per-problem vector of size at most costs .
The complexity of one test case is time and memory. The aggregate bounds keep the total workload within the limits.
Solution written by GPT5.6