锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久久国产精品亚洲一区,亚洲av伊人久久综合密臀性色,久久婷婷成人综合色综合http://www.shnenglu.com/MiYu/category/14861.html ______________鐧界櫧銇眿zh-cnTue, 16 Nov 2010 20:50:44 GMTTue, 16 Nov 2010 20:50:44 GMT60HDU 3468 HDOJ 3468 A Simple Problem with Integers ACM 3468 IN HDUhttp://www.shnenglu.com/MiYu/archive/2010/11/16/133824.htmlMiYuMiYuTue, 16 Nov 2010 13:28:00 GMThttp://www.shnenglu.com/MiYu/archive/2010/11/16/133824.htmlhttp://www.shnenglu.com/MiYu/comments/133824.htmlhttp://www.shnenglu.com/MiYu/archive/2010/11/16/133824.html#Feedback0http://www.shnenglu.com/MiYu/comments/commentRss/133824.htmlhttp://www.shnenglu.com/MiYu/services/trackbacks/133824.html闃呰鍏ㄦ枃

MiYu 2010-11-16 21:28 鍙戣〃璇勮
]]>
PKU 2528 POJ 2528 Mayor's posters ( 綰挎鏍?紱繪暎鍖?) ACM 2528 IN PKUhttp://www.shnenglu.com/MiYu/archive/2010/10/15/PKU-2528.htmlMiYuMiYuFri, 15 Oct 2010 03:12:00 GMThttp://www.shnenglu.com/MiYu/archive/2010/10/15/PKU-2528.htmlhttp://www.shnenglu.com/MiYu/comments/129997.htmlhttp://www.shnenglu.com/MiYu/archive/2010/10/15/PKU-2528.html#Feedback0http://www.shnenglu.com/MiYu/comments/commentRss/129997.htmlhttp://www.shnenglu.com/MiYu/services/trackbacks/129997.html闃呰鍏ㄦ枃

MiYu 2010-10-15 11:12 鍙戣〃璇勮
]]>
PKU 2352 POJ 2352 Stars ( 綰挎鏍戠増 ) ACM 2352 IN PKUhttp://www.shnenglu.com/MiYu/archive/2010/10/13/PKU-2352-POJ-2352-Stars-ACM-2352-IN-PKU.htmlMiYuMiYuWed, 13 Oct 2010 14:29:00 GMThttp://www.shnenglu.com/MiYu/archive/2010/10/13/PKU-2352-POJ-2352-Stars-ACM-2352-IN-PKU.htmlhttp://www.shnenglu.com/MiYu/comments/129780.htmlhttp://www.shnenglu.com/MiYu/archive/2010/10/13/PKU-2352-POJ-2352-Stars-ACM-2352-IN-PKU.html#Feedback0http://www.shnenglu.com/MiYu/comments/commentRss/129780.htmlhttp://www.shnenglu.com/MiYu/services/trackbacks/129780.htmlMiYu鍘熷垱, 杞笘璇鋒敞鏄?: 杞澆鑷?nbsp;______________鐧界櫧銇眿    

棰樼洰鍦板潃 :

http://poj.org/problem?id=2352

棰樼洰鎻忚堪:

Stars
Time Limit: 1000MSMemory Limit: 65536K
Total Submissions: 14814Accepted: 6404

Description

Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given star. Astronomers want to know the distribution of the levels of the stars. 

For example, look at the map shown on the figure above. Level of the star number 5 is equal to 3 (it's formed by three stars with a numbers 1, 2 and 4). And the levels of the stars numbered by 2 and 4 are 1. At this map there are only one star of the level 0, two stars of the level 1, one star of the level 2, and one star of the level 3. 

You are to write a program that will count the amounts of the stars of each level on a given map.

Input

The first line of the input file contains a number of stars N (1<=N<=15000). The following N lines describe coordinates of stars (two integers X and Y per line separated by a space, 0<=X,Y<=32000). There can be only one star at one point of the plane. Stars are listed in ascending order of Y coordinate. Stars with equal Y coordinates are listed in ascending order of X coordinate. 

Output

The output should contain N lines, one number per line. The first line contains amount of stars of the level 0, the second does amount of stars of the level 1 and so on, the last line contains amount of stars of the level N-1.

Sample Input

5
1 1
5 1
7 1
3 3
5 5

Sample Output

1
2
1
1
0
 涓庢爲鐘舵暟緇勭殑瑙f硶涓鏍?  鏌ヨ鏇存柊灝卞彲浠ヤ簡. 
	鏍戠姸鏁扮粍 瑙f硶浼犻侀棬 : http://www.cnblogs.com/MiYu/archive/2010/08/26/1808963.html 
浠g爜濡備笅 : 
/*
Mail to   : miyubai@gamil.com
Link      : http://www.cnblogs.com/MiYu  || http://www.shnenglu.com/MiYu
Author By : MiYu
Test      : 1
Complier  : g++ mingw32-3.4.2
Program   : POJ_2352
Doc Name  : Stars
*/
//#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 P{
       int x, y;
}p[15010];
int seg[100000];
int NN = 32768, res[15010];
int get ( int &n ) {
    int i = 1;
    while ( i < n ) i << 1;
    return i;    
}
void modify ( int &pos ) {
     pos += NN;
     seg[pos] ++;
     while ( pos > 1 ) {
           if ( ~pos & 1 ) seg[pos>>1] ++;
           pos >>= 1;
     }
}
int query ( int pos ) {
     pos += NN;  
     int sum = seg[pos];
     while ( pos > 1 ) {
            if ( pos & 1 ) {
                 sum += seg[pos>>1];  
            }      
            pos >>= 1;
     }   
     return sum;
}
int main ()
{
    int N;
    while ( scanf ( "%d", &N ) == 1 ) {
           int pos;
           memset ( res, 0, sizeof ( res ) );
           memset ( seg, 0, sizeof ( seg ) );
           for ( int i = 0; i < N; ++ i ) {
                  scanf ( "%d%*d", &pos );
                  res[ query ( pos ) ] ++;
                  modify ( pos );   
           }   
           for ( int i = 0; i < N; ++ i ) {
                printf ( "%d\n", res[i] );     
           } 
    }
    return 0;
}

 



MiYu 2010-10-13 22:29 鍙戣〃璇勮
]]>
HDU 3016 HDOJ 3016 Man Down ACM 3016 IN HDUhttp://www.shnenglu.com/MiYu/archive/2010/10/13/HDU-2871-HDOJ-2871-Memory-Control-ACM-2871-IN-HDU.htmlMiYuMiYuWed, 13 Oct 2010 13:26:00 GMThttp://www.shnenglu.com/MiYu/archive/2010/10/13/HDU-2871-HDOJ-2871-Memory-Control-ACM-2871-IN-HDU.htmlhttp://www.shnenglu.com/MiYu/comments/129775.htmlhttp://www.shnenglu.com/MiYu/archive/2010/10/13/HDU-2871-HDOJ-2871-Memory-Control-ACM-2871-IN-HDU.html#Feedback2http://www.shnenglu.com/MiYu/comments/commentRss/129775.htmlhttp://www.shnenglu.com/MiYu/services/trackbacks/129775.htmlMiYu鍘熷垱, 杞笘璇鋒敞鏄?: 杞澆鑷?nbsp;______________鐧界櫧銇眿    

棰樼洰鍦板潃 :

http://acm.hdu.edu.cn/showproblem.php?pid=3016

棰樼洰鎻忚堪:

Man Down

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 618    Accepted Submission(s): 197


Problem Description
The Game “Man Down 100 floors” is an famous and interesting game.You can enjoy the game from 
http://hi.baidu.com/abcdxyzk/blog/item/16398781b4f2a5d1bd3e1eed.html

We take a simplified version of this game. We have only two kinds of planks. One kind of the planks contains food and the other one contains nails. And if the man falls on the plank which contains food his energy will increase but if he falls on the plank which contains nails his energy will decrease. The man can only fall down vertically .We assume that the energy he can increase is unlimited and no borders exist on the left and the right.

First the man has total energy 100 and stands on the topmost plank of all. Then he can choose to go left or right to fall down. If he falls down from the position (Xi,Yi),he will fall onto the nearest plank which satisfies (xl <= xi <= xr)(xl is the leftmost position of the plank and xr is the rightmost).If no planks satisfies that, the man will fall onto the floor and he finishes his mission. But if the man’s energy is below or equal to 0 , he will die and the game is Over.

Now give you the height and position of all planks. And ask you whether the man can falls onto the floor successfully. If he can, try to calculate the maximum energy he can own when he is on the floor.(Assuming that the floor is infinite and its height is 0,and all the planks are located at different height).
 

Input
There are multiple test cases.

For each test case, The first line contains one integer N (2 <= N <= 100,000) representing the number of planks.

Then following N lines representing N planks, each line contain 4 integers (h,xl,xr,value)(h > 0, 0 < xl < xr < 100,000, -1000 <= value <= 1000), h represents the plank’s height, xl is the leftmost position of the plank and xr is the rightmost position. Value represents the energy the man will increase by( if value > 0) or decrease by( if value < 0) when he falls onto this plank.
 

Output
If the man can falls onto the floor successfully just output the maximum energy he can own when he is on the floor. But if the man can not fall down onto the floor anyway ,just output “-1”(not including the quote)
 

Sample Input
4 10 5 10 10 5 3 6 -100 4 7 11 20 2 2 1000 10
 

Sample Output
140
 

 /*

  棰樼洰鎻忚堪:  

          涓嶅悓楂樺害澶勬湁涓嶅悓鐨勬按騫蟲澘錛岃煩鍒拌鏉夸細鏈夎閲忓彉鍖杤錛?/p>

          闂綋涓涓漢浠庢渶楂樻澘寮濮嬶紝鍙互鍚戝乏鎴栬呭悜鍙籌紝

          绔栫洿璺沖埌涓嬮潰鐨勬澘錛屾眰涓嬭惤鍒板湴闈㈢殑鏈澶ц閲忥紝鎴栬?1銆?/p>

          綰挎鏍?dp  

          闇瑕佺敤綰挎鏍戞煡璇㈠緱鍒版瘡涓澘鐨勪袱涓鐐逛笅钀藉悗浼氬埌鍝釜鏉匡紱

          鐒跺悗鏍規(guī)嵁榪欎釜浠庢渶楂樼殑寮濮媎p灝卞彲浠ヤ簡

          dp[i] = max ( dp[i], dp[i^].v )  // dp[i^] 浠h〃鑳借蛋鍒?i 鐨勭嚎孌?nbsp;

/* 


/*

Mail to   : miyubai@gamil.com

Link      : http://www.cnblogs.com/MiYu  || http://www.shnenglu.com/MiYu

Author By : MiYu

Test      : 1

Complier  : g++ mingw32-3.4.2

Program   : HDU_3016

Doc Name  : Man Down

*/

//#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 seg_tree {

    int id, left, right;

    int mid () { return ( left + right )>>1; }  

}seg[333333];

inline void creat ( int x, int y, int rt = 1 ) {

     seg[rt].left = x;

     seg[rt].right = y;

     //0 浠h〃鍦伴潰 鍏朵粬鐨勮嚜鐒舵暟浠h〃鍚勫眰鐨勬湪鏉跨紪鍙? -1 浠h〃鏈夊鏉$嚎孌佃鐩?nbsp;

     seg[rt].id = 0;                  

     if ( x == y ) return ;

     int mid = seg[rt].mid();

     creat ( x, mid, rt << 1 );

     creat ( mid + 1, y, rt << 1 | 1 );     

}

inline void modify ( int x, int y, int id, int rt = 1 ) {

     //鎵懼埌浜嗙嚎孌? 鐩存帴淇敼ID 瑕嗙洊鎺?nbsp;

     if ( seg[rt].left == x && seg[rt].right == y ) {

         seg[rt].id = id;

         return;   

     }

     int LL = rt << 1, RR = rt << 1 | 1, mid = seg[rt].mid();

     // 鍓嶉潰娌℃湁return鎺? 閭d箞榪欐潯綰挎鑲畾鏄瑕嗙洊鐨? 灝嗗畠鐨勬爣璁頒笅浼犲悗鏍囪涓?1 

     if ( seg[rt].id != -1 ) {      

         seg[LL].id = seg[RR].id = seg[rt].id;          

         seg[rt].id = -1;

     }      

     if ( y <= mid ) modify ( x, y, id, LL ); //鍒嗘淇敼 

     else if ( x > mid ) modify ( x, y, id, RR );

     else {

          modify ( x, mid, id, LL );

          modify ( mid + 1, y, id, RR );     

     }

}

inline int query ( int pos, int rt = 1 ) {   // 鏌ヨ Pos 鎵鍦ㄧ嚎孌電殑 id  

    if ( seg[rt].id != -1 ) return seg[rt].id; //綰挎琚鐩?鐩存帴榪斿洖 ID 

    int LL = rt << 1, RR = rt << 1 | 1, mid = seg[rt].mid();

    if ( pos <= mid ) return query ( pos, LL );             //鍒嗘鏌ヨ 

    else return query ( pos, RR );    

}

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;

}

struct Plank {

       int x,y,h,v,left,right; 

       //鎸夐珮鎺掑簭       

       friend bool operator < ( const Plank &a, const Plank &b ) {

              return a.h < b.h;

       }

}pk[100010];

int dp[100010];

int main ()

{

    int N, M;

    creat ( 1, 100000 );

    while ( scan_d ( N ) ) {

           M = -1;

           for ( int i = 1; i <= N; ++ i ) {

                scan_d ( pk[i].h );scan_d ( pk[i].x );scan_d ( pk[i].y );scan_d ( pk[i].v );

                if ( pk[i].y > M ) M = pk[i].y;       // 璁板綍 鍖洪棿鏈澶у? 鍔犻熺敤鐨?nbsp;

           }

           modify  ( 1, M, 0 );

           sort ( pk + 1, pk + N + 1 );               // 鎸夐珮鎺掑簭 

           memset ( dp, 0, sizeof ( dp ) );

           dp[N] = 100 + pk[N].v;

           // 鑷簳鍚戜笂 鏇存柊 綰挎, 璁板綍 姣忔潯綰挎 宸﹀彸绔偣鑳藉埌杈劇殑 綰挎 ID 

           for ( int i = 1; i <= N; ++ i ) {          

                int x = pk[i].left = query ( pk[i].x );

                int y = pk[i].right = query ( pk[i].y );

                modify ( pk[i].x, pk[i].y, i );

           }

           int res = -1;

           //鑷《鍚戜笅 DP    dp[i] = max ( dp[i], dp[i^].v )  

           // dp[i^] 浠h〃鑳借蛋鍒?i 鐨勭嚎孌?nbsp;

           for ( int i = N; i >= 1; -- i ) {   

               if ( dp[ pk[i].left ] < dp[i] + pk[ pk[i].left ].v )

                    dp[ pk[i].left ] = dp[i] + pk[ pk[i].left ].v;

               if ( dp[ pk[i].right ] < dp[i] + pk[ pk[i].right ].v )

                    dp[ pk[i].right ] = dp[i] + pk[ pk[i].right ].v; 

           } 

           printf ( "%d\n",dp[0] > 0 ? dp[0] : -1 );

    }

    return 0;

}


 

 



MiYu 2010-10-13 21:26 鍙戣〃璇勮
]]>
HDU 2871 HDOJ 2871 Memory Control ACM 2871 IN HDUhttp://www.shnenglu.com/MiYu/archive/2010/10/07/128951.htmlMiYuMiYuThu, 07 Oct 2010 13:49:00 GMThttp://www.shnenglu.com/MiYu/archive/2010/10/07/128951.htmlhttp://www.shnenglu.com/MiYu/comments/128951.htmlhttp://www.shnenglu.com/MiYu/archive/2010/10/07/128951.html#Feedback1http://www.shnenglu.com/MiYu/comments/commentRss/128951.htmlhttp://www.shnenglu.com/MiYu/services/trackbacks/128951.html闃呰鍏ㄦ枃

MiYu 2010-10-07 21:49 鍙戣〃璇勮
]]>
PKU 3667 HDOJ 3667 Hotel ACM 3667 IN HDUhttp://www.shnenglu.com/MiYu/archive/2010/10/07/128936.htmlMiYuMiYuThu, 07 Oct 2010 09:36:00 GMThttp://www.shnenglu.com/MiYu/archive/2010/10/07/128936.htmlhttp://www.shnenglu.com/MiYu/comments/128936.htmlhttp://www.shnenglu.com/MiYu/archive/2010/10/07/128936.html#Feedback0http://www.shnenglu.com/MiYu/comments/commentRss/128936.htmlhttp://www.shnenglu.com/MiYu/services/trackbacks/128936.html闃呰鍏ㄦ枃

MiYu 2010-10-07 17:36 鍙戣〃璇勮
]]>
HDU 1540 HDOJ 1540 Tunnel Warfare ACM 1540 IN HDUhttp://www.shnenglu.com/MiYu/archive/2010/10/06/128767.htmlMiYuMiYuWed, 06 Oct 2010 03:06:00 GMThttp://www.shnenglu.com/MiYu/archive/2010/10/06/128767.htmlhttp://www.shnenglu.com/MiYu/comments/128767.htmlhttp://www.shnenglu.com/MiYu/archive/2010/10/06/128767.html#Feedback0http://www.shnenglu.com/MiYu/comments/commentRss/128767.htmlhttp://www.shnenglu.com/MiYu/services/trackbacks/128767.html闃呰鍏ㄦ枃

MiYu 2010-10-06 11:06 鍙戣〃璇勮
]]>
綰挎鏍戠殑涓縐嶇畝鍖栧疄鐜癧杞琞 by 韙忛洩璧ゅ厰 http://www.shnenglu.com/MiYu/archive/2010/10/04/128568.htmlMiYuMiYuMon, 04 Oct 2010 08:11:00 GMThttp://www.shnenglu.com/MiYu/archive/2010/10/04/128568.htmlhttp://www.shnenglu.com/MiYu/comments/128568.htmlhttp://www.shnenglu.com/MiYu/archive/2010/10/04/128568.html#Feedback0http://www.shnenglu.com/MiYu/comments/commentRss/128568.htmlhttp://www.shnenglu.com/MiYu/services/trackbacks/128568.html

 杞澆鑷?nbsp;http://www.cnitblog.com/cockerel/archive/2006/09/13/16806.html

鐩鎬俊瀵圭畻娉曡璁℃垨鑰呮暟鎹粨鏋勬湁涓瀹氫簡瑙g殑浜哄綰挎鏍戦兘涓嶄細澶檶鐢熴傚畠鏄兘澶熷湪log(MaxLen)鏃墮棿鍐呭畬鎴愮嚎孌電殑娣誨姞銆佸垹闄ゃ佹煡璇㈢瓑鎿嶄綔銆備絾涓鑸殑瀹炵幇閮芥湁鐐瑰鏉傦紙鎴戣嚜鍐欑殑鏄閫掑綊鐨勶紝姣旇緝澶氳錛夈傝岀嚎孌墊爲搴旂敤涓湁涓縐嶆槸涓撻棬閽堝鐐圭殑銆傦紙鐐規(guī)爲錛燂級瀹冪殑瀹炵幇鍗撮潪甯哥畝鍗曘?br>銆銆榪欑鏁版嵁緇撴瀯鏈変粈涔堢敤錛熸垜浠厛鏉ヨ冭檻涓涓嬩笅闈㈢殑闇姹傦紙鍏ㄩ儴瑕佹眰鍦↙ogN鏃墮棿鍐呭畬鎴愶級錛氬浣曠煡閬撲竴涓偣鍦ㄤ竴涓偣闆嗛噷鐨勫ぇ灝?#8220;鎺掑悕”錛熷緢綆鍗曪紝寮涓涓偣鏁扮粍錛屾帓涓簭錛屽啀浜屽垎鏌ユ壘灝辮浜嗭紱濡備綍鍦ㄤ竴涓偣闆嗗唴鍔ㄦ佸鍒犵偣錛熶篃寰堢畝鍗曪紝寮勪釜騫寵 鏍戝氨琛屼簡錛堟湰鏉ュ鉤琛℃爲姣旂嚎孌墊爲澶嶆潅寰楀錛屼絾鑷粠涓栫晫涓婃湁浜哠TL set榪欎箞涓ソ涓滀笢錛屽氨……^_^錛夐偅濡傛灉鎴戞棦瑕佸姩鎬佸鍒犵偣錛屼篃瑕侀殢鏃舵煡璇㈠埌涓涓偣鐨勬帓鍚嶅憿錛熼偅瀵逛笉璧鳳紝鍙兘灝辮鍑哄姩鍒版垜浠殑“鐐規(guī)爲”浜嗐?br>銆銆鍏跺疄鐜板師鐞嗗緢綆鍗曪細姣忓綋澧炲姞錛堟垨鍒犻櫎錛変竴涓ぇ灝忎負X鐨勭偣鏃訛紝灝卞湪鏍戜笂娣誨姞錛堟垨鍒犻櫎錛変竴鏉?X,MaxLen)鐨勭嚎孌碉紙涓嶅惈绔偣錛夛紝褰撹鏌ヨ涓涓偣鐨勬帓鍚嶆椂錛屽彧瑕佺湅鐪嬪叾涓婃湁澶氬皯鏉$嚎孌靛氨鍙互浜嗐傞拡瀵硅繖涓闇姹傦紝榪欓噷鏈変釜闈炲父綆鍗曠殑瀹炵幇錛堣浠ヤ笅浠g爜錛屽崄澶氳錛屽鐭簡鍚э紵錛夊叾涓璫lear()鐢ㄤ簬娓呯┖鐐歸泦錛沘dd()鐢ㄤ簬娣誨姞涓涓偣錛沜ntLs()榪斿洖灝忎簬n鐨勭偣鐨勪釜鏁幫紝涔熷氨鏄痭鐨勫崌搴忔帓鍚嶏紝綾諱技鍦癱ntGt鏄檷搴忔帓鍚嶃?br>銆銆榪欎釜鐐規(guī)爲鏈変粈涔堢敤鍛紵鍏朵腑涓涓簲鐢ㄦ椂鍦∣(NlogN)鏃墮棿鍐呮眰鍑轟竴涓帓鍒楃殑閫嗗簭鏁幫紙http://acm.zju.edu.cn/show_problem.php?pid=1484錛屼綘鏈夋洿濂界殑綆楁硶鍚楋紵嬈㈣繋浜ゆ祦錛夋柟娉曟槸姣忚鍒頒竴涓暟x錛屽氨璁╅嗗簭鏁?=cntGt(x);鐒跺悗鍐峚dd(x)銆?br>銆銆榪欎釜瀹炵幇榪樺彲浠ヨ繘琛屼竴浜涙墿灞曘傛瘮濡傚垹闄el(int n)錛屽彧瑕佹妸add(int n)涓殑++size鎹㈡垚--size錛屾妸a[i/2]++鏀規(guī)垚a[i/2]--鍗沖彲銆傚彟澶栬繕鍙互閫氳繃浜屽垎鏌ユ壘鍔熻兘鍦∣(logN)鏃墮棿鍐呮煡鍒版帓鍚嶇n鐨勭偣鐨勫ぇ灝忋傚簲璇ヤ篃鍙互涓夊洓琛屽唴鎼炲畾銆?/p>

 template < int  N > // 琛ㄧず鍙敤鍖洪棿涓篬0,N)錛屽叾涓璑蹇呴』鏄?鐨勫箓鏁?  
 
class  PointTree {
    
 int  a[ 2 * N];
    
 int  size; 
    
 void  clear() { memset( this , 0 , sizeof ( * this ));}  
    
 void  add( int  n) {
        
 int  i = N + n;  ++ size; 
        
 for ( ++ a[i]; i > 1 ; i /= 2 )
            
 if ( ~ i & 1 ) a[i / 2 ] ++ ;
    }
 
 
    
 int  cntLs( int  n) { // 緇熻灝忎簬  
 
         int  i = N + n,c = 0  // 鑻ョ粺璁″皬浜庣瓑浜庡垯c=a[i];  
 
         for (; i > 1 ; i /= 2 
            
 if (i & 1 ) c += a[i / 2 ];
         
 return  c;
    }
 

     
 int  cntGt( int  n)  return  size - a[N + n] - cntLs(n); }  
}
 

銆銆鍡瘇~~涓轟簡瑙?/span>http://acm.zju.edu.cn/show_problem.php?pid=2425榪欎竴棰橈紝榪樻槸鎶婁笂榪頒袱涓墿灞曠粰瀹炵幇浜嗗暒錛屾灉鐒朵笉闅撅細
錛堟帴涓婏級
    
void del(int n){
        
if(!a[n+=N])return;
        
--size;
        
for(--a[n]; n>1; n/=2)
            
if(~n&1)--a[n/2];
    }

    
/*  瑙e喅錛氭眰鐐歸泦涓i灝忕殑鏁?鐢?鏁拌搗)
     *    娉ㄦ剰錛氬鏋渋>=size 榪斿洖N-1 
     
*/
 
    
int operator[](int n){
        
int i=1;
        
while(i<N){
            
if(n<a[i]) i*=2;
            
else n-=a[i], i=i*2+1;
        }

        
return i-N;    
    }
    
};  
//闄勪竴涓祴璇曠▼搴?/span>
#include<iostream.h>
T
<8192> t;  
int main(){
    
char c; int n;
    
while(cin>>c){
           
if(c=='c') t.clear();
           
else{
               cin
>>n;
               
if(c=='a') t.add(n);
               
if(c=='d') t.del(n);
               
if(c=='q') cout<<t[n]<<endl;
           }
    
    }
    
               
    
return 0;
}
  
姹傜偣闆嗛噷n鐨勪釜鏁頒簡!
int cntEQ(int n){
    
return a[N+n];
}

P.S.錛?/span>
銆銆鍦ㄥ啓瀹岃繖綃囨枃绔犱竴孌墊椂闂村悗錛屾垜璁よ瘑浜嗗彟涓縐嶅姛鑳戒笂姣旇緝綾諱技鐨勬暟鎹粨鏋勶紝鍙仛“鏍戠姸鏁扮粍”銆傚畠浠湁涓嶅皯鐩鎬技涔嬪錛?/span>
  • 閽堝鐐歸泦鐨勫鐞嗭紙娣誨姞銆佸垹闄ゃ佹煡鎵撅級錛?/li>
  • 鐩鎬技鐨勬椂絀哄鏉傚害錛坙ogN鏃墮棿錛?N絀洪棿錛夛紱
  • 鐩鎬技鐨勭紪紼嬪鏉傚害錛堥兘姣旂嚎孌墊爲綆鐭緱澶氾級錛?/li>

鍥犳錛屾墍鏈夊彲浠ョ敤鏍戠姸鏁扮粍瑙e喅鐨勯棶棰橀兘鍙互鐢ㄨ繖涓?#8220;鐐規(guī)爲”鏉ヨВ鍐籌紝鍙﹀瀹冭繕鏈変互涓嬪ソ澶勶細

  • 鏇寸洿瑙傜殑杞Щ錛堜釜浜烘劅鍙楋紝涓嶄竴瀹氳鍚屾剰錛夛紱
  • 鍚屾椂鏀寔鑷笅鑰屼笂鍜岃嚜涓婅屼笅涓ょ鏂瑰悜鐨勬煡鎵懼拰鏇存柊錛岃屽悗鑰呮爲鐘舵暟緇勪笉鏀寔錛屾墍浠ユ爲鐘舵暟緇勪笉鎻愪緵鏌愪簺鍔熻兘錛屾瘮濡傝O(logN)姹傜偣闆嗕腑絎琸灝忔暟銆?/li>

posted on 2006-09-13 19:54 韙忛洩璧ゅ厰 



MiYu 2010-10-04 16:11 鍙戣〃璇勮
]]>
HDU 2795 HDOJ 2795 Billboard ACM 2795 IN HDUhttp://www.shnenglu.com/MiYu/archive/2010/09/26/127809.htmlMiYuMiYuSun, 26 Sep 2010 14:15:00 GMThttp://www.shnenglu.com/MiYu/archive/2010/09/26/127809.htmlhttp://www.shnenglu.com/MiYu/comments/127809.htmlhttp://www.shnenglu.com/MiYu/archive/2010/09/26/127809.html#Feedback0http://www.shnenglu.com/MiYu/comments/commentRss/127809.htmlhttp://www.shnenglu.com/MiYu/services/trackbacks/127809.html

MiYu鍘熷垱, 杞笘璇鋒敞鏄?: 杞澆鑷?nbsp;______________鐧界櫧銇眿    

 

棰樼洰鍦板潃:

 http://acm.hdu.edu.cn/showproblem.php?pid=2795

棰樼洰鎻忚堪:

Billboard

Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 733    Accepted Submission(s): 340


Problem Description
At the entrance to the university, there is a huge rectangular billboard of size h*w (h is its height and w is its width). The board is the place where all possible announcements are posted: nearest programming competitions, changes in the dining room menu, and other important information.

On September 1, the billboard was empty. One by one, the announcements started being put on the billboard.

Each announcement is a stripe of paper of unit height. More specifically, the i-th announcement is a rectangle of size 1 * wi.

When someone puts a new announcement on the billboard, she would always choose the topmost possible position for the announcement. Among all possible topmost positions she would always choose the leftmost one.

If there is no valid location for a new announcement, it is not put on the billboard (that's why some programming contests have no participants from this university).

Given the sizes of the billboard and the announcements, your task is to find the numbers of rows in which the announcements are placed.
 

Input
There are multiple cases (no more than 40 cases).

The first line of the input file contains three integer numbers, h, w, and n (1 <= h,w <= 10^9; 1 <= n <= 200,000) - the dimensions of the billboard and the number of announcements.

Each of the next n lines contains an integer number wi (1 <= wi <= 10^9) - the width of i-th announcement.
 

Output
For each announcement (in the order they are given in the input file) output one number - the number of the row in which this announcement is placed. Rows are numbered from 1 to h, starting with the top row. If an announcement can't be put on the billboard, output "-1" for this announcement.
 

Sample Input
3 5 5 2 4 3 3 3
 

Sample Output
1 2 1 3 -1
 

 

涓寮濮嬫病鎯蟲槑鐧芥庝箞鍋?,  浠旂粏鎯充簡鎯?   鍐嶆 璇婚鍚?鍙戠幇 , n <= 200000;  涔熷氨鏄  鏈澶?涔熷氨 200000 鏉″箍鍛?, 浣犲氨綆楁瘡琛岃創(chuàng)涓寮?,

鏈澶氫篃灝辮創(chuàng)鍒?200000 琛?  鎵浠? 涓嶈琚? h <= 10^9  嬈℃柟鍚撳埌浜? ,璁や負 綰挎鏍戝紑涓嶄簡閭d箞澶х殑鏁扮粍  . 鍙寮 200000 灝卞彲浠ヤ簡 .

 

鍏朵粬鐨?娌′粈涔?濂借鐨?, 鐭ラ亾榪欎釜 灝辯洿鎺?鏆?鍚?............灝嗚繎 7000MS .=姘磋繃.................   g++鎻愪氦 榪樺崕涓界殑 閫佸嚭浜?涓嬈?TLE....

C++  姘磋繃浜?............

 

//    涓鐩存病鏄庣櫧 涓轟粈涔堟垜鐨?浠g爜閫熷害 閭d箞 鎱?  鏌ヨ鍚?鏇存柊 鐨勬椂闂存槸 2000MS 宸﹀彸  , 鎴戠殑 鏄?鏌ヨ 灝辨洿鏂頒簡,

绔熺劧瑕?灝嗚繎 7000MS ? 闈炲父 閮侀椃 ,  涓嶄俊閭殑 緇х畫 媯鏌?浠g爜, 鍦?鐬簡 1鍝ュ皬鏃跺悗 , 蹇界劧鎯沖埌 : 鎶?cout 鏀規(guī)垚

printf 浼氭庢牱?   緇撴灉 :  1640 MS  AC ..............楝肩煡閬撲粬鐨?鏁版嵁閲忔湁澶氬ぇ..... cout 鍜?printf

绔熺劧 宸簡 5000 MS 鐨勬椂闂?...........鏃犺

浠g爜濡備笅 :

 

 /*

Coded By  : MiYu

Link      : http://www.cnblogs.com/MiYu  || http://www.shnenglu.com/MiYu

Author By : MiYu

Test      : 1

Program   : 2795

*/

//#pragma warning( disable:4789 )

#include <iostream>

#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>

using namespace std;


struct ADV {

       int left, right, val;

       int mid () { return ( left + right ) >> 1; }     

}adv[800000];

int N, W, H, w;

void creat ( int l, int r, int rt = 1 ){

     adv[rt].left = l;

     adv[rt].right = r;

     adv[rt].val = W;

     if ( l == r )

        return ;

     int mid = adv[rt].mid();

     creat ( l, mid, rt << 1 );

     creat ( mid + 1, r, ( rt << 1 ) + 1 );

}

void add ( int rt = 1, int wei = w ){

    if ( wei <= adv[rt].val ){

         if ( adv[rt].left == adv[rt].right ){

              adv[rt].val -= wei;

              //cout << adv[rt].left << endl;  //鏉叿鐨?鍦版柟

printf ( "%d\n", adv[rt].left ); 

              return ;     

         } else if ( adv[rt<<1].val >= wei ) {

                add ( rt << 1 );

                adv[rt].val = max ( adv[rt<<1].val, adv[(rt<<1)+1].val );     

         } else {

                add ( ( rt << 1 ) + 1 );

                adv[rt].val = max ( adv[rt<<1].val, adv[(rt<<1)+1].val );        

         }   

    } else {

           //cout << -1 << endl;      //鏉叿鐨勫湴鏂?/span>

puts ( "-1" );   

    }   

}

inline bool scan_ud(int &num)

{

    char in;

    in=getchar();

    if(in==EOF) return false;

    while(in<'0'||in>'9') in=getchar();

    num=in-'0';

    while(in=getchar(),in>='0'&&in<='9'){

        num*=10,num+=in-'0';

    }

    return true;

}

int main ()

{

    while ( scan_ud (H)&&scan_ud (W)&&scan_ud (N) ) {

           if ( H > 200000 )

               H = 200010;

           creat ( 1, H );

           for ( int i = 1; i <= N; ++ i ) {

                scan_ud (w);

                add ( );     

           }      

    }

    return 0;

}

 

 

 

 

鍙?闄勪笂 鍌誨唇  紲炵墰 浠g爜 :

 

#include <iostream>

#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>

#define FF(i,a) for( int i = 0 ; i < a ; i ++ )

#define FOR(i,a,b) for( int i = a ; i < b ; i ++ )

#define LL(a) a<<1

#define RR(a) a<<1|1

template<class T> inline void checkmin(T &a,T b) {if(a < 0 || a > b)a = b;}

template<class T> inline void checkmax(T &a,T b) {if(a < b) a = b;}

using namespace std;

struct Node {

int val;

int idx;

friend bool operator < (Node a , Node b) {

if(a.val == b.val) {

return a.idx > b.idx;

}

return a.val < b.val;

}

}error;

 

struct Seg_Tree{

int left,right;

Node node;

int mid() {

return (left + right)>>1;

}

}tt[800000];

 

int n , h , m;

 

void build(int l,int r,int idx) {

tt[idx].left = l;

tt[idx].right = r;

tt[idx].node.idx = l;

tt[idx].node.val = h;

if(l == r) return ;

int mid = tt[idx].mid();

build(l,mid,LL(idx));

build(mid+1,r,RR(idx));

}

 

void update(int l,int r,int val,int idx) {

if(l <= tt[idx].left && r >= tt[idx].right) {

tt[idx].node.val += val;

return ;

}

int mid = tt[idx].mid();

if(l <= mid) update(l,r,val,LL(idx));

if(mid < r) update(l,r,val,RR(idx));

tt[idx].node = max(tt[LL(idx)].node,tt[RR(idx)].node);

}

 

Node query(int w,int idx) {

if(tt[idx].node.val < w) {

return error;

}

if(tt[idx].left == tt[idx].right) {

return tt[idx].node;

}

if(tt[LL(idx)].node.val >= w) {

return query(w,LL(idx));

} else {

return query(w,RR(idx));

}

}

 

int main() {

error.idx = -1;

while(scanf("%d%d%d",&n,&h,&m) == 3) {

checkmin(n,m);

build(1,n,1);

while(m --) {

int w;

scanf("%d",&w);

Node ret = query(w,1);

printf("%d\n",ret.idx);

if(ret.idx != -1) {

update(ret.idx,ret.idx,-w,1);

}

}

}

return 0;

 

 



MiYu 2010-09-26 22:15 鍙戣〃璇勮
]]>
HDOJ 1698 HDU 1698 Just a Hook ACM 1698 IN HDUhttp://www.shnenglu.com/MiYu/archive/2010/09/17/126829.htmlMiYuMiYuFri, 17 Sep 2010 02:09:00 GMThttp://www.shnenglu.com/MiYu/archive/2010/09/17/126829.htmlhttp://www.shnenglu.com/MiYu/comments/126829.htmlhttp://www.shnenglu.com/MiYu/archive/2010/09/17/126829.html#Feedback4http://www.shnenglu.com/MiYu/comments/commentRss/126829.htmlhttp://www.shnenglu.com/MiYu/services/trackbacks/126829.html闃呰鍏ㄦ枃

MiYu 2010-09-17 10:09 鍙戣〃璇勮
]]>
HDOJ 1754 HDU 1754 I Hate It ACM 1754 IN HDUhttp://www.shnenglu.com/MiYu/archive/2010/09/15/126668.htmlMiYuMiYuWed, 15 Sep 2010 08:08:00 GMThttp://www.shnenglu.com/MiYu/archive/2010/09/15/126668.htmlhttp://www.shnenglu.com/MiYu/comments/126668.htmlhttp://www.shnenglu.com/MiYu/archive/2010/09/15/126668.html#Feedback0http://www.shnenglu.com/MiYu/comments/commentRss/126668.htmlhttp://www.shnenglu.com/MiYu/services/trackbacks/126668.htmlMiYu鍘熷垱, 杞笘璇鋒敞鏄?: 杞澆鑷?nbsp;______________鐧界櫧銇眿    

 

棰樼洰鍦板潃:

銆銆http://acm.hdu.edu.cn/showproblem.php?pid=1754

棰樼洰鎻忚堪:

銆銆

I Hate It

Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6306    Accepted Submission(s): 2267


Problem Description
寰堝瀛︽牎嫻佽涓縐嶆瘮杈冪殑涔犳儻銆傝佸笀浠緢鍠滄璇㈤棶錛屼粠鏌愭煇鍒版煇鏌愬綋涓紝鍒嗘暟鏈楂樼殑鏄灝戙?br>榪欒寰堝瀛︾敓寰堝弽鎰熴?br>
涓嶇浣犲枩涓嶅枩嬈紝鐜板湪闇瑕佷綘鍋氱殑鏄紝灝辨槸鎸夌収鑰佸笀鐨勮姹傦紝鍐欎竴涓▼搴忥紝妯℃嫙鑰佸笀鐨勮闂傚綋鐒訛紝鑰佸笀鏈夋椂鍊欓渶瑕佹洿鏂版煇浣嶅悓瀛︾殑鎴愮嘩銆?/div>
 

Input
鏈鐩寘鍚緇勬祴璇曪紝璇峰鐞嗗埌鏂囦歡緇撴潫銆?br>鍦ㄦ瘡涓祴璇曠殑絎竴琛岋紝鏈変袱涓鏁存暟 N 鍜?M ( 0<N<=200000,0<M<5000 )錛屽垎鍒唬琛ㄥ鐢熺殑鏁扮洰鍜屾搷浣滅殑鏁扮洰銆?br>瀛︾敓ID緙栧彿鍒嗗埆浠?緙栧埌N銆?br>絎簩琛屽寘鍚玁涓暣鏁幫紝浠h〃榪橬涓鐢熺殑鍒濆鎴愮嘩錛屽叾涓i涓暟浠h〃ID涓篿鐨勫鐢熺殑鎴愮嘩銆?br>鎺ヤ笅鏉ユ湁M琛屻傛瘡涓琛屾湁涓涓瓧絎?C (鍙彇'Q'鎴?U') 錛屽拰涓や釜姝f暣鏁癆錛孊銆?br>褰揅涓?Q'鐨勬椂鍊欙紝琛ㄧず榪欐槸涓鏉¤闂搷浣滐紝瀹冭闂甀D浠嶢鍒癇(鍖呮嫭A,B)鐨勫鐢熷綋涓紝鎴愮嘩鏈楂樼殑鏄灝戙?br>褰揅涓?U'鐨勬椂鍊欙紝琛ㄧず榪欐槸涓鏉℃洿鏂版搷浣滐紝瑕佹眰鎶奍D涓篈鐨勫鐢熺殑鎴愮嘩鏇存敼涓築銆?br>
 

Output
瀵逛簬姣忎竴嬈¤闂搷浣滐紝鍦ㄤ竴琛岄噷闈㈣緭鍑烘渶楂樻垚緇┿?/div>
 

Sample Input
5 6 1 2 3 4 5 Q 1 5 U 3 6 Q 3 4 Q 4 5 U 2 9 Q 1 5
 

Sample Output
5 6 5 9
Hint
Huge input,the C function scanf() will work better than cin
 

 

鎰熻濂戒箙娌℃湁A棰樹簡 , 鏈榪戜竴鐩存病鏈夌姸鎬?  璞嗚眴涔熻漿琛屼簡, 閮侀椃.......    鍥犱負鎵撶畻 涓撶簿 鏁版嵁緇撴瀯鏂歸潰,

鎵浠ヨ繖鍑犲ぉ涓鐩撮兘鍦ㄥ涔?鏁版嵁緇撴瀯, 鍐嶄竴嬈″涔犱簡 綰挎鏍? 浠ュ墠鍙細鐢ㄥ畠鏉?鏇存柊鐐?姹傚拰 , 鐜板湪緇堜簬姘翠簡涓

涓?RMQ 鐨勮8棰樹簡, HAPPY 涓涓?...

瀵逛簬 RMQ 鐨勯鐩? 鐪婸PT 涓婇潰鐨?DP 鎴戠洿鎺?rz浜?..........琛ㄧずDP鍙細鍋氭按棰?... 榪欐柟闈㈣繕鏄氦緇?br>

YCH 鍚?   涓嶈繃鐪嬩簡 sh菐宕?/a> 澶х 鍗氬鐨?綰挎鏍戜笓杈戝悗, 鍙戠幇 鐢ㄧ嚎孌墊爲澶勭悊 榪欑被闂 闈炲父鏂逛究, 淇敼鏌ヨ

閮芥槸 O (logN)鐨?,  紼嶇◢浼樺寲浜嗕笅杈撳叆, 234MS AC ........

 

浠g爜濡備笅 :

浠g爜
/*
Coded By  : MiYu
Link      : 
http://www.cnblogs.com/MiYu  || http://www.shnenglu.com/MiYu
Author By : MiYu
Test      : 1
Program   : 1754
*/
//#pragma warning( disable:4789 )
#include 
<iostream>
#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>
using namespace std;
inline 
int max ( int a, int b ){
    
return a > b ? a : b;
}
typedef 
struct seg_Tree {
    
int left, right;
    
int mid() { return (left+right)>>1; }
    
int max;
}S;
S seg[
605000];
int key[200010];
int creat ( int left, int right, int root = 1 ){
    seg[root].left 
= left;    
    seg[root].right 
= right; 
    
if ( left == right )
        
return seg[root].max = key[left];
    
int mid = seg[root].mid();
    
return seg[root].max = max ( creat ( left, mid, root << 1 ),creat ( mid + 1, right, ( root << 1 ) + 1 ) );
}

void modify ( int val, int pos, int r = 1 ){
    
if ( seg[r].left == seg[r].right ){
        seg[r].max 
= val;
        
return;
    }
    
int mid = seg[r].mid();
    
if ( pos <= mid ){
        modify ( val, pos, r 
<< 1 );
    } 
else {
        modify ( val, pos, ( r 
<< 1 ) + 1 );
    }
    seg[r].max 
= max ( seg[r<<1].max, seg[ (r<<1+ 1 ].max );
}

int quy ( int left, int right, int r = 1 ){
    
if ( seg[r].left == left && seg[r].right == right ){
        
return seg[r].max;
    }
    
int mid = seg[r].mid();
    
if ( right <= mid  ){
        
return quy ( left, right, r << 1 );
    } 
else if ( left > mid ) {
        
return quy ( left, right, (r << 1+ 1 );
    } 
else {
        
return max ( quy ( left, mid, r << 1 ), quy ( mid + 1, right, (r << 1+ 1 ) );
    }
}
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;
}
int main ()
{
    
int N, M, x, y;
    
while ( scan_d(N) && scan_d(M) ){
        
for ( int i = 1; i <= N; ++ i ){
            scan_d( key[i] );    
        }
        creat ( 
1, N );  
        while ( M -- ){
            
char ask[5];
            scanf ( 
"%s", ask );
            scan_d(x);
            scan_d(y);
            
switch ( ask[0] ){
                
case 'Q':    printf ( "%d\n", quy ( x,y ) );
                            
break;
                
case 'U':    modify ( y, x );
            }
        }
    }
    
return 0;
}

/*
5 6
1 2 3 4 5
Q 1 5
U 3 6
Q 3 4
Q 4 5
U 2 9
Q 1 5
*/


 

 




MiYu 2010-09-15 16:08 鍙戣〃璇勮
]]>HDOJ 1166 HDU 1166 鏁屽叺甯冮樀 (綰挎鏍戣В娉?ACM 1166 IN HDUhttp://www.shnenglu.com/MiYu/archive/2010/09/04/125867.htmlMiYuMiYuSat, 04 Sep 2010 04:53:00 GMThttp://www.shnenglu.com/MiYu/archive/2010/09/04/125867.htmlhttp://www.shnenglu.com/MiYu/comments/125867.htmlhttp://www.shnenglu.com/MiYu/archive/2010/09/04/125867.html#Feedback0http://www.shnenglu.com/MiYu/comments/commentRss/125867.htmlhttp://www.shnenglu.com/MiYu/services/trackbacks/125867.htmlMiYu鍘熷垱, 杞笘璇鋒敞鏄?: 杞澆鑷?nbsp;______________鐧界櫧銇眿    

 

鍏堝墠鍋氫簡榪欎竴棰? 涓嶈繃鏄敤 鏍戠姸鏁扮粍鍋氱殑, 瀵逛簬榪欎竴綾誨瀷鐨勯鐩篃鏉ヨ闈炲父鏂逛究蹇嵎. 鍏蜂綋鍦板潃 : http://www.cnblogs.com/MiYu/archive/2010/08/25/1808441.html

 

榪欏嚑澶╁浜?綰挎鏍?, 涓嶆槸寰堟槑鐧藉畠鐨勭敤閫?鍜?浣跨敤鏂規(guī)硶,  鍥犱負 鍚 鏍戠姸鏁扮粍鏄?綰挎鏍戠殑 涓縐嶇壒孌婃儏鍐?( 閮ㄥ垎璧勬枡鏄繖涔堣鐨?) .  浜庢槸灝卞張鍋氫簡涓嬈¤繖涓鐩?

涓嶈繃浣跨敤鐨勬槸綰挎鏍戠殑 鏂規(guī)硶 :

浠g爜濡備笅 :

浠g爜
/*
MiYu鍘熷垱, 杞笘璇鋒敞鏄?nbsp;: 杞澆鑷?nbsp;______________鐧界櫧銇眿
          
http://www.cnblog.com/MiYu
Author By : MiYu
Test      : 3
Program   : 1166
*/

#include 
<iostream>
#include 
<algorithm>
using namespace std;
typedef 
struct Line{ //綰挎鏍戠粨鏋勪綋
        friend 
struct optLine;
        Line () { sum 
= 0; left = right = NULL; };
        
int l,r,sum;
        
struct Line *left, *right;
}L;
typedef 
struct optLine { //綰挎鏍戞搷浣滅粨鏋?br>       void Creat ( struct Line *node, int beg, int end );
       
void modify ( struct Line *node, int pos,int val );
       
int quy ( struct Line *node, int beg, int end );     
}OPT;
void optLine::Creat ( struct Line *node, int beg, int end ){ //寤烘爲
     node
->= beg;  node->= end;
     
if ( beg == end ) return;
     
int mid = ( node->+ node->r ) >> 1;
     L 
*= new L;  L *= new L;
     node
->left = p; node->right = q;
     Creat ( p, beg, mid );   Creat ( q, mid 
+ 1, end );          
}
void optLine::modify ( struct Line *node, int pos, int val ){ //淇敼
     
if ( pos >= node->&& pos <= node->r ) node->sum += val;
     
if ( node->== node->r ) return;
     
int mid = ( node->+ node->r ) >> 1;
     
if ( mid >= pos ) modify ( node->left, pos, val );
     
else if ( mid < pos ) modify ( node->right, pos,val );
}
int optLine::quy ( struct Line *node, int beg, int end ){ //鏌ヨ
    
int sum = 0;  int mid = ( node->+ node->r ) >> 1;
    
if ( node->== beg && node->== end ) return node->sum;
    
if ( mid >= end ) return sum += quy ( node->left, beg,end );
    
else if ( beg > mid ) return sum += quy ( node->right, beg, end ); 
    
else {
          
return sum += quy ( node->left, beg, mid ) + quy ( node->right, mid+1,end );     
    }   
}
inline 
bool scan_ud(int &num) 
{
        
char in;
        
in=getchar();
        
if(in==EOF) return false;
        
while(in<'0'||in>'9'in=getchar();
        num
=in-'0';
        
while(in=getchar(),in>='0'&&in<='9'){
                num
*=10,num+=in-'0';
        }
        
return true;
}
int main ( int T, int N )
{
    scan_ud ( T );
    
for ( int ca = 1; ca <= T ; ++ ca ){
         printf ( 
"Case %d:\n",ca );
         scan_ud ( N );    OPT opt;  L 
*root = new L;   int val,x,y;
         opt.Creat ( root, 
1, N );  
         
for ( int i = 1; i <= N; ++ i ){
              scan_ud ( val );  opt.modify ( root, i, val );    
         }
         
char ask[10];  
         
while ( scanf ( "%s", ask ), ask[0!= 'E' ){
                scanf ( 
"%d%d",&x,&y );
                
switch ( ask[0] ){
                        
case 'Q':  printf ( "%d\n",opt.quy ( root, x,y ) ); break;
                        
case 'A':  opt.modify ( root, x, y ); break;
                        
case 'S':  opt.modify ( root, x, -y ); break;      
                }      
         }
    }
    
return 0;
}

 

 



MiYu 2010-09-04 12:53 鍙戣〃璇勮
]]>
久久久久久久久久免免费精品| 久久综合综合久久综合| 久久久久亚洲精品无码网址| 久久强奷乱码老熟女| 伊人久久精品影院| 久久午夜无码鲁丝片| 亚洲国产成人久久精品影视| 久久无码人妻精品一区二区三区 | 久久精品国产福利国产琪琪| 国产精品久久久久乳精品爆| 久久这里都是精品| 久久夜色精品国产噜噜麻豆| 93精91精品国产综合久久香蕉| 日日狠狠久久偷偷色综合免费| 亚洲欧美日韩中文久久| 青青草国产精品久久| 欧美国产成人久久精品| 69久久精品无码一区二区| 久久久精品视频免费观看| 亚洲va久久久噜噜噜久久| 久久综合久久综合久久综合| 色播久久人人爽人人爽人人片AV| 久久香蕉国产线看观看精品yw| 久久久久久国产精品无码下载| 麻豆亚洲AV永久无码精品久久| 久久精品中文字幕一区| 久久午夜伦鲁片免费无码| 久久亚洲国产精品123区| 久久精品蜜芽亚洲国产AV| 久久夜色撩人精品国产| 久久se精品一区精品二区| 国产欧美久久久精品影院| 大美女久久久久久j久久| 久久人人妻人人爽人人爽| 亚洲国产精品狼友中文久久久| 精品久久久久久久| 无码精品久久久久久人妻中字| 久久影视综合亚洲| 国产精品免费久久久久电影网| 久久精品麻豆日日躁夜夜躁| 麻豆精品久久久久久久99蜜桃|