Delayed Signals (Delay) : OIS2021 - Round 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

O I ( ) OIS2021 – Round 2 

; + + S Online, December 15th, 2020 delay • EN

Delayed Signals (delay)


Giorgio loves playing with delays to compose electronic songs! A delay is an electrical component that
takes two inputs: a musical signal, which is a sequence St for t = 0 . . . N − 1 of integer values, and the
delay amount, which is also a sequence Dt for t = 0 . . . N − 1 of integers (it can change over time!).
As output, the delay component produces the exact same values appearing in the input musical signal,
in the correct order, possibly skipping some of them and repeating others, in order to match as much as
possible the requested delay. We say that the integer Ot in output at time t has a delay of x if it is equal
to the input musical signal St−x . At every time step t, the delay component chooses the value of x closer
to Dt which produces a value coming no earlier than Ot−1 in the original sequence.
This delayed version of the input musical signal is
very useful to create psychedelic echo effects.
Giorgio had a pedal applying delays to his musi-
cal tracks, but it just broke and now he wants to
replace it with a software version. Help Giorgio
compute the output of a delay component!
For example, suppose that the delay amount is
fixed to 2 and the input sequence is:

0 5 8 9 7 10 4 1.

Then, the delayed output is:


Figure 1: Giorgio’s broken delay pedal.
0 0 0 5 8 9 7 10,

since it reports the same values as the original sequence in order, repeating the first three times and
skipping the last two, with every integer in output being produced with the requested delay of two
(except for the first with a delay of zero and the second with a delay of one, which are the maximum
delays possible).
Suppose now that the delay amount is varying over time: 5 4 3 2 1 0 2 1, with the same input se-
quence. Then, the most accurate output is:

0 0 0 5 9 10 10 4.

The first three values are 0, with delays 0, 1, and 2 respectively, which is as close as you can get to
the requested 5, 4, 3. The following values 5, 9, 10 match exactly the requested delays of 2, 1 and 0
respectively. The following value, 10, has a delay of 1 (instead of the requested 2), which is as much
as possible given that you have to respect the order of the original sequence. Finally, 4 conclude the
sequence with the requested delay of 1.

+ Among the attachments of this task you may find a template file delay.* with a sample
incomplete implementation.

Input
The first line contains the only integer N . The second line contains N integers St . The third line contains
N integers Dt .

delay Page 1 of 2
Output
You need to write a single line with N integers Ot : the delayed signal.

Constraints
• 1 ≤ N ≤ 100 000.
• −109 ≤ St ≤ 109 for each t = 0 . . . N − 1.
• 0 ≤ Dt < N for each t = 0 . . . N − 1.
• The integers in the input sequence St are all distinct.

Scoring
Your program will be tested against several test cases grouped in subtasks. In order to obtain the score
of a subtask, your program needs to correctly solve all of its test cases.
– Subtask 1 (0 points) Examples.

– Subtask 2 (30 points) N ≤ 100 and Dt = Dt0 for every t, t0 .

– Subtask 3 (20 points) N ≤ 1000.

– Subtask 4 (15 points) Dt = Dt0 for every t, t0 .

– Subtask 5 (35 points) No additional limitations.


Examples
input output

8 0 0 0 5 8 9 7 10
0 5 8 9 7 10 4 1
2 2 2 2 2 2 2 2

8 0 0 0 5 9 10 10 4
0 5 8 9 7 10 4 1
5 4 3 2 1 0 2 1

delay Page 2 of 2

You might also like