Once when I was little, my father took me to a tobacco shop! It is surprising, but true. He asked the shopkeeper to give me some empty packets of cigarettes. The shopkeeper obliged and gave me a lot of empty packets in a bag. I took them back home and my brother showed me how to make domino out of the packets. Since then, domino had become an important part of my pastime.
Here's how you play domino, you place cigarette boxes one after the other. The boxes are placed in such a way that if you drop the first box with your hand, it will touch the second box. As a result, the second box will fall, which will touch the third box. Thus, the third box will fall as well. The process continues until all the boxes are dropped. This process is famously called the domino effect. If you search the YouTube, you will be able to see a plenty of amazing domino videos.
Now placing dominoes one after the other might be very tricky. If a domino is placed too far forward from the next one , then will not be able to touch the domino when it falls. As a result, the domino and the ones after that will not fall and the game will not end. In this problem, we will use our programming skill to predict the outcome of this beautiful game.
Let us imagine that we have dominoes. These dominoes are placed from left to right in sequential order. The 0-th domino is placed at the leftmost position and the -th domino is placed at the rightmost position. The -th domino is placed at a certain place pi and has a height of . Now, if we tilt the -th domino towards right, it will touch and drop all the dominoes to its right, if they are reached. Formally, the -th domino will drop the -th domino if the following condition is satisfied:
If the j'th domino is dropped, it will drop towards right and continue to domino effect as long as possible.
Now you will be given the number of dominoes that you have, the position and height of each of the dominoes. You have to answer queries of the following form: if the -th domino is dropped towards right, how many dominoes will fall as the result of the domino effect.
The first line contains an integer (), the number of domino pieces available. The next line contains integers (), the the height of each of the dominoes in sequential order. The next line contains integers (), the position of the dominos in sequential order. You can safely assume that the positions will be given in increasing order.
The next line contains an integer (), the number of queries to perform. The following lines will contain one integer (), the index of the domino that we want to tilt.
For each query, output an integer, the number of dominoes that will fall if the -th domino is tilted.
3 5 3 1 1 3 5 3 3 2 1
1 2 3
Login to submit