New Year's '17 P1 - Mr. N and Presents

View as PDF

Submit solution


Points: 7 (partial)
Time limit: 0.5s
Memory limit: 64M

Author:
Problem type

Mr. N, a kind CS teacher, has decided to give out presents to his hard working students! He has decided that a harder working student should get priority over a student that has slacked off. Unfortunately, some of Mr. N's students are trolls, and Mr. N will remove them from his list if he sees fit. Hoping to move up Mr. N's list, you decide to write a program to order the list.

Input Specification

The first line will have an integer Q (1 \le Q \le 10^5), the number of queries that follow.
Lines 2 \dots Q + 1 will each contain one of three possible queries:

  • F x: add student x to the beginning of the list
  • E x: add student x to the end of the list
  • R x: remove student x from the list. x is guaranteed to be a student already in the list.

x is an integer 1 \le x \le 10^9.

Output Specification

Output the list, from beginning to end, with each number on a new line. It is guaranteed that the list will only contain distinct integers.

Subtasks

For 20\% of points, Q \le 1\,000 and each x satisfies 1 \le x \le 10^6.

Sample Input

5
F 1
F 2
R 1
E 3
E 1

Sample Output

2
3
1

Comments


  • 1
    Kirito  commented on Jan. 24, 2024, 6:10 p.m.

    A new testcase has been added to kill unintended solutions, and the time limit has been dropped to 0.5s.


  • 1
    kh0i  commented on March 14, 2022, 3:45 a.m.

    Is this test valid?

    2
    F 1
    E 2

    The correct output is

    1
    2

    but polyglot's submission output

    2

    only.


  • 1
    pto1026  commented on Nov. 3, 2021, 1:51 a.m.

    Hey can anybody take a look at my submission and explain what I have done wrong here.


    • 4
      uselessleaf  commented on Nov. 4, 2021, 1:14 a.m. edited

      What happens if x has more than 1 digit?

      Also, in the future, you can ask for help in the dmoj discord.


  • 4
    cardistryMagic  commented on Jan. 1, 2017, 11:28 p.m.

    Sorry, this is my first contest. Is the clipboard supposed to show us the program's output or is it disabled? My clipped solution is blank and I don't think it's my program.


    • 4
      Kirito  commented on Jan. 1, 2017, 11:38 p.m.

      Your output is clipped, meaning that it doesn't show the full output. For most contests on DMOJ, no output is shown at all.


  • 1
    onlyIfStatement  commented on Jan. 1, 2017, 6:52 p.m. edited

    I have the sample case working but I instantly get WA when I test

    A little new to C++ so i have no clue what im doing wrong, thanks!

    EDIT: Never mind i'm just bad at copying and pasting :) Happy new year


  • 0
    RezaSi  commented on Jan. 1, 2017, 2:47 p.m.

    this test is valid?

    5
    F 1
    F 1
    R 1
    E 3
    E 1

    • 1
      Revolution  commented on Jan. 1, 2017, 2:51 p.m.

      I don't think so because on the problem statement it says "It is guaranteed that the list will only contain distinct integers".


      • 0
        RezaSi  commented on Jan. 1, 2017, 3:07 p.m.

        it can be ... the last list of my test is distinct(output)


    • 1
      imaxblue  commented on Jan. 1, 2017, 2:50 p.m.

      No, because students that are already in the list cannot be inserted again. Also, students that are not in the list cannot be erased


    • 1
      Kirito  commented on Jan. 1, 2017, 2:50 p.m. edited

      No, since 1 is inserted twice without being removed in between.


      • 1
        RezaSi  commented on Jan. 1, 2017, 3:07 p.m.

        ok ... tnx ...