青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

ACM___________________________

______________白白の屋
posts - 182, comments - 102, trackbacks - 0, articles - 0
<2010年9月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

常用鏈接

留言簿(24)

隨筆分類(332)

隨筆檔案(182)

FRIENDS

搜索

積分與排名

最新隨筆

最新評論

閱讀排行榜

評論排行榜


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

 

題目地址:

 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
 

 

一開始沒想明白怎么做 ,  仔細(xì)想了想,   再次 讀題后 發(fā)現(xiàn) , n <= 200000;  也就是說  最多 也就 200000 條廣告 , 你就算每行貼一張 ,

最多也就貼到 200000 行,  所以  不要被  h <= 10^9  次方嚇到了  ,認(rèn)為 線段樹開不了那么大的數(shù)組  . 只要開 200000 就可以了 .

 

其他的 沒什么 好說的 , 知道這個(gè) 就直接 暴 吧 ............將近 7000MS .=水過.................   g++提交 還華麗的 送出了 一次 TLE....

C++  水過了 ............

 

//    一直沒明白 為什么我的 代碼速度 那么 慢,  查詢后 更新 的時(shí)間是 2000MS 左右  , 我的 是 查詢 就更新了,

竟然要 將近 7000MS ? 非常 郁悶 ,  不信邪的 繼續(xù) 檢查 代碼, 在 瞪了 1哥小時(shí)后 , 忽然想到 : 把 cout 改成

printf 會(huì)怎樣?   結(jié)果 :  1640 MS  AC ..............鬼知道他的 數(shù)據(jù)量有多大..... cout 和 printf

竟然 差了 5000 MS 的時(shí)間 ...........無語

代碼如下 :

 

 /*

Coded By  : MiYu

Link      : http://www.cnblogs.com/MiYu  || http://m.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;      //杯具的地方

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;

}

 

 

 

 

另 附上 傻崽  神牛 代碼 :

 

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

 

 

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲免费观看| 国产伦理一区| 久久精品导航| 中文国产成人精品| 亚洲国产日韩欧美在线99 | 91久久国产综合久久| 久久久久久穴| 欧美中文字幕| 午夜天堂精品久久久久| 一区二区三区欧美在线| 亚洲欧洲精品一区二区| 一区三区视频| 激情一区二区三区| 国产亚洲免费的视频看| 国产精品日韩欧美一区| 欧美视频日韩视频在线观看| 欧美激情久久久| 免费欧美网站| 免费一级欧美片在线播放| 久久久久国产精品一区三寸| 久久se精品一区精品二区| 亚洲一区二区欧美日韩| 中文在线不卡| 亚洲一区视频在线| 亚洲永久字幕| 午夜精品国产| 欧美一区二区视频在线观看2020| 香蕉久久精品日日躁夜夜躁| 亚洲欧美一区在线| 欧美一区二区视频在线观看2020 | 欧美一级片在线播放| 亚洲伊人第一页| 亚洲欧美在线观看| 欧美一级黄色录像| 久久久久这里只有精品| 久热精品视频在线| 欧美福利一区二区| 亚洲高清不卡| 亚洲三级视频| 亚洲最新在线视频| 亚洲一区二区三区四区五区午夜 | 99在线热播精品免费99热| av成人免费在线观看| 亚洲在线视频| 久久久激情视频| 免费毛片一区二区三区久久久| 欧美刺激性大交免费视频 | 欧美一区二区成人| 欧美一区二区三区免费观看视频 | 欧美69视频| 欧美日韩精品欧美日韩精品一| 国产精品成人午夜| 国产视频一区在线观看一区免费| 黄色一区二区三区| 亚洲精品视频在线| 亚洲一区二区成人| 久久久久成人精品| 亚洲福利电影| 亚洲综合大片69999| 久久精品在线免费观看| 欧美福利视频一区| 国产欧美三级| 亚洲狠狠婷婷| 午夜精品国产精品大乳美女| 久久影院午夜片一区| 亚洲精品免费一二三区| 性xx色xx综合久久久xx| 久久影视三级福利片| 欧美性大战久久久久| 在线观看成人网| 亚洲午夜视频在线| 美女国产精品| 亚洲午夜精品一区二区| 久久综合久久综合久久综合| 欧美午夜不卡| 亚洲国产天堂久久综合| 亚洲欧美视频在线观看| 欧美激情国产日韩| 午夜精品久久久久久久99樱桃| 欧美.www| 国产有码一区二区| 亚洲午夜激情免费视频| 欧美jizz19性欧美| 亚洲主播在线| 欧美精品在线一区二区三区| 国产一区二区三区高清在线观看 | 欧美性一二三区| 亚洲福利视频专区| 欧美在线91| 亚洲看片免费| 鲁大师成人一区二区三区| 国产美女高潮久久白浆| 夜色激情一区二区| 欧美国产日产韩国视频| 欧美一区成人| 国产精品久久久91| 亚洲精品孕妇| 免费国产一区二区| 欧美伊人久久久久久久久影院| 欧美日韩日本网| 亚洲乱码一区二区| 老鸭窝亚洲一区二区三区| 亚洲一区精彩视频| 欧美日韩中字| 一级日韩一区在线观看| 亚洲国产精品va在线观看黑人| 久久久久成人精品| 国产一在线精品一区在线观看| 亚洲欧美色一区| 一区二区三区导航| 欧美日韩国产高清视频| 亚洲精品国产无天堂网2021| 欧美成人免费播放| 久久免费观看视频| 在线不卡中文字幕播放| 麻豆国产精品一区二区三区| 久久精品国产视频| 国产综合激情| 久久九九久精品国产免费直播| 亚洲尤物影院| 国产欧美日韩视频一区二区| 欧美在线二区| 亚洲欧美综合网| 国产日韩欧美精品综合| 欧美一区午夜精品| 香蕉国产精品偷在线观看不卡 | 免费永久网站黄欧美| 久久九九精品| 在线日韩日本国产亚洲| 欧美成人一品| 欧美高清不卡在线| 亚洲免费av片| 日韩午夜电影av| 国产精品久久久久一区二区三区| 亚洲一区二三| 午夜精品福利视频| 韩国av一区二区三区四区| 美女露胸一区二区三区| 女女同性精品视频| 99re66热这里只有精品3直播| 日韩天天综合| 国产精品亚洲人在线观看| 久久精品国产清高在天天线| 久久精品国产99国产精品澳门| 亚洲电影激情视频网站| 亚洲国产精品久久91精品| 欧美日韩专区在线| 久久精品夜色噜噜亚洲aⅴ| 久久久另类综合| 99精品久久久| 亚洲男人av电影| 在线精品高清中文字幕| 亚洲精品国产拍免费91在线| 欧美日韩在线直播| 久久精品国产亚洲精品| 麻豆国产精品一区二区三区| 亚洲视频在线免费观看| 欧美一区二区精品久久911| 在线欧美影院| 一区二区三区成人精品| 国外成人网址| 亚洲美女尤物影院| 国产一区二区三区在线播放免费观看| 欧美大片一区二区| 国产精品剧情在线亚洲| 免费看黄裸体一级大秀欧美| 欧美日韩少妇| 毛片一区二区三区| 欧美无乱码久久久免费午夜一区| 久久男人资源视频| 欧美日韩午夜剧场| 老司机午夜精品视频在线观看| 欧美日产在线观看| 久久久亚洲人| 欧美亚州在线观看| 欧美暴力喷水在线| 国产嫩草一区二区三区在线观看| 欧美大片国产精品| 国产精品自在线| 亚洲国产专区| 黄色一区二区在线观看| 一本一本大道香蕉久在线精品| 一区二区在线不卡| 亚洲一区二区三区涩| 亚洲久久在线| 久久久久久久性| 午夜精品久久久久久久99樱桃| 牛牛影视久久网| 久久一区免费| 国产乱人伦精品一区二区| 亚洲精品一区二区三区av| 韩国av一区二区三区| 亚洲一区亚洲| 亚洲一二三区在线| 欧美激情一区二区三区在线| 久久综合久色欧美综合狠狠 | 国产精品观看| 亚洲人妖在线| 91久久精品美女高潮| 久久久久国产一区二区三区四区 |