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

2182 Lost Cows

Lost Cows

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2824 Accepted: 1742

Description

N (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacular display of poor judgment, they visited the neighborhood 'watering hole' and drank a few too many beers before dinner. When it was time to line up for their evening meal, they did not line up in the required ascending numerical order of their brands.

Regrettably, FJ does not have a way to sort them. Furthermore, he's not very good at observing problems. Instead of writing down each cow's brand, he determined a rather silly statistic: For each cow in line, he knows the number of cows that precede that cow in line that do, in fact, have smaller brands than that cow.

Given this data, tell FJ the exact ordering of the cows.

Input

* Line 1: A single integer, N

* Lines 2..N: These N-1 lines describe the number of cows that precede a given cow in line and have brands smaller than that cow. Of course, no cows precede the first cow in line, so she is not listed. Line 2 of the input describes the number of preceding cows whose brands are smaller than the cow in slot #2; line 3 describes the number of preceding cows whose brands are smaller than the cow in slot #3; and so on.

Output

* Lines 1..N: Each of the N lines of output tells the brand of a cow in line. Line #1 of the output tells the brand of the first cow in line; line 2 tells the brand of the second cow; and so on.

Sample Input

5
1
2
1
0

Sample Output

2
4
5
3
1

Source



Analysis

Which number can we determine at the first glance of the input data? Of course, the answer is the tail. Suppose the last number of the input data, which is the number of cows with lower brand number than it, is a[n]. According to the defination, the last cow gets the (a[n]+1)th number, since there are a[n] brand number before. What's more, the brand number is constrained in range from 1 to n, so the last number is well ensured.

Later, the earlier one will be determined in a set containing the numbers range from 1 to n except b[n], which is the brand number of the last cow. Obviously, the brand number is the (a[n-1]+1)th number in the set. The problem turns to be the method to save and search used numbers. If we create a constantly array, the cost of time in deleting and searching is both O(n) and the whole cost is o(n^2). Just consider about the segment tree. Create a segment tree of range [1,n], and the number of tree[p] is the number of brands used. When a number is inserting, calculate the remaining number of the left range: m-l+1-tree[p]. If it is larger than the current number, which is a[i]+1, then searching the left child. Otherwise, search the right one. When it is searching, adding the current root since it is clear to see that a new member is coming now. At last, when the search comes to an end and find a leave, record the range number.

My code:

#include <stdio.h>
#include 
<stdlib.h>
#include 
<memory.h>
#define MAX 8000

int main(){
    
int n,i;
    
int a[MAX],b[MAX];
    
int tree[4*MAX+1];
    scanf(
"%d",&n);
    a[
0]=0;
    
for (i=1;i<n;i++)
        scanf(
"%d",a+i);
    
for (i=n-1;i>=0;i--){
        
int l,r,p,m,no;
        no
=a[i]+1;
        l
=1;r=n;p=1;
        
while (l<r){
            tree[p]
++;
            m
=(l+r)>>1;
            
if (m-l+1-tree[2*p]>=no ){
                r
=m;
                p
<<=1;
            }

            
else {
                no
-=m-l+1-tree[2*p];
                l
=m+1;
                p
=2*p+1;                
            }

        }

        tree[p]
++;
        b[i]
=l;
    }

    
for (i=0;i<n;i++)
        printf(
"%d\n",b[i]);
    
return 0;
}

posted on 2008-11-22 20:36 幻浪天空領主 閱讀(857) 評論(0)  編輯 收藏 引用 所屬分類: POJ

<2025年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

導航

統計

常用鏈接

留言簿(1)

隨筆檔案(2)

文章分類(23)

文章檔案(22)

搜索

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲欧美成aⅴ人在线观看| 欧美高清在线一区| 欧美电影专区| 久久综合狠狠| 欧美成人一区二区三区在线观看| 欧美成人资源网| 亚洲欧洲美洲综合色网| 亚洲国产精品久久久久| 亚洲精品日韩精品| 亚洲欧美日韩成人| 毛片基地黄久久久久久天堂| 欧美激情一区二区| 国产精品视频自拍| 在线日本成人| 亚洲自拍偷拍一区| 久久久亚洲国产美女国产盗摄| 蜜桃久久精品乱码一区二区| 亚洲欧洲综合另类在线| 亚洲少妇自拍| 久久视频精品在线| 国产精品麻豆va在线播放| 极品日韩久久| 欧美一级大片在线观看| 欧美激情精品久久久久久黑人 | 亚洲三级网站| 羞羞答答国产精品www一本| 卡一卡二国产精品| 妖精视频成人观看www| 欧美在线看片| 国产精品av一区二区| 亚洲电影免费在线观看| 欧美一区二区视频在线观看| 亚洲国产日韩欧美综合久久| 午夜精品久久久久久| 欧美日韩成人在线观看| 在线观看不卡av| 欧美一区二区在线免费观看| 99国产精品国产精品久久| 久久―日本道色综合久久| 国产精品一区久久久| 一区二区三欧美| 欧美激情2020午夜免费观看| 亚洲欧美日韩国产精品| 欧美日韩一区二区国产| 久久福利视频导航| 欧美日韩1080p| 国产日韩精品一区观看| 亚洲一区国产| 亚洲激情一区| 免费在线看一区| 又紧又大又爽精品一区二区| 欧美中文字幕久久| 中文日韩在线视频| 欧美日韩在线免费| 99伊人成综合| 亚洲毛片在线观看.| 欧美精品三区| 一区二区三区日韩在线观看| 欧美激情免费在线| 麻豆精品一区二区av白丝在线| 狠狠色狠狠色综合日日91app| 久久精品国产清高在天天线 | 亚洲日本中文字幕免费在线不卡| 久久成人综合网| 国一区二区在线观看| 久久理论片午夜琪琪电影网| 欧美一二区视频| 国产一区高清视频| 久久一二三区| 欧美成人一区在线| 一区二区三区www| 夜夜嗨一区二区三区| 欧美视频手机在线| 性色av香蕉一区二区| 久久精品官网| 日韩亚洲不卡在线| 亚洲欧美韩国| 亚洲国产欧美在线人成| 99视频精品免费观看| 国产嫩草影院久久久久 | 99热在这里有精品免费| 欧美午夜精品| 免费av成人在线| 欧美日韩精品三区| 久久国产精品第一页| 蜜臀99久久精品久久久久久软件 | 女人香蕉久久**毛片精品| 亚洲精品黄网在线观看| 亚洲视频一区在线| 在线播放中文字幕一区| 亚洲日本欧美天堂| 国产模特精品视频久久久久 | 亚洲一二三四久久| 欧美一区二区三区喷汁尤物| 91久久久国产精品| 亚洲欧美日韩一区二区三区在线观看| 狠狠色狠色综合曰曰| 久久最新视频| 久久国产精品电影| 免费国产自线拍一欧美视频| 欧美激情一二三区| 欧美亚洲免费在线| 韩国三级电影一区二区| 亚洲高清精品中出| 久久香蕉精品| 亚洲视频免费观看| 欧美一区二区三区日韩| 亚洲日本中文字幕| 99国产麻豆精品| 欧美日韩一区国产| 浪潮色综合久久天堂| 欧美日韩国产成人在线91| 久久精品一区二区三区四区 | 午夜国产精品视频免费体验区| 欧美日韩视频在线一区二区| 久久天天狠狠| 欧美精品一二三| 久久夜色撩人精品| 国产精品久久久久久久久果冻传媒 | 日韩写真在线| 伊人成年综合电影网| 亚洲影院高清在线| 亚洲久色影视| 久久综合狠狠综合久久综合88 | 欧美精品一区二区在线播放| 欧美一区二区免费| 欧美暴力喷水在线| 亚洲欧美日韩在线播放| 99这里有精品| 欧美成人在线免费观看| 久久免费视频在线| 国产免费一区二区三区香蕉精| 日韩一二三在线视频播| 亚洲精品偷拍| 免费一级欧美片在线观看| 久久伊人免费视频| 精品1区2区| 久久精品亚洲乱码伦伦中文 | 亚洲精品乱码久久久久久按摩观| 国内精品一区二区| 久久超碰97中文字幕| 久久久久久久久久久久久9999| 国产精品午夜视频| 亚洲午夜精品福利| 欧美亚洲在线| 国产一区二区久久精品| 欧美一区二视频| 麻豆精品精华液| 亚洲一区二区少妇| 亚洲少妇在线| 国产精品盗摄久久久| 亚洲午夜激情网站| 欧美一级理论片| 国产精品你懂的| 在线中文字幕一区| 久久精品视频在线观看| 激情偷拍久久| 免费在线国产精品| 亚洲毛片一区| 亚洲一区日韩| 国产精品一级二级三级| 欧美专区在线| 亚洲激情视频| 亚洲欧美在线磁力| 黑人中文字幕一区二区三区| 免费av成人在线| 99re66热这里只有精品3直播| 亚洲欧美在线一区二区| 在线观看视频欧美| 欧美屁股在线| 欧美自拍丝袜亚洲| 亚洲日韩欧美视频一区| 欧美一级在线视频| 亚洲第一二三四五区| 欧美日本一区二区视频在线观看| 亚洲一区亚洲二区| 欧美激情在线观看| 午夜在线精品| 亚洲日本中文字幕| 国产午夜精品一区二区三区欧美| 免费观看成人| 亚洲欧美日韩一区二区在线 | 欧美日韩亚洲三区| 久久精品国产成人| 一本久久青青| 欧美成人国产va精品日本一级| 亚洲一二三区在线| 亚洲第一黄色| 国产日韩欧美在线| 欧美日韩国产小视频在线观看| 欧美一区激情| 中文高清一区| 亚洲日本欧美在线| 免费观看日韩av| 欧美综合国产精品久久丁香| 一本大道久久a久久综合婷婷| 一区在线影院| 国产一级揄自揄精品视频| 欧美三级乱码| 欧美日韩精品一区二区在线播放|