The Great Battle
Time limit5sMemory limit1024 MB
Given gods with strengths, handle range decrements and, for each query, find which god in a range first drives Kratos's power to zero.
- Level
Medium7 of 10
- Topics
- Segment tree, Simulation
- Solved
- No attempts yet
Statement
Recovering from the last fight, Kratos sets out on another journey. He decides to climb Mount Olympus together with the Titans and fight the greatest battle yet.
At the summit he sees gods. After watching them, Kratos sizes up the strength of each one. God number has strength .
Fighting gods is hard, so after a battle with god , Kratos's power becomes . When drops to zero, Kratos dies.
Over time, some gods standing next to each other grow tired, and their strength drops by one. In other words, a query means that for every god at position through , .
During the fight, Kratos makes plans. Plan number means Kratos fights gods in order, starting with power . For each plan he wants to know whether he survives it. If he dies, he wants to know which god lands the last blow.
For each plan, print the number of the god who kills Kratos. If Kratos survives, print <<-1>>.
Input
The first line contains two integers and , the number of gods and the number of queries (). The second line contains integers , the strengths of the gods (). Each of the next lines is a query, and its first number is the type .
If , two integers and follow (). The strength of the gods from to decreases by one.
If , three integers , , and follow: the number of the first god, the number of the last god, and Kratos's starting power for this plan (, ).
Output
For each query of type 2, print the number of the god who kills Kratos. If Kratos is still alive after the plan, print <<-1>>.
Hint
In the first query of the first sample, Kratos starts with power 61. After the first fight, it is . Then the power becomes 30, 10, 5, 1, 1, and 1 in turn.