While coding the OJ judge system last year, Rar the Cat has encountered a problem with coding the judge queue and needs your help.
In this hypothetical scenario, there will be up to N submissions in total, each with a unique submission id (subID).
However, each submission should be in the queue with a different priority. Rar the Cat thus wants 4 ways to add a submission to the queue.
The 4 ways are:
- void push_front (int subID) : Queue a submission of subID to the front of the queue
- void push_back (int subID) : Queue a submission of subID to the back of the queue
- void insert_before (int subID, int ref) : Queue a submission of subID before the submission with subID of 'ref'
- void insert_after (int subID, int ref) : Queue a submission of subID after the submission with subID of 'ref'
Furthermore, there are also 4 ways for the judge to inspect or access the queue.
The 4 ways are:
- int queue_front () : Returns the subID of the submission at the front of the queue
- int queue_back () : Returns the subID of the submission at the back of the queue
- int sub_before (int ref) : Returns the subID of the submission just before the submission with subID of 'ref'
- int sub_after (int ref) : Returns the subID of the submission just after the submission with subID of 'ref'
In addition, the judge also needs to update the queue when a submission has been graded. There are 3 ways for the judge to update the queue:
- void pop_front() : Deletes the first submission of the queue
- void pop_back() : Deletes the last submission of the queue
- void erase (int subID) : Delete the submission with 'subID' from the queue
It's now your job to implement all these functions!
Furthermore, an initialize function (void init(int X, int N) ) will also be called before any of the above functions are called. You can put any initialization code here.
This is a function call question, there is a template provided under Attachments. Please use that template, you do not need to declare int main() or input from file.
For testing purposes, you may uncomment the int main() from the template. Please remember to comment it back when submitting the problem.
Unless otherwise specified, 0 < N ≤ 1000000 for each testcase, this means that subID can range from 1 to N
X will be the maximum number of function calls for each testcase. The limits of X will be addressed in the subtask section.
It is guaranteed that the system will not attempt to add any submissions that are already in the queue into the queue again. However, a submission can be requeued after it has been deleted from the queue previously.
Subtask 1 (33%): X ≤ 10,000,000, There will only be the following functions: queue_front, push_back, pop_front
Subtask 2 (31%): X ≤ 10,000,000 There will not be the following functions: insert_before, insert_after, erase.
Subtask 3 (36%): X ≤ 10,000,000
Subtask 4 (0%): Sample Testcase
The first line of input (for your grader) will consist of 2 integers, X followed by N, where N is the maximum of all the subIDs in the problem.
insert_after 4 1
insert_before 5 4