#P15147. [SWERC 2024] Titanomachy
[SWERC 2024] Titanomachy
题目描述
In ancient Greek mythology, it is believed that the Olympian gods acquired their power from a long lasting war with the Titans.
After some recent excavations, an archaeological team found manuscripts explaining how people thought this war happened.
Zeus, the leader of the Olympian gods, and Kronos, the leader of the titans, each picked their best soldiers in order to fight.
Then, the soldiers arranged themselves in two rows, one row containing only the Olympian gods, and the other containing the Titans, such that each soldier faced exactly one opponent.
At the beginning of the battle, each such pair () of soldiers had a score, , which is an integer representing which side of the war had the advantage. A positive number represented an advantage for Zeus and the Olympian gods, a negative number an advantage for the Titans.
During the war, events occurred. These events could be of two kinds: either the relative strength of all pairs of soldiers changed due to the actions of Zeus and Kronos (for example, breaking down mountains with lightning), or Zeus conducted a strategic assessment of his army’s advantage.
In the first case, the same integer got added to every single . If was greater than 0, it meant that Zeus increased the strength of his army, while a negative value meant that the Titans increased their strength, and a value of 0 meant that nothing changed.
In the second case, Zeus focused on an interval of soldiers (): he considered every possible subinterval, that is, all such that , and computed the sum for each of them. He computed the maximum value of such sums over all possible subintervals, and declared that was the strategic assessment of his army’s advantage.
Obviously, Zeus’s wisdom allowed him to compute such values instantaneously, but unfortunately, he did not record them anywhere.
Your task as a philologist is to provide the values of all the strategic assessments made by Zeus during the war.
输入格式
The first line of the input contains two space-separated integers and . The second line contains space-separated integers , representing the state at the beginning of the war. The following lines describe the events of the war, in chronological order. Each of them is either:
-
The word STRENGTH, followed by a space and an integer , meaning that the strength of an army changed.
-
The word ASSESS followed by space-separated integers and , meaning that Zeus made a strategic assessment of his army’s advantage by focusing on the interval ().
输出格式
For every time Zeus made a strategic assessment of his army’s advantage, and in the order they appear in the input, you must output one line with the value of each assessment.
4 6
1 -2 3 4
ASSESS 1 4
ASSESS 1 2
ASSESS 2 2
STRENGTH 2
ASSESS 1 4
ASSESS 1 2
7
1
0
14
3
提示
Limits
- for .
- All integers are between and , inclusive.
- At all times during the war, for all holds true.