Vault Robbery
Time limit3sMemory limit1024 MB
Find the maximum loot on a route that ends at building E, moving only to visible buildings and never robbing two consecutive visited buildings, as values and E change over Q updates.
- Level
Hard8 of 10
- Topics
- Tree, Dynamic programming, Segment tree
- Solved
- No attempts yet
Statement
The capital of GSHS country has buildings in a row, numbered from left to right. The height of building is , and all building heights are distinct. Each building has a vault on its roof, and the vault in building holds won. and are positive integers.
You are a thief who robs the vaults of the capital. You start on the roof of any building and move between buildings while robbing vaults. After the robbery, your helper sends a helicopter to the roof of building to take you out of the city. So the last building you reach must be building . For safety, you must follow these rules.
- To move from building to building , building must be visible from the roof of building . Building is visible from building if every building between them (including buildings and ) has height at most the height of building . Otherwise, another building blocks the view.
- While moving, you may rob at most one of any two consecutively visited buildings.
- For each visited building, your gain is if you rob it and 0 otherwise. The total gain is the sum of the gains over all visited buildings.
The building heights are fixed, but the vault values can change, and the helper's destination building can also change. Each time the information is updated, compute the maximum total gain you can earn under the rules above.
Input
The first line contains two integers and , separated by a space.
The second line contains integers , separated by spaces.
The third line contains integers , separated by spaces.
The fourth line contains an integer .
Each of the next lines is one of the following updates.
1 i c: the vault value in building changes to won.2 e: the helper's destination changes to .
Output
Print lines. The first line contains the maximum gain for the initial state. Line contains the maximum gain after applying the first updates ().
Constraints
- , and the are distinct.
Hint
You may start at the same building as .