HDU 1892 See you~ (Two-dimensional tree array)

Source: Internet
Author: User
Tags x2 y2

See you~

Time limit:5000/3000 MS (java/others) Memory limit:65535/32768 K (java/others)
Total submission (s): 4753 Accepted Submission (s): 1518


Problem Descriptionnow I am leaving Hust ACM. In the past II and half years, I learned so many knowledge on algorithm and programming, and I met so many good friend S. I want to say sorry to Mr, Yin, I must leave now ~~>.<~~. I am very sorry, we could not advanced to the world finals last year.
When coming to our training, a lot of books is in my eyes. And every time the books is moving from one place to another one. Now give your position of the books at the early of the day. And the moving information of the books the day, your work was to tell me how many books was stayed in some rectangles.
To make the problem easier, we divide the same as different grids and a book can only stayed in one grid. The length and the width of the is less than 1000. I can move one book from one position to another position, take away one book from a position or bring in one book and put It on one position.

Inputin the first line of the input file there was an Integer T (1<=t<=10), which means the number of test cases in th e input file. Then N test cases is followed.
For each test case, in the first line there is a Integer Q (1<q<=100,000), means the queries of the case. Then followed by Q queries.
There is 4 kind of queries, sum, add, delete and move.
For example:
S x1 y1 x2 y2 means you should tell me the total books of the rectangle used (x1,y1)-(x2,y2) as the diagonal, including th e-Points.
A x1 y1 N1 means I put N1 books on the position (X1,Y1)
D x1 y1 N1 means I move away N1 books on the position (x1,y1), if less than N1 books at this position, move away all of th Em.
M x1 y1 x2 y2 n1 means you move N1 books from (x1,y1) to (x2,y2), if less than N1 books at that position, move away all of them.
Make sure in first, there is a book on every grid and 0<=x1,y1,x2,y2<=1000,1<=n1<=100.

Outputat the beginning of each case, output ' case x: ' where x is the index of the "the" and then followed by the "S" Quer ies.
For each "S" query, just print out the total number of books in the.

Sample input23s 1 1 1 1 a 1 1 2S 1 1 1 13S 1 1 1 1 a 1 1 2S 1 1 1 2

Sample outputcase 1:13case 2:14

authorsempr| Crazybird|hust07p43

Source HDU 2008-4 Programming Contest

Recommendlcy | We have carefully selected several similar problems for you:1541 2492 1894 1394 3450
/*given 4 operations: S x1 y1 x2 Y2 asks for the area of the rectangle (x1, y1)-(x2, y2)-diagonal, but the diagonal is not necessarily a positive diagonal. A x1 y1 N points (x1, y1) plus n. D x1 y1 N points (x1, y1) minus n if less than n is all removed. M x1 y1 x2 y2 n points (x1, y1) point value is deducted from N plus to (x2, y2), if but n the (x1, y1) value is added to (X2 , y2)*/#include<iostream>#include<stdio.h>#include<cmath>#include<string.h>#defineLowbit (x) x& (-X)#defineN 1005using namespacestd;intT,n;intC[n][n];voidUpdateintXintYintval) {    //int Flag=fabs (val); //While (x<n)// {        //While (y<n)// {            //cout<<x<< "" <<y<<endl; //C[x][y]+=val; //if (c[x][y]<0)// {                //Flag=c[x][y]+val; //c[x][y]=0; // }                //y+=lowbit (y); // }        //x+=lowbit (x); // }     for(inti=x;i<n;i+=lowbit (i)) {         for(intj=y;j<n;j+=Lowbit (j)) {C[i][j]+=Val; //if (c[i][j]<0)// {                //Flag=c[i][j]+val; //c[i][j]=0; // }            }        }    //return Val;//back to what you actually handled.}intGetsum (intXinty) {    ints=0; //While (x>0)// {        //While (y>0)// {            //S+=c[x][y]; //y-=lowbit (y); // }        //x-=lowbit (x); // }     for(intI=x;i>0; i-=lowbit (i)) {         for(intJ=y;j>0; j-=Lowbit (j)) {s+=C[i][j]; }        }    returns;}//int GetS (int x1,int y1,int x2,int y2)// {    //cout<<getsum (x1,y1) << "<<getsum (x1-1,y2) <<" "<<getsum (x2,y1-1) <<" "<    <getsum (x2-1,y2-1) <<endl; //return Getsum (x1,y1)-getsum (x1,y2-1)-getsum (x2-1,y1) +getsum (x2-1,y2-1);// }intMain () {//freopen ("C:\\users\\acer\\desktop\\in.txt", "R", stdin);scanf"%d",&t); intCase=1;  while(t--) {printf ("Case %d:\n", case++); scanf ("%d",&N); intX1,x2,y1,y2,val; Memset (c,0,sizeofc);  for(intI=1; i<=n;i++)             for(intj=1; j<=n;j++) Update (I,J,1); //cout<<getsum << "<<getsum (2,2) <<endl;         for(intI=0; i<n;i++)        {            //GetChar ();            Charop[5]; scanf ("%s",&op); //GetChar ();            if(op[0]=='A'|| op[0]=='D') {scanf ("%d%d%d",&x1,&y1,&val); X1++;y1++; if(op[0]=='D') Val=-min (Val,getsum (x1,y1)-getsum (x1-1, y1)-getsum (x1,y1-1) +getsum (x1-1, y1-1));            Update (X1,Y1,VAL); }            Else if(op[0]=='M') {scanf ("%d%d%d%d%d",&x1,&y1,&x2,&y2,&val); X1++;x2++;y1++;y2++; intTemp=min (Val,getsum (x1,y1)-getsum (x1-1, y1)-getsum (x1,y1-1) +getsum (x1-1, y1-1));//This is something you actually moved from the previous point .Update (x1,y1,-temp);            Update (X2,Y2,TEMP); }            Else{scanf ("%d%d%d%d",&x1,&y1,&x2,&y2); if(x1<x2) Swap (X1,X2); if(y1<y2) swap (y1,y2);//is not necessarily a positive diagonalx1++;x2++;y1++;y2++; //cout<<x1<< "<<y1<<" "<<x2<<" "<<y2<<endl; //cout<< "Getsum (x2,y2) =" <<getsum (x2,y2) <<endl; //cout<<getsum (x1,y1) << "<<getsum (x1,y2-1) <<" "<<getsum (x2-1,y1) <<" "< <getsum (x2-1,y2-1) <<endl;printf"%d\n", Getsum (x1,y1)-getsum (x1,y2-1)-getsum (x2-1, y1) +getsum (x2-1, y2-1)); }        }    }    return 0;}/*Case 1:13case 2:1 4*/

HDU 1892 See you~ (Two-dimensional tree array)

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.