• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            ACM___________________________

            ______________白白の屋
            posts - 182, comments - 102, trackbacks - 0, articles - 0
            <2025年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            常用鏈接

            留言簿(24)

            隨筆分類(332)

            隨筆檔案(182)

            FRIENDS

            搜索

            積分與排名

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            MiYu原創(chuàng), 轉帖請注明 : 轉載自 ______________白白の屋    

             

            題目描述:

            Cube

            Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
            Total Submission(s): 495    Accepted Submission(s): 226


            Problem Description
            Given an N*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 A[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].
             

            Input
            Multi-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.
             

            Output
            For each query output A[x, y, z] in one line. (1<=n<=100 sum of m <=10000)
             

            Sample Input
            2 5 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 2 2 2 0 1 1 1 0 2 2 2
             

            Sample Output
            1 0 1
             

            題目分析 :

                  更新區(qū)間, 查詢一個點, 三維線段樹 直接無視.........數據不是很強, 所以 直接暴力就可以過, 過完發(fā)現自己的時間 在700MS 左右, 看了下rank,

            小A 榜首..... 時間竟然才62MS....果然還是要用三維樹狀數組來加速啊 . 不過一直沒理解 用 樹狀數組 解決這題的思路, 今早上終于明白了.

            畫個圖先 :

                         

            好了 , 看代碼:

            樹狀數組代碼 :

             /*

            Mail to   : miyubai@gamil.com
            My Blog   : www.baiyun.me
            Link      : http://www.cnblogs.com/MiYu  || http://m.shnenglu.com/MiYu
            Author By : MiYu
            Test      : 1
            Complier  : g++ mingw32-3.4.2
            Program   : HDU_3584
            Doc 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)  //整數輸入
            {
                    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;
            }
            

            暴力代碼 :

            /*
            Mail to   : miyubai@gamil.com
            My Blog   : www.baiyun.me
            Link      : http://www.cnblogs.com/MiYu  || http://m.shnenglu.com/MiYu
            Author By : MiYu
            Test      : 1
            Complier  : g++ mingw32-3.4.2
            Program   :
            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%d",&N,&M ) != EOF )  {  
                    int cnt = 0;  
                    while ( M -- )  
                    {  
                        int ask;  
                        scanf ( "%d", &ask );  
                        switch ( ask ) {
                            case 1:   
                                scanf ( "%d%d%d%d%d%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%d%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;  
            }  
            

             

            Feedback

            # re: HDU 3584 HDOJ 3584 Cube ACM 3584 IN HDU  回復  更多評論   

            2010-11-14 21:40 by 博客之家
            好復雜的代碼啊

            # re: HDU 3584 HDOJ 3584 Cube ACM 3584 IN HDU  回復  更多評論   

            2010-12-03 01:59 by flagman
            說兩點,
            1)這三維樹狀數組,占空間比較大,特別是問題規(guī)模快速增長時;
            2)對于
            void setLow () {
            for ( i = 1; i <= MAXN; ++ i ) low[i] = i & (- i);
            }
            這樣的短函數,topcoder上很多人都喜歡用宏定義,不知道為啥,難道受C的影響太深了,抑或為了節(jié)約函數調用開銷?呵呵,比如上面這函數,可能寫成如下,
            #define SETLOW(low,MAXN) for( i = 1; i <= (MAXN); ++i) *((low) + i) = i & (-i);

            # re: HDU 3584 HDOJ 3584 Cube ACM 3584 IN HDU  回復  更多評論   

            2011-04-07 19:51 by
            你好,我是一個代碼初學者,也是在HD里做題目的,看了你的解析,相當的蛋疼。。。完全是看不懂,汗,不過看得出你狠厲害啊!呵呵。。。。
            尹人香蕉久久99天天拍| 99久久精品无码一区二区毛片 | AA级片免费看视频久久| 亚洲精品乱码久久久久久| 2021国产精品午夜久久| 日韩AV毛片精品久久久| 精品久久久久久无码不卡| 99精品国产综合久久久久五月天 | 亚洲日韩欧美一区久久久久我 | 伊人久久综合热线大杳蕉下载| 91久久精品视频| 亚洲人成无码久久电影网站| 婷婷久久久亚洲欧洲日产国码AV| 久久精品国产亚洲av高清漫画| 97r久久精品国产99国产精| 女同久久| 久久久久噜噜噜亚洲熟女综合| 性欧美丰满熟妇XXXX性久久久| 久久精品国产福利国产秒| 一本一本久久a久久精品综合麻豆| 久久精品国产男包| 久久综合九色综合欧美就去吻| 久久99国产综合精品| 久久热这里只有精品在线观看| 韩国免费A级毛片久久| 久久99亚洲网美利坚合众国| 久久久国产打桩机| 狠狠色噜噜色狠狠狠综合久久| 久久久久国产精品嫩草影院| 色悠久久久久久久综合网| 久久久久女教师免费一区| 亚洲国产视频久久| 久久久久久久久66精品片| 久久久久亚洲av成人网人人软件 | 国产V综合V亚洲欧美久久| 久久99国产精品久久99| 9191精品国产免费久久| 久久久久这里只有精品| 久久99精品国产麻豆宅宅| 99久久这里只有精品| 久久亚洲电影|