HDU 3584 hdoj 3584 cube ACM 3584 in HDU

Source: Internet
Author: User
Tags cmath

Miyu original, post Please note: Reprinted from __________ White House

 

Description:


Cube

Time Limit: 2000/1000 MS (Java/others) memory limit: 131072/65536 K (Java/Others)
Total submission (s): 495 accepted submission (s): 226

Problem descriptiongiven an N * n cube A, whose elements are either 0 or 1. A [I, j, k] means the number in the I-th row, J-th Column and k-th layer. initially we have a [I, j, k] = 0 (1 <= I, j, k <= N ).
We define two operations, 1: "not" operation that we change the [I, j, k] =! A [I, j, k]. that means we change a [I, j, k] from 0-> 1, or 1-> 0. (X1 <= I <= x2, Y1 <= j <= Y2, Z1 <= k <= Z2 ).
0: "Query" operation we want to get the value of a [I, j, k].

Inputmulti-cases.
First line contains N and M, M lines follow indicating the operation below.
Each operation contains an X, the type of operation. 1: "not" operation and 0: "Query" operation.
If X is 1, following X1, Y1, Z1, X2, Y2, Z2.
If X is 0, following X, Y, Z.

Outputfor each query output a [x, y, z] in one line. (1 <= n <= 100 sum of M <= 10000)

Sample Input

 
2 51 1 1 1 1 1 10 1 11 1 1 1 2 2 20 1 10 2 2 2

Sample output

101

Question Analysis:

Update the interval and query a point. The 3D line segment tree directly ignores ......... the data is not very strong, so we can go through the direct violence. After we found that our time was around 700 ms, we looked at rank,

Small A leads the world ..... the time is only 62ms .... we still need to use a three-dimensional tree array for acceleration. however, I have never understood how to solve this problem with a tree array. I finally understood this morning.

Draw a picture first:

Okay. Check it out.Code:

Tree array code:

 /*

Mail to: miyubai@gamil.comMy blog: www. policyun. melink: http://www.cnblogs.com/MiYu | http://www.cppblog.com/MiYuAuthor by: miyutest: 1 complier: G ++ mingw32-3.4.2Program: hdu_3584doc name: Cube * // # pragma warning (Disable: 4789) # include <iostream> # include <fstream> # include <sstream> # include <algorithm> # include <string> # include <set> # include <map> # include <utility> # include <queue> # include <stack> # include <list> # include <vector> # include <cstdio> # include <cstdlib> # include <cstring> # include <cmath> # include <ctime> Using namespace STD ;  Inline  Bool Scan_d (  Int  & Num ) // Integer input {  Char In ;  Bool ISN = False ; In = Getchar ();  If  ( In = EOF )  Return False ;  While  ( In ! = '-' &&( In < '0' | In> '9' )) In = Getchar ();  If  ( In = '-' ){ ISN = True ; Num = 0 ;}  Else Num = In - '0' ;  While  ( In = Getchar (), In > = '0' && In <= '9' ){ Num * = 10 , Num + = In - '0' ;}  If  ( ISN ) Num =- Num ;  Return True ;}  Const  Int Maxn = 105 ;  Int Mat[ Maxn ] [ Maxn ] [ Maxn ];  Int Low [ Maxn ];  Int I , J , K ;  Void Setlow (){  For  ( I = 1 ; I <= Maxn ; ++ I ) Low [ I ] = I &(- I );}  Void Modify (  Int X ,  Int Y ,  Int Z ){  For  ( I = X ; I <= Maxn ; I + = Low [ I ]) {  For ( J = Y ; J <= Maxn ; J + = Low [ J ]) {  For  ( K = Z ; K <= Maxn ; K + = Low [ K ]) Mat [ I ] [ J ] [ K ] ^ = 1 ;}}}  Int Query (  Int X ,  Int Y ,  Int Z ){  Int Sum = 0 ;  For  ( I = X ; I > 0 ; I ^ = Low [ I ]) {  For  ( J = Y ; J > 0 ; J ^ = Low [ J ]) {  For  ( K = Z ; K > 0 ; K ^ = Low [ K ]) Sum + = Mat [ I ] [ J ] [ K ] ;}}  Return Sum & 1 ;}  Int  Main  (){ Setlow ();  Int N , M ;  While  ( Scan_d ( N )&& Scan_d ( M )){ Memset ( Mat , 0 ,  Sizeof  ( Mat ));  While  ( M --){  Int X1 , Y1 , Z1 , X2 , Y2 , Z2 ;  Int S ; Scan_d ( S ); Switch  ( S ){  Case 1 : Scan_d ( X1 ); Scan_d ( Y1 ); Scan_d ( Z1 ); Scan_d ( X2 ); Scan_d ( Y2 ); Scan_d ( Z2 ); Modify( X1 , Y1 , Z1 ); Modify ( X1 , Y1 , Z2 + 1 ); Modify ( X2 + 1 , Y1 , Z1 ); Modify ( X2 + 1 , Y1 , Z2 + 1); Modify ( X1 , Y2 + 1 , Z1 ); Modify ( X2 + 1 , Y2 + 1 , Z1 ); Modify ( X2 + 1 , Y2 + 1 , Z2 + 1 ); Modify ( X1 , Y2 + 1 , Z2 + 1 );  Break  ;  Case 0 : Scan_d ( X1 ); Scan_d ( Y1 ); Scan_d ( Z1 ); Printf ( "% D \ n" , Query ( X1 , Y1 , Z1 ));}}}  Return 0 ;} 

Brute force code:

/* Mail to: miyubai@gamil.comMy blog: www. policyun. melink: http://www.cnblogs.com/MiYu | http://www.cppblog.com/MiYuAuthor by: miyutest: 1 complier: G ++ mingw32-3.4.2Program: Doc name: * // # pragma warning (Disable: 4789) # include <iostream> # include <fstream> # include <sstream> # include <algorithm> # include <string> # include <set> # include <map> # include <utility> # include <queue> # include <stack> # include <list> # include <vector> # include <cstdio> # include <cstdlib> # include <cstring> # include <cmath> # include <ctime> Using namespace STD ;  Struct Node {  Int X1 , X2 , Y1, Y2 , Z1 , Z2 ;} Cube [ 10010 ];  Int  Main  (){  Int N , M ;  Int X , Y , Z ;  While  ( Scanf ( "% D" ,& N ,& M)! = EOF ){  Int CNT = 0 ;  While  ( M --){  Int Ask ; Scanf ( "% D" ,& Ask );  Switch  ( Ask ){  Case 1 : Scanf ( "% D" ,& Cube [ CNT ]. X1 ,& Cube [ CNT ]. Y1 ,& Cube [ CNT ]. Z1 ,& Cube [ CNT ]. X2 ,& Cube [ CNT ]. Y2 ,& Cube [ CNT ]. Z2 ); ++ CNT ;  Break  ;  Case 0 : Scanf ( "% D" ,& X ,& Y ,& Z );  Int Count = 0 ;  For  (  Int I = 0 ; I ! = CNT ; ++ I )  If  ( Cube [ I ]. X1 <= X && X <= Cube [ I ]. X2 && Cube [ I ]. Y1 <= Y && Y<= Cube [ I ]. Y2 && Cube [ I ]. Z1 <= Z && Z <= Cube [ I ]. Z2 ) Count ^ = 1 ;; Puts ( Count ? "1" : "0");}}}  Return 0 ;}   

 

 

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.