Mr. N and Presents

View as PDF

Submit solution


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

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

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 1 \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


  • 0
    IanHu  commented on Dec. 24, 2018, 1:55 p.m.

    Any tips for how to solve if i get TLE in Batch #2? I have got AC in Batch #1 already. Thanks!


  • 0
    p1geon  commented on Dec. 23, 2018, 3:49 p.m.

    Shouldn't the input specifications say lines 2...Q + 1? Line numbers don't start from index 0 xd.


  • 1
    echofox  commented on Oct. 3, 2017, 10:52 a.m.

    anyone know why i'm getting an IR: ValueError? the only problem i can think of is with deque.remove, but the problem states that x is guaranteed to be a student in the list, so there shouldn't be anything wrong with that.


  • 0
    cardistryMagic  commented on Jan. 1, 2017, 6: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.


    • 0
      Kirito  commented on Jan. 1, 2017, 6: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.


    • 0
      imaxblue  commented on Jan. 1, 2017, 6:38 p.m.

      The judge will not show your output


  • 0
    jlsajfj  commented on Jan. 1, 2017, 2:19 p.m.

    With each number of a new line?


    • 0
      Kirito  commented on Jan. 2, 2017, 9:31 a.m.

      on

      My bad, has been fixed.


  • 0
    onlyIfStatement  commented on Jan. 1, 2017, 1: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
    Sirkular  commented on Jan. 1, 2017, 12:30 p.m.

    For 20% of points, N≤1000. You mean Q right?


    • 0
      Kirito  commented on Jan. 1, 2017, 12:37 p.m.

      Yes. Sorry about that.


  • 0
    RezaSi  commented on Jan. 1, 2017, 9:47 a.m.

    this test is valid?

    5
    F 1
    F 1
    R 1
    E 3
    E 1

    • 0
      Revolution  commented on Jan. 1, 2017, 9:51 a.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, 10:07 a.m.

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


    • 0
      imaxblue  commented on Jan. 1, 2017, 9:50 a.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


    • 0
      Kirito  commented on Jan. 1, 2017, 9:50 a.m. edited

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


      • 0
        RezaSi  commented on Jan. 1, 2017, 10:07 a.m.

        ok ... tnx ...