[C++] henuACM summer training Day16 tree array

First put two blogs and watch slowly
https://www.cnblogs.com/xenny/p/9739600.html
https://blog.csdn.net/bestsort/article/details/80796531

A title enemy troops formation (HDU 1166)

topic

Country C’s enemy, Country A, is conducting military exercises during this period, so country C spy chief Derek and his subordinate Tidy are busy again. Country A has arranged N engineer camps along the coastline. The task of Derek and Tidy is to monitor the activities of these engineer camps. Due to the adoption of some advanced monitoring methods, the number of people in each engineering camp is clear to country C. The number of people in each engineering camp may change, and it may increase or decrease a number of manpower, but these cannot escape C. State surveillance.
The CIA wants to study the enemy's tactics, so Tidy must report to Derek at any time how many people are in a certain continuous engineering camp. For example, Derek asks: "Tidy, immediately report how many people there are from the third camp to the tenth camp. !" Tidy will start counting and reporting the total number of people in this segment right away. However, the number of enemy camps changed frequently, and Derek asked different segments each time, so Tidy had to count one by one camp each time, and quickly became exhausted. Derek's calculation of Tidy became faster. More and more dissatisfied: "You fat guy, it's so slow, I'll fire you!" Tidy thought, "You can count it yourself, this is really tiring work! I can't wait for you to fire me! "In desperation, Tidy had to call Windbreaker, a computer expert, for help. Windbreaker said, "Deadly fat boy, I asked you to do more acm questions and read more algorithm books. Now you can taste the bitter fruit!" Tidy said: " I got it wrong..." But Windbreaker has already hung up. Tidy is very distressed, he will really fall apart, clever reader, can you write a program to help him complete this work? But if your program is not efficient enough, Tidy will still be scolded by Derek.

Input

An integer T in the first line indicates that there are T groups of data.
The first line of each group of data is a positive integer N (N<=50000), which means that the enemy has N engineer camps, and then there are N positive integers. The i-th positive integer ai represents the i-th engineer camp with ai at the beginning Individual (1<=ai<=50).
There is a command on each line in the next, and the command has 4 forms:
(1) Add ij, i and j are positive integers, which means that j individuals are added to the i-th camp (j does not exceed 30)
(2) Sub ij ,i and j It is a positive integer, which means that the i-th camp reduces j individuals (j does not exceed 30);
(3) Query ij, i and j are positive integers, i<=j, which means that the total number of people in the i-th camp is asked;
(4) End means end, this command appears at the end of each group of data;
each group of data has a maximum of 40,000 commands

Output

For the i-th group of data, first output "Case i:" and press Enter.
For each Query query, output an integer and press Enter to indicate the total number of people in the query segment, and this number is kept within int.

Simple Input

1
10
1 2 3 4 5 6 7 8 9 10
Query 1 3
Add 3 6
Query 2 7
Sub 10 2
Add 6 3
Query 3 10
End

Simple Output

Case 1:
6
33
59

Title

After listing the number of people in all camps, there are two operations, one starting with Q is called query, one starting with A is called adding, and starting with S is reducing.

Guess you like

Origin blog.csdn.net/qq_44899247/article/details/97951674