#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 NN 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 ii (1iN1 \le i \le N) of soldiers had a score, AiA_i, 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, QQ 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 XX got added to every single AiA_i. If XX 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 [L,R][L, R] of soldiers (1LRN1 \le L \le R \le N): he considered every possible subinterval, that is, all l,rl, r such that LlrRL \le l \le r \le R, and computed the sum Al+Al+1++ArA_l + A_{l+1} + \cdots + A_r for each of them. He computed the maximum value MM of such sums over all possible subintervals, and declared that V=max(M,0)V = \max(M, 0) 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 NN and QQ. The second line contains NN space-separated integers AiA_i, representing the state at the beginning of the war. The following QQ 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 XX, meaning that the strength of an army changed.

  • The word ASSESS followed by space-separated integers LL and RR, meaning that Zeus made a strategic assessment of his army’s advantage by focusing on the interval [L,R][L, R] (1LRN1 \le L \le R \le N).

输出格式

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 VV 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

  • 1N3×1051 \le N \le 3 \times 10^5
  • 1Q3×1051 \le Q \le 3 \times 10^5
  • 109Ai109-10^9 \le A_i \le 10^9 for i=1,,Ni = 1, \dots, N.
  • All XX integers are between 109-10^9 and 10910^9, inclusive.
  • At all times during the war, 2×109Ai2×109-2 \times 10^9 \le A_i \le 2 \times 10^9 for all i=1,,Ni = 1, \dots, N holds true.