JOI Spring Training Camp 2015/16
Original Statement / Submission Site
At the JOI conveyor belt sushi restaurant, sushi plates are delivered on a circular conveyor belt rotating counterclockwise. There are N customers, numbered 1 to N, seated counterclockwise in this order around the belt. Customer N is next to customer 1.
Each customer initially has one sushi plate. Each plate has a value called its price.
The restaurant holds a special time sale during which Q plates are served one by one. The i-th serving is described by a triple of integers (Si, Ti, Pi):
Note: In the case that Si = Ti, customer Si is the only one who performs Step (2).
You are in charge of washing plates at the restaurant. As plates are washed differently depending on their price, you want to know in advance the price of the plate retrieved by the chef after each serving.
Given the initial plates of each customer and the Q servings of the time sale, write a program to determine the price of the plate retrieved by the chef after each serving.
Print Q lines. The i-th line contains the price of the plate retrieved after the i-th serving.
6 7 8 6 7 4 5 9 2 4 5 4 1 4 6 2 7 1 5 2 3 4 8 4 3 1 3 1 3
7 9 8 7 8 6 5
4 2 5 2 4 7 1 4 3 1 4 1
7 5
10 10 19 5 8 17 14 3 9 10 7 6 1 8 4 7 3 2 5 9 10 4 8 3 10 3 6 8 7 4 6 6 3 2 9 12 6 3 7 9 6 3
19 10 14 17 8 10 3 12 7 9