"poj1195" Mobile phones (two-dimensional tree-like array)

Source: Internet
Author: User

Title Link: http://poj.org/problem?id=1195

Test instructions

give a full 0 matrix, and then some operations0 S: Initialize the matrix, the dimension is s*s, and the value is all 0, this operation only appears at the beginning of the1 X y a: Increase the x, y coordinates of a matrix by a2 L B R T: Ask (l,b) to the sum of the values in the (r,t) interval3: End operation on this matrix"Ideas"Two-dimensional tree array single point update + area query, can be used as a template problem. Note that the coordinates are starting from 0, so take +1 "Code"
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5#include <cstdlib>6#include <cmath>7 using namespacestd;8 Const intN =1029;9typedefLong LongLL;Ten intC[n][n], N; One intLowbit (intx) A { -     returnX & (-x); - } the voidUpdateintXintYintnum) - { -      for(inti = x; I <= N; i + =lowbit (i)) -          for(intj = y; J <= N; J + =Lowbit (j)) +C[I][J] + =num; - } + intQueryintXinty) A { at     intsum =0; -      for(inti = x; i >0; I-=lowbit (i)) -          for(intj = y; J >0; J-=Lowbit (j)) -Sum + =C[i][j]; -     returnsum; - } in intMain () - { to     intI, M; +scanf"%d%d", &i, &n); -      while(SCANF ("%d", &m), M! =3) the     { *         intx1, x2, y1, y2, num; $         if(M = =1)Panax Notoginseng         { -scanf"%d%d%d", &x1, &y1, &num); thex1++, y1++; + Update (x1, y1, num); A         } the         Else +         { -scanf"%d%d%d%d", &x1, &y1, &AMP;X2, &y2); $x1++, y1++, x2++, y2++; $printf"%d\n", query (x2, y2)-Query (x1-1, y2)-Query (x2, y1-1) + Query (x1-1, Y1-1)); -         } -     } the     return 0; -}

"poj1195" Mobile phones (two-dimensional tree-like 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.