Hold the Line
InterviewTime limit2sMemory limit1024 MB
Each update replaces the height at one position, and each query asks whether the whole line is in non-decreasing order.
- Level
Easy3 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Problem
Nick Fury decided that soldiers from the special forces unit of S.H.I.E.L.D. would help the Avengers fend off Loki's army. He will send soldiers into the attack, and all the others are needed elsewhere. All that remains is to choose which soldiers go.
Nick first picked soldiers at random and lined them up. Then he began replacing, one at a time, one of the selected soldiers with a soldier who is not currently in the line. The unit is large, and Nick does not know each soldier personally. He can judge the unit's fighting strength only by visible external signs. One important measure is whether the soldiers in the line stand in non-decreasing order of height.
Nick can issue two kinds of commands. The first command: a new soldier of height takes the place of the soldier standing at position . With the second command he asks whether the soldiers in the line stand in non-decreasing order of height. Process these commands and answer the queries.
Input
The first line contains two integers and (, ): the number of soldiers in the line and the number of commands Nick issues. The second line contains non-negative integers, none exceeding , the initial heights of the soldiers.
Each of the next lines is a command. If the line starts with !, two integers and follow (, ), meaning the soldier of height replaces the soldier at position . A line starting with ? is the second kind of command.
Output
For each second-type command, print <<YES>> on its own line if the soldiers in the line are currently in non-decreasing order of height, and <<NO>> otherwise.