The Staging
Time limit2sMemory limit512 MB
Given n gangsters each aiming at a distinct target, count survivors after each of q updates to the shooting time of one gangster.
- Level
Hard8 of 10
- Topics
- Graph, Dynamic programming, Sorting, Implementation
- Solved
- No attempts yet
Problem
Steven Byteberg is a movie director who specializes in action movies. He is now working on a new movie about the Byteonian Mafia wars. Byteberg wonders what the climax of the movie, a spectacular exchange of gunfire, should look like.
gangsters take part in this scene. For simplicity they are numbered from 1 to . When the tension reaches its peak, every gangster draws his weapon and takes aim at another gangster. Nobody is aimed at by more than one gangster. The gangsters are poor but well trained: each of them can shoot only once, and that shot is always accurate and always deadly.
At some point one of the thugs cannot stand the tension any longer, and the shooting starts.
The director has fixed the order in which the gangsters pull their triggers. Gangster shoots at gangster at exactly the moment , unless gangster has already been killed by then. A gangster is killed at exactly the moment someone shoots at him.
The director wants to know how many gangsters are alive at the end of the scene. Byteberg is not yet sure about the order in which the gangsters shoot. From time to time he orders one of the values to be changed. After every such change he wants to know how many gangsters survive under the new order, taking into account all changes made so far.
Input
The first line contains one integer (), the number of gangsters in the scene. The second line contains integers (, , and for ), where gangster aims at gangster .
The third line contains integers () describing the initial shooting order: the initial value of is .
The fourth line contains one integer (), the number of changes to that Byteberg plans. Each of the next lines describes one change. The -th of these lines contains two integers and (, ), meaning that the -th change sets to . The numbers are pairwise distinct.
Output
Print exactly lines. The first line contains the number of gangsters who survive the shooting under the initial order. The -th of the following lines contains the number of gangsters who survive when the shooting order is given by after the first changes have been applied.