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

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 幻浪天空領(lǐng)主 閱讀(866) 評論(0)  編輯 收藏 引用 所屬分類: POJ


只有注冊用戶登錄后才能發(fā)表評論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


<2025年12月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

導(dǎo)航

統(tǒng)計

常用鏈接

留言簿(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>
            欧美亚洲专区| 亚洲少妇最新在线视频| 欧美一区二区三区成人| 一二三区精品福利视频| 欧美日韩在线不卡| 亚洲淫性视频| 亚洲免费在线| 激情成人在线视频| 亚洲高清不卡| 欧美日韩一区在线观看| 亚洲欧美第一页| 香蕉视频成人在线观看| 激情婷婷久久| 日韩午夜精品视频| 国产精品一区二区在线观看| 久久久精彩视频| 六月丁香综合| 在线综合亚洲| 久久精品欧美日韩| 亚洲精品系列| 亚洲欧美变态国产另类| 影音先锋久久精品| 日韩一级精品| 伊人久久大香线蕉av超碰演员| 亚洲国产精品va在线看黑人动漫| 欧美图区在线视频| 久久久国产精品一区| 欧美精品情趣视频| 久久精品国产第一区二区三区最新章节| 久久www成人_看片免费不卡| 亚洲人成在线观看| 亚洲伊人一本大道中文字幕| 亚洲国产乱码最新视频| 一区二区日韩欧美| 欲香欲色天天天综合和网| 日韩视频在线一区二区| 韩国在线视频一区| 中文网丁香综合网| 亚洲欧洲日夜超级视频| 亚洲欧美在线一区二区| 亚洲免费不卡| 久久精品一区| 香蕉久久夜色精品| 欧美片在线播放| 美女精品自拍一二三四| 国产精品伦一区| 亚洲欧洲日产国产网站| 国产一区二区三区自拍| 亚洲色诱最新| 中文在线资源观看视频网站免费不卡| 久久精品国产精品亚洲精品| 午夜宅男欧美| 国产精品国产| 亚洲精品永久免费| 最新亚洲一区| 老司机午夜精品| 久久久欧美一区二区| 国产精品日韩在线播放| 日韩午夜精品| 亚洲图片欧洲图片av| 欧美日本精品| 99国产精品久久久久久久| 亚洲品质自拍| 美国三级日本三级久久99| 老**午夜毛片一区二区三区| 国产午夜久久久久| 先锋影音国产一区| 久久精品青青大伊人av| 国产午夜精品在线| 性欧美在线看片a免费观看| 欧美一级一区| 国产一区二区三区高清在线观看| 亚洲一区日韩在线| 欧美自拍偷拍午夜视频| 国产欧美日韩麻豆91| 翔田千里一区二区| 久久亚洲综合色一区二区三区| 国产性做久久久久久| 久久精品一区二区三区中文字幕| 久久嫩草精品久久久精品| 黄色亚洲网站| 免费欧美电影| 亚洲伦理中文字幕| 亚洲欧美亚洲| 国产日韩亚洲欧美精品| 久久久久久有精品国产| 亚洲成人在线网| 在线视频日本亚洲性| 国产精品一区二区三区乱码 | 亚洲国产欧美一区二区三区同亚洲 | 99精品欧美一区| 亚洲永久在线| 国产综合18久久久久久| 欧美mv日韩mv国产网站| 一本久道久久久| 久久精品国产99| 亚洲三级免费| 国产精品永久| 美女视频网站黄色亚洲| 日韩视频精品| 久久精品综合网| 亚洲精品视频免费| 国产精品一国产精品k频道56| 久久激情视频久久| 亚洲人成啪啪网站| 久久精品中文字幕一区| 99视频在线观看一区三区| 国产伦精品一区二区三区照片91 | 国产亚洲毛片在线| 欧美a级片一区| 亚洲欧美日韩精品综合在线观看| 免费视频一区二区三区在线观看| 99亚洲一区二区| 在线免费观看视频一区| 欧美视频中文在线看| 久久婷婷人人澡人人喊人人爽| 9l国产精品久久久久麻豆| 久久亚洲色图| 香蕉久久夜色精品| 夜夜夜精品看看| 精品不卡一区| 国产伦精品一区二区| 欧美日韩国产综合视频在线观看中文| 午夜日韩福利| 中文有码久久| 亚洲精品四区| 亚洲国产成人高清精品| 久久久久久久久久久久久久一区 | 国内激情久久| 国产精品久久91| 欧美理论在线| 欧美成人资源| 久久亚洲综合色| 久久精选视频| 久久av二区| 欧美一区二区三区日韩| 亚洲一区二区伦理| 一区二区三区免费看| 亚洲美女av网站| 亚洲国产成人91精品| 欧美二区乱c少妇| 免费成人av在线| 蜜桃av一区二区三区| 久久久之久亚州精品露出| 欧美一级久久| 欧美一区激情视频在线观看| 午夜精品久久久久久| 亚洲综合导航| 亚洲欧美国产77777| 亚洲一区国产精品| 亚洲欧美日本精品| 午夜精品久久久久久久| 亚洲欧美在线免费| 欧美在线精品免播放器视频| 欧美一级欧美一级在线播放| 久久av一区| 久久五月激情| 欧美+亚洲+精品+三区| 亚洲国产欧美在线| 亚洲国产日韩在线一区模特| 亚洲精品乱码久久久久久日本蜜臀| 亚洲国产免费| 一区二区高清视频| 亚洲在线视频网站| 久久精品国产久精国产爱| 麻豆久久婷婷| 国产精品国产三级国产专播品爱网 | 红桃视频欧美| 亚洲欧洲精品一区二区三区不卡 | 国产精品一区二区你懂得| 国产一本一道久久香蕉| 在线观看视频免费一区二区三区| 亚洲国产成人精品女人久久久 | 亚洲午夜精品| 久久国产精品久久精品国产 | 亚洲欧美成人一区二区三区| 久久国产婷婷国产香蕉| 美女主播一区| 国产精品久久久久久久9999| 国产日韩欧美黄色| 亚洲精品1234| 欧美一区二区精品| 亚洲第一中文字幕| 亚洲一区二区在线播放| 久久亚洲综合| 国产酒店精品激情| 亚洲人精品午夜| 久久精品国产清高在天天线| 亚洲人成在线观看网站高清| 午夜精品区一区二区三| 牛牛影视久久网| 国产精品一区二区三区成人| 亚洲精品在线看| 久久精品国产免费看久久精品| 91久久精品国产91久久| 久久精品1区| 国产精品久久久一区二区三区| 亚洲福利在线观看| 欧美在线不卡| 在线视频日韩|