HDU 3584-cube (three-dimensional bit)

Source: Internet
Author: User

Test instructions

Give you three-dimensional space two operations, give two vertex coordinates, they determine the range (box) within the number of all the inverse, query to the value of the point. Initially all zeros

Analysis:

With the knowledge of the previous, using bit to achieve the interval update single-point query, and then use multidimensional implementation can

#include <map>#include<Set>#include<list>#include<cmath>#include<queue>#include<stack>#include<cstdio>#include<vector>#include<string>#include<cctype>#include<complex>#include<cassert>#include<utility>#include<cstring>#include<cstdlib>#include<iostream>#include<algorithm>using namespaceStd;typedef pair<int,int>Pii;typedefLong Longll;#defineLson l,m,rt<<1#definePi ACOs (-1.0)#defineRson m+1,r,rt<<11#defineAll 1,n,1#defineRead Freopen ("In.txt", "R", stdin)#defineN 110Constll infll =0x3f3f3f3f3f3f3f3fll;Const intinf=0x7ffffff;Const intMoD =1000000007;inta[n][n][n],n,m;intLowbit (intx) {    returnx& (-x);}voidAddintXintYintz) {     for(inti=x;i<=n;i+=lowbit (i)) for(intj=y;j<=n;j+=Lowbit (j)) for(intk=z;k<=n;k=k+Lowbit (k)) A[i][j][k]++;//statistical parity +1,-1}intSumintXintYintz) {    intnum=0;  for(intI=x;i>0; i-=lowbit (i)) for(intJ=y;j>0; j-=Lowbit (j)) for(intK=z;k>0; k-=Lowbit (k)) Num+=A[i][j][k]; returnnum;}intMain () {intop,x1,y1,z1,x2,y2,z2;  while(~SCANF ("%d%d",&n,&m)) {memset (A,0,sizeof(a));  while(m--) {scanf ("%d",&op); if(op==1) {scanf ("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);            Add (X1,Y1,Z1); Add (x1,y1,z2+1); Add (x2+1, Y1,Z1); Add (X1,y2+1, Z1); Add (x2+1, y2+1, Z1); Add (x2+1, y1,z2+1); Add (X1,y2+1, z2+1); Add (x2+1, y2+1, z2+1); }        Else{scanf ("%d%d%d",&x1,&y1,&Z1); printf ("%d\n", SUM (X1,Y1,Z1)%2); }      }    }return 0;}

HDU 3584-cube (three-dimensional bit)

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.