Video Clips
Time limit2sMemory limit1024 MB
For each starting video index, find which video a viewer reaches after watching M videos, where the next video after i is S[i].
- Level
Medium6 of 10
- Topics
- Graph, Binary search, Implementation, Array
- Solved
- No attempts yet
Problem
On a popular web site, the KATT contestants watch cat videos between solving problems.
The site has videos of cats jumping around on a keyboard, numbered from to . When a contestant finishes a video, the site suggests the next cat video, and the contestant of course clicks it and starts watching.
You are given the cat video each contestant watches first. Find the -th video each contestant watches.
Input
The judge reads input in the following format:
- line :
K M - line :
S[0] ... S[K - 1] - line :
N: the number of calls made toclip(I). - line :
I1 ... IN: the parameters of the calls toclip(I).
Output
The judge writes lines with the return values of clip(I).