POJ-1195 Mobile Phones---bare two-dimensional tree array (note subscript starting from 1, 1)

Source: Internet
Author: User

Topic Links:

https://vjudge.net/problem/POJ-1195

Main topic:

Direct maintenance of two-dimensional tree arrays

Note that the horizontal ordinate all needs to add 1, because the tree array starts at (

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++) - using namespacestd; +typedefLong Longll; - intT, N, m, cases; + intnum[1048][1048]; A intLowbit (intx) at { -     returnX & (-x); - } - ///Modify Num[x][y] = d - voidAddintXintYintd) - { in      for(inti = x; I <= N; i + =lowbit (i)) -     { to          for(intj = y; J <= N; J + =Lowbit (j)) +NUM[I][J] + =D; -     } the } * ///calculates the sum of the vertices as (1, 1) (x, y) $ intSumintXinty)Panax Notoginseng { -     intAns =0; the      for(inti = x; i >0; I-=lowbit (i)) +     { A          for(intj = y; J >0; J-=Lowbit (j)) theAns + =Num[i][j]; +     } -     returnans; $ } $ intMain () - { -     intT, x1, y1, x2, y2, D; the      while(Cin >> T >>N) -     {Wuyimemset (NUM,0,sizeof(num)); the          while(Cin >>t) -         { Wu             if(T = =3) Break; -             Else if(T = =1) About             { $scanf"%d%d%d", &x1, &y1, &d); -x1++, y1++; - Add (x1, y1, d); -             } A             Else if(T = =2) +             { thescanf"%d%d%d%d", &x1, &y1, &AMP;X2, &y2); -x1++, y1++, x2++, y2++; $cout<< (sum (x2, y2)-sum (x2, y1-1)-SUM (x1-1, y2) + SUM (x1-1, Y1-1)) <<Endl; the             } the         } the     } the     return 0; -}

POJ-1195 Mobile Phones---bare two-dimensional tree array (note subscript starting from 1, 1)

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.