HDU 1166 Segment Tree interval summation + single point Update CD template

Source: Internet
Author: User
Tags cas tidy

Topic links

Enemy Soldiers

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


problem Descriptionc State of the death of a country during the period of military exercises, so the C state spy chief Derek and his men tidy began to busy again. 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. 

InputThe first line is an integer t, which indicates 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, which indicates that the I camp increases J person (J not more than ten)
(2) Sub I J, I and J are positive integers, indicating that I camp Reduction J person (J not more than ten);
(3) Query I J, I and J are positive integers, i<=j, indicating the total number of persons who have been questioned on the first to the J camps;
(4) end indicates that the command is final at each set of data;
up to 40,000 commands per set of data 

Outputfor Group I data, first output "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:63359 

#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath > #include <vector> #include <queue> #include <stack> #include <map> #include <algorithm > #include <set>using namespace std;typedef long long ll;typedef unsigned long long Ull; #define MM (A, B) memset (A, B , sizeof (a)); const double EPS = 1e-10;const int inf = 0x3f3f3f3f;const double Pi=acos ( -1); const int Maxn=100000;struct Tree   {int l,r; ll Maxn,sum;}    tree[4*maxn+5];void Build (int id,int l,int r) {tree[id].l=l;    Tree[id].r=r;    if (r==l) scanf ("%lld", &tree[id].sum);        else {int mid= (L+R) >>1;        Build (2*id,l,mid);        Build (2*id+1,mid+1,r);    Tree[id].sum=tree[2*id].sum+tree[2*id+1].sum;    }}int query (int id,int l,int R) {if (l<=tree[id].l&&tree[id].r<=r) return tree[id].sum;        else if (tree[id].r>=l&&tree[id].l<=r) {int x=query (2*ID,L,R); int y=Query (2*ID+1,L,R);    return x+y; } else return 0;}     void update (int id,int pos,int val) {if (TREE[ID].L==TREE[ID].R) Tree[id].sum+=val;         else{int mid= (TREE[ID].L+TREE[ID].R) >>1;         if (pos<=mid) update (2*id,pos,val);         else update (2*id+1,pos,val);     Tree[id].sum=tree[2*id].sum+tree[2*id+1].sum;    }}char S[14];int Main () {int cas;    scanf ("%d", &cas);        for (int kk=1;kk<=cas;kk++) {int n;        scanf ("%d", &n);        Build (1,1,n);        printf ("Case%d:\n", KK);            while (~SCANF ("%s", s)) {if (s[0]== ' E ') is break;            int x, y;            scanf ("%d%d", &x,&y);            if (s[0]== ' Q ') printf ("%d\n", Query (1,x,y));            else if (s[0]== ' A ') update (1,X,Y);        else if (s[0]== ' s ') update (1,X,-Y); }} return 0;}

  

HDU 1166 Segment Tree interval summation + single point Update CD template

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.