Punch-in comp sheet
MediumOnline Assessment
Work out which recorded take of each instrument is heard in which bars of the finished song, once the engineer has punched in fixes and scrapped bad takes.
A song is a sequence of numbered bars. The session log lists the engineer's actions in the order they happened:
"rec <track> <take> <first>-<last>"records take numbertakeon the track (for example"rec vox 3 17-24"), covering barsfirstthroughlast, both inclusive. The new take overwrites whatever was audible on that track in those bars; bars outside the range are not affected. Each take number is recorded at most once per track, and takes need not be recorded in increasing order."scrap <track> <take>"throws that take away completely. Whatever was audible in the bars the scrapped take covered becomes the most recently recorded take that still covers each of those bars, and if there is none, those bars fall silent. Ascrapof a take that has not been recorded yet at that point of the log, or has already been scrapped, does nothing (a take recorded later is kept).
Tracks are independent. Bars no kept take covers are silent.
Input: log, a list of action strings.
Output: one string per track that has at least one audible bar, ordered by track name (ordinary string order): the track name followed by its audible stretches from the first bar to the last, each written <take>@<first>-<last> and separated by single spaces, such as "vox 1@1-16 3@17-24". A stretch is a maximal run of consecutive bars heard from the same take; two stretches of the same take with another take in between stay separate. Return [] if nothing is audible.
Example 1
- Input:
- [["rec vox 1 1-32","rec vox 2 9-12","rec vox 3 12-20","rec bass 1 1-32","scrap vox 2"]]
- Output:
- ["bass 1@1-32","vox 1@1-11 3@12-20 1@21-32"]
- Explanation
- On
vox, take 1 covers bars 1-32, take 2 punches in over 9-12, and take 3 over 12-20 overwrites bar 12 of take 2. Scrapping take 2 uncovers bars 9-11, where the most recently recorded kept take is take 1 again (bar 12 stays with take 3). Sovoxreads1@1-11 3@12-20 1@21-32;basshas take 1 alone.
Example 2
- Input:
- [["scrap vox 2","rec vox 2 20-24","rec vox 1 1-16","rec vox 3 3-6","scrap vox 3","scrap vox 3","rec gtr 7 1-4","scrap gtr 7","rec gtr 4 10-10"]]
- Output:
- ["gtr 4@10-10","vox 1@1-16 2@20-24"]
- Explanation
- The first
scrap vox 2comes before take 2 exists and does nothing, so take 2 (bars 20-24) is kept. Take 1 covers 1-16; take 3 punches in over 3-6 but is scrapped, which uncovers take 1 there (the repeated scrap does nothing). Ongtr, take 7 is scrapped and leaves silence, and take 4 covers bar 10 only. Tracks are ordered by name, so the result isgtr 4@10-10, thenvox 1@1-16 2@20-24.
Example 3
- Input:
- [["rec vox 1 1-4","scrap vox 1","scrap vox 1"]]
- Output:
- []
- Explanation
- Take 1 is scrapped and nothing else was recorded, so there is no audible bar and the result is empty.
Constraints
0 <= log.length <= 500- track names are non-empty lowercase strings;
takeis an integer from1to100,000; each take number is recorded at most once per track 1 <= first <= last <= 1,000,000