HDU 3584 tree-like array

Source: Internet
Author: User

Click to open link

Test instructions: three-dimensional space has two operations, the initial time each space element is 0, and then the update operation is 0 to 0, is a space all elements are updated, and then query is asked whether the element of this point is 0 or 1

Idea: Because it is not good to update to each point, then we can count the number of space rollover, and then use three-dimensional tree array can be, but the update can not only update that point, because if so, can include this interval of the large interval because it has not been updated and become 1, that is not what we want, So we're going to surround the circle of this interval in an update, then the value is 2, without affecting the result

#include <stdio.h> #include <string.h> #include <stdlib.h> #include <iostream> #include < Algorithm>using namespace Std;typedef Long long ll;typedef unsigned long long ull;const int Inf=0x3f3f3f3f;const ll INF =0x3f3f3f3f3f3f3f3fll;const int maxn=110;int sum[maxn][maxn][maxn],n;int lowbit (int x) {return x& (-X);}            void update (int x,int y,int z,int val) {for (Int. i=x;i<=n;i+=lowbit (i)) {for (int j=y;j<=n;j+=lowbit (j)) {            for (int l=z;l<=n;l+=lowbit (l)) {sum[i][j][l]+=val;    }}}}int msum (int x,int y,int z) {int res=0;                For (Int. i=x;i>0;i-=lowbit (i)) {for (Int. j=y;j>0;j-=lowbit (J)) {for (int l=z;l>0;l-=lowbit (l)) {            RES+=SUM[I][J][L]; }}} return res;}    int main () {int m,x1,y1,z1,x2,y2,z2,type;        while (scanf ("%d%d", &n,&m)!=-1) {memset (sum,0,sizeof (sum));            while (m--) {scanf ("%d", &type); if (TyPe==1) {scanf ("%d%d%d%d%d%d", &AMP;X1,&AMP;Y1,&AMP;Z1,&AMP;X2,&AMP;Y2,&AMP;Z2);                Update (x1,y1,z1,1); update (x1,y1,z2+1,1);                Update (x1,y2+1,z1,1); update (x1,y2+1,z2+1,1);                Update (x2+1,y1,z1,1); update (x2+1,y1,z2+1,1);            Update (x2+1,y2+1,z1,1); update (x2+1,y2+1,z2+1,1);                }else{scanf ("%d%d%d", &AMP;X1,&AMP;Y1,&AMP;Z1);            printf ("%d\n", Msum (X1,Y1,Z1) &1); }}} return 0;}

HDU 3584 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.