hdu-1892 See you~---The application of two-dimensional tree array

Source: Internet
Author: User
Tags x2 y2

Topic Links:

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

Main topic:

The main topic: There are many squares, each grid corresponds to the coordinates (I,J), at the beginning of each lattice there are 1 books, and then let you count a region how many books, can also increase the book and reduce, mobile books.

Problem Solving Ideas:

Direct two-dimensional array array simulation

Attention:

Each subscript +1, starting from (1, 1)

X1 Y1 and X2 y2 are not standard diagonal lines and need to be converted.

1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5#include <string>6#include <cmath>7#include <Set>8#include <queue>9#include <map>Ten#include <stack> One#include <vector> A#include <list> -#include <deque> -#include <sstream> the#include <cctype> - #defineREP (i, n) for (int i = 0; I < (n); i++) - #defineFor (I, S, T) for (int i = (s); I < (t); i++) - #defineMEM (A, X) memset (A, X, sizeof (a)); + using namespacestd; -typedefLong Longll; +typedef unsignedLong Longull; A Const intMAXN =1010; at Const DoubleEPS = 1e-Ten; - Const intINF =1<< -; - Const intdir[4][2] = {1,0,0,1,0,-1,-1,0}; - Const DoublePI =3.1415926535898; - intT, N, m, cases; - intTREE[MAXN][MAXN], A[MAXN][MAXN]; in intLowbit (intx) - { to     returnx& (-x); + } - intSumintXinty) the { *     intAns =0; $      for(inti = x; i >0; I-=lowbit (i))Panax Notoginseng          for(intj = y; J >0; J-=Lowbit (j)) -Ans + =Tree[i][j]; the     returnans; + } A voidAddintXintYintd) the { +      for(inti = x; i < MAXN; i + =lowbit (i)) -     { $          for(intj = y; J < Maxn; J + =Lowbit (j)) $         { -TREE[I][J] + =D; -         } the     } - }Wuyi intMain () the { -scanf"%d", &T); Wu     Chars[3]; -     intx, y, x1, y1, x2, y2, D; About      while(t--) $     { -scanf"%d", &n); -MEM (Tree,0); -          for(inti =1; i < MAXN; i++) A         { +              for(intj =1; J < Maxn; J + +) the             { -Add (i, J,1); $A[I][J] =1; the             } the         } theprintf"Case %d:\n", ++cases); the          while(n--) -         { inscanf"%s", s); the             if(s[0] =='S') the             { Aboutscanf"%d%d%d%d", &x1, &y1, &AMP;X2, &y2); the                 ///not the standard X1.<x2, Y1<y2, to transform it . the int A, B, C, D; theA = min (x1, x2); a++; +b = min (y1, y2); b++; -c = max (x1, x2); C + +; thed = max (y1, y2);d + +;Bayiprintf"%d\n", sum (c, D) + sum (A-1, B-1)-SUM (A-1, d)-sum (c, B-1)); the             } the             Else if(s[0] =='A') -             { -scanf"%d%d%d", &x, &y, &d); thex + +, y++; the Add (x, y, d); theA[x][y] + =D; the             } -             Else if(s[0] =='D') the             { thescanf"%d%d%d", &x, &y, &d); thex + +, y++;94                 if(d > a[x][y]) d =A[x][y]; theAdd (x, Y,-d); theA[x][y]-=D; the             }98             Else About             { -scanf"%d%d%d%d%d", &x1, &y1, &x2, &y2, &d);101x1++, y1++, x2++, y2++;102                 if(d > a[x1][y1]) d =A[x1][y1];103Add (x1, y1,-d);104 Add (x2, y2, d); theA[X1][Y1]-=D;106A[x2][y2] + =D;107             }108         }109     } the     return 0;111}

hdu-1892 See you~---The application of 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.