HUD 1166 Enemy Soldiers

Source: Internet
Author: User
Tags tidy

http://acm.hdu.edu.cn/showproblem.php?pid=1166

Enemy soldiers

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 57332 Accepted Submission (s): 24215


Problem Descriptionc State of the death of a country this period is a military exercise, so the C state spy chief Derek and his men tidy again began busy. Country A has a line of N engineering camps along the coastline, and Derek and tidy are tasked with monitoring the activities of these engineering camps. As a result of the adoption of some advanced monitoring tools, the number of people in each engineering camp, C, is well-informed and the number of personnel in each engineering camp is likely to change, possibly by increasing or reducing the number of staff, but none of them can escape the surveillance of State C.
The CIA wants to study what tactics the enemy is practicing, so Tidy to report to Derek at any time about how many people there are in a succession of engineering camps, such as Derek asking: "Tidy, Report to the 3rd camp to the 10th camp." Tidy is about to start calculating the total number of people in this section and report it immediately. But the number of enemy barracks is constantly changing, and Derek Each asked the paragraph is not the same, so tidy had to every time a camp to count, quickly exhausted, Derek to tidy's calculation speed more and more dissatisfied: "You a dead Fat boy, calculate so slow, I fire you squid!" Tidy thought, "You can count on yourself, it's a tiring job!" I wish you would fire me! " Helpless under, tidy had to call computer experts windbreaker for help, Windbreaker said: "Die fat, you usually do more than a point of ACM and see more Algorithms book, now taste the bitter pill!" Tidy said: "I know the wrong ... "But Windbreaker already hung up the phone." Tidy is very distressed, so he really will collapse, smart Reader, can you write a program to help him finish the work? But if your program is not efficient enough, tidy will still be scolded by Derek.

Input the first line of an integer t, indicating that there is a T group of data.
The first line of each group of data is a positive integer n (n<=50000), which indicates that the enemy has N engineering camps, followed by n positive integers, and the second positive integer AI represents the first AI individual (1<=ai<=50) in the field of the I barracks.
Next, there is one command in each line, with 4 forms of command:
(1) Add I j,i and J are positive integers, indicating that I camp increase J person (J not more than 30)
(2) Sub i J, I and J are positive integers, indicating that the I camp reduced J person (j not more than 30);
(3) Query i J, I and J are positive integers, i<=j, which indicate the total number of persons who have inquired about the first and the J camps;
(4) End indicates that the command ends in each group of data;
Up to 40,000 commands per set of data

Output to group I data, first outputs "case I:" and carriage return,
For each query, output an integer and enter it to indicate the total number of people in the segment you are asking for, which remains within Int.

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

Sample outputcase 1:63,359 Segment Tree template problem, change the value of the point, find out a range of and, update point
#include <stdio.h>#include<math.h>#include<string.h>#include<algorithm>#defineN 50010#defineLson root<<1, L, Tree[root]. Mid ()//root<<1 says Root*2#defineRson root<<1|1, Tree[root]. Mid () + 1, R//root<<1|1 says Root*2+1using namespacestd;structtree{intL, R; inte, sum; intMid () {return(L + R)/2; }}tree[n*4];intAl[n];voidBuild (intRootintLintR) {Tree[root]. L= L, Tree[root]. R =R; if(L = =R) {tree[root].sum=Al[l]; return ;    } Build (Lson);    Build (Rson); Tree[root].sum= tree[root<<1].sum + tree[root<<1|1].sum;//The sum of the previous node interval and equal to the left and right intervals}voidInsert (intRootintKintE//K for the update{tree[root].sum+=e; if(Tree[root]. L = =Tree[root]. R)return ; if(k <=Tree[root]. Mid ()) Insert (Root<<1, K, E); ElseInsert (Root<<1|1, K, e);}intQuery (intRootintLintR) {    if(Tree[root]. L = = L && tree[root]. R = =R)returntree[root].sum; if(R <=Tree[root]. Mid ())returnQuery (root<<1, L, R); Else if(L >Tree[root]. Mid ())returnQuery (root<<1|1, L, R); Else        returnQuery (Lson) +Query (Rson);}intMain () {intT, a, B, N, I, x =0; Chars[Ten]; scanf ("%d", &t);  while(t--) {x++; scanf ("%d", &N);  for(i =1; I <= N; i++) scanf ("%d", &Al[i]); Build (1,1, N); printf ("Case %d:\n", x);  while(SCANF ("%s", s), s[0] !='E') {scanf ("%d%d", &a, &b); if(s[0] =='Q') printf ("%d\n", Query (1, A, b)); Else if(s[0] =='A') Insert (1, A, b); ElseInsert (1, A,-b); }    }    return 0;}

HUD 1166 Enemy Soldiers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.