DMOPC '16 Contest 4 P3 - Carnival Phantasm

View as PDF

Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 256M

Authors:
Problem type

Molly, having finished the DMOPC, decides to go to a carnival! Noticing the candy apples on sale, Molly checks a map and finds the distance from the entrance to each stand, as well as which candy apples they're selling. Using the skills she has acquired from the DMOPC, she decides to model the stores as such:

  • A x k: The stand x now sells candy apple k.
  • S x k: The stand x no longer sells candy apple k, if it was previously doing so.
  • E x k: The stand x has decided to move locations, and is now a distance of k from the entrance. In addition, it is no longer selling any candy apples.
  • Q k: Print the closest stand that sells candy apple k, or -1 if it doesn't exist.

While Molly is perfectly capable of doing this herself, you also want some candy apples, and this might just be the perfect bribe...

Input Specification

Line 1: Two separated integers, N, and S, the number of stalls, and number of stalls that sell candy apples.

Line 2: N space separated integers di, the distance from the entrance to stall i.

Lines 3S+2 : Two space separated integers, si and ai, indicating that stall si sells candy apples of flavour ai.

Line S+3: An integer, Q, the number of queries Molly has.

Lines S+4S+Q+3: Any valid query, as described above.

Output Specification

For each Q query, print the answer on a new line.

Constraints

1N,S105

1di109

1siN

0ai100

1Q104

In the case of ties, print the stand with the smaller id.

Sample Input

Copy
5 3
1 2 3 4 5
2 1
3 1
5 3
4
Q 1
Q 3
S 2 1
Q 1

Sample Output

Copy
2
5
3

Comments


  • 2
    julian33  commented on Jan. 2, 2021, 11:57 p.m.

    Constraints on k are incorrect, please fix


  • 23
    IanWong  commented on Feb. 15, 2017, 3:18 p.m.

    Now you changed 0 <= a[i] < N. SERIOUSLY ? You guys didn't even comment or notice me the constraints are changed. I don't think this is appropriate. You just changed the constraints secretly and act like nothing had happened. I am very disappointed.


    • 14
      r3mark  commented on Feb. 15, 2017, 4:09 p.m.

      Kirito must now commit harakiri in apology.


      • -3
        Kirito  commented on Feb. 15, 2017, 4:28 p.m. edit 4

        The original constraints were 0ai<100, but in haste I messed up the problem statement. I apologise for not posting this earlier.

        @r3mark:

        Me RN


  • 2
    IanWong  commented on Feb. 15, 2017, 2:15 p.m.

    Seems like the constraints is wrong ?? Look at my latest submission.


  • 2
    pls  commented on Feb. 15, 2017, 1:31 a.m.

    Can stands sell more than one type of apple?


    • 1
      r3mark  commented on Feb. 15, 2017, 1:40 a.m.

      Yes.


  • 0
    BillZeng2k  commented on Feb. 14, 2017, 9:36 p.m.

    Sorry but can you clarify the constraints on k? Is it also < 100?


    • 0
      Kirito  commented on Feb. 14, 2017, 10:00 p.m.

      Yes.