Virus Simulator
Time limit3sMemory limit1024 MB
Process virus spreads that pass between people, vaccinations, and range queries for the largest sum of a block of consecutive people with positive immunity.
- Level
Hard8 of 10
- Topics
- Segment tree, Simulation
- Solved
- No attempts yet
Problem
In the spring of 2123, the Virus Simulator was finally released.
The Virus Simulator lets users set people's immunity and viruses' vitality, then run simulations directly. It was built to prepare for future virus outbreaks.
There are people in the simulator, numbered from to in order. The immunity of the -th person is .
You may perform one or more actions. There are three kinds: virus infiltration, vaccination, and group immunity measurement. Each action is given in the input as follows.
- Virus infiltration: . A virus with vitality infiltrates person . The virus spends vitality to reduce the infected person's immunity by . If, before the virus dies, the infected person has no immunity (that is, immunity is ) or loses it, the virus moves to the person with the highest immunity among people numbered greater than the current infected person. If several people tie, the virus moves to the one with the smallest number. This repeats until the virus's vitality reaches or no one is left to transfer to.
- Vaccination: . Person receives a vaccine with potency , and their immunity increases by .
- Group immunity measurement: . People through form groups. Groups consist of adjacent people. People with no immunity form groups only with others who have no immunity, and people with immunity form groups only with others who have immunity. Among the groups formed, find the maximum sum of immunity among a group's members.
Input
The first line contains two integers and , the number of people and the number of actions, separated by a space.
The second line contains integers , the immunity of each person, separated by spaces.
The next lines each give one action in the format above.
At least one group immunity measurement action is given.
Output
For each group immunity measurement action, print the result on its own line.