Spoj 1029 Matrix Summation "Two-dimensional tree-like array"

Source: Internet
Author: User

Test instructions: A two-dimensional tree array, changing the value is a little different,

is to set a[x][y] to a value, so add has to make it worse than the previous value.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <Set>9#include <queue>Ten#include <algorithm> One using namespacestd; A  -typedefLong LongLL; - Const intINF = (1<< -)-1; the Const intMod=1000000007; - Const intmaxn=5005; -  - intA[MAXN][MAXN]; + intC[MAXN][MAXN];//tree-like array - intN; +  A intLowbit (intx) {returnX & (-x);} at  - intSumintXinty) { -     intret=0; -     intY1; -      while(X >0){ -Y1 =y; in          while(Y1 >0){ -RET + = c[x][y1];y1-=lowbit (y1); to         } +x-=lowbit (x); -     } the     returnret; * } $ Panax Notoginseng voidAddintXintYintd) { -     intY1; the      while(X <MAXN) { +Y1 =y; A          while(Y1 <MAXN) { theC[x][y1]+=d; y1+=lowbit (y1); +         }  -x+=lowbit (x); $     } $ } -  - intMain () { the     intT; -scanf"%d",&T);Wuyi      while(t--){ theMemset (c,0,sizeof(c)); -Memset (A,0,sizeof(a)); Wuscanf"%d",&n); -         Chars[ the]; About          while(SCANF ("%s", s)! =EOF) { $             if(s[0] =='E') Break; -             if(s[1]=='E'){ -                 intX,y,num; -scanf" %d%d%d", &x,&y,&num); x++;y++; A                 intTMP = num-A[x][y]; +A[x][y] =num; the Add (x,y,tmp); -             } $             if(s[1]=='U'){ the                 intX,y,xx,yy; the                 intans=0; thescanf"%d %d%d%d",&x,&y,&xx,&yy); thex++;y++;xx++;yy++; -ans = SUM (xx,yy)-SUM (x1, yy)-sum (xx,y-1) + SUM (x1, Y1); inprintf"%d\n", ans); the             } the         }     About     } the     return 0; the}
View Code

Spoj 1029 Matrix Summation "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.