oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • About
    • Terms of Use
    • Technical Specifications
    • Credits

medianheap Batch , stdin/stdout

Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

medianheap.html

Problem Description

Remember the priority_queue data structure that pops out the greatest element every time? Now, you have to implement a data structure that is similar to priority_queue, but does not pop out the greatest element, but pops out the element according to the following rules:

  1. If the size of the queue is odd, pop out the middle element. (i.e. the median)
  2. Otherwise, pop out the element to the left of the middle.
Given a list of PUSH and POP instructions, output the resultant queue in ascending order.

Input

The first line of input will contain N, the number of instructions.
The following N lines of input will contain either a PUSH x, where you will be required to push an integer x into the queue, or a POP instruction, where you will be required to pop an integer out of the queue according to the instructions above.

Output

Your output should contain a list of space-seperated integers, which represents the resultant queue in ascending order.
Your output should be terminated with a newline.

Limits

Subtask 1 (36%): 1 ≤ N ≤ 1 000
Subtask 2 (64%): 1 ≤ N ≤ 1 000 000
Subtask 3 (0%): As per sample testcases

Sample Input 1

5
PUSH 5
PUSH 2
POP
PUSH 3
PUSH 9

Sample Output 1

3 5 9

Tags

Data Structure

Subtasks and Limits

Subtask Score #TC Time Memory Scoring
136201s256MBMinimum
264212s256MBMinimum
3011s256MBMinimum

Judge Compile Command

g++-8 ans.cpp -o medianheap -Wall -Wshadow -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512

Accepted Submissions

subIDUserTimeMax Time

Past Submissions

subIDUserTimeScore
mrJudge 09.05.20
Copyright © 2020 mrJudge. All rights reserved.