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

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>
            免费在线播放第一区高清av| 亚洲一区免费观看| 久久综合一区二区| 尤物yw午夜国产精品视频明星| 久久男人资源视频| 久久久久欧美精品| 亚洲清纯自拍| 一区二区三区四区五区精品视频 | 欧美黄在线观看| 欧美激情免费观看| 校园春色综合网| 久久久999成人| 亚洲视屏一区| 欧美在线视频免费观看| 亚洲日本中文字幕免费在线不卡| 亚洲精品乱码| 国产精品丝袜久久久久久app| 久久精品夜色噜噜亚洲a∨ | 久久精品最新地址| 亚洲精品一区二| 亚洲天堂男人| 在线观看视频日韩| 一区二区精品| 亚洲成色www久久网站| 一本色道久久加勒比精品| 国产午夜精品视频| 亚洲精品国产欧美| 国产一区99| 夜夜嗨av一区二区三区四季av | 在线成人激情视频| 一区二区国产精品| 亚洲二区在线| 午夜免费日韩视频| av成人福利| 久久欧美肥婆一二区| 亚洲影院免费观看| 欧美xart系列高清| 久久综合给合| 国产精品亚洲视频| 亚洲毛片在线看| 亚洲国产日韩美| 性欧美video另类hd性玩具| 亚洲视频在线观看| 欧美国产高清| 欧美国产丝袜视频| 伊人久久婷婷色综合98网| 亚洲视频一区| 亚洲视频免费看| 欧美99在线视频观看| 久久久久成人精品| 国产精品一区免费视频| 夜夜嗨网站十八久久| 日韩视频精品在线| 欧美韩国在线| 欧美激情中文字幕乱码免费| 国产在线精品二区| 羞羞答答国产精品www一本| 亚洲欧美日韩成人| 国产精品xnxxcom| 一区二区三区.www| 亚洲一区三区视频在线观看| 欧美日韩国产小视频| 亚洲日本精品国产第一区| 亚洲精品一区二区三| 欧美暴力喷水在线| 亚洲国产一成人久久精品| 亚洲国产精品一区制服丝袜| 久久一区二区精品| 欧美成人一区二区| 日韩一区二区电影网| 欧美久久综合| 亚洲一区二区视频在线| 亚洲女优在线| 国产一区二区三区奇米久涩| 久久精品二区亚洲w码| 久久三级福利| 91久久极品少妇xxxxⅹ软件| 免费不卡亚洲欧美| 亚洲人成在线播放| 午夜欧美精品| 在线观看视频一区二区| 欧美xxxx在线观看| 亚洲网友自拍| 美女精品网站| 亚洲午夜视频| 国产一区白浆| 欧美黄色精品| 亚洲欧美一区二区三区在线| 久久亚洲综合色一区二区三区| 亚洲国产成人精品久久| 欧美另类一区| 欧美自拍偷拍| 日韩视频在线观看一区二区| 欧美亚洲自偷自偷| 亚洲激情小视频| 国产精品高潮在线| 久久久久99| 在线视频免费在线观看一区二区| 久久久久久久性| 日韩视频―中文字幕| 国产午夜精品全部视频播放 | 午夜日韩在线| 最新热久久免费视频| 久久国产精品久久久| 91久久综合| 狠狠久久综合婷婷不卡| 欧美日韩美女在线| 久久影院午夜论| 亚洲摸下面视频| 亚洲国产成人精品视频| 久久se精品一区二区| 在线视频欧美日韩| 在线视频国产日韩| 国产亚洲激情| 国产精品久久久久婷婷| 欧美黑人多人双交| 久久久久久久久久久久久女国产乱| 日韩视频一区二区三区在线播放| 久久亚洲一区| 久久久精品久久久久| 亚洲与欧洲av电影| 亚洲最新视频在线| 亚洲精选久久| 亚洲高清不卡av| 国产一区二区三区久久 | 亚洲伊人第一页| 日韩视频欧美视频| 亚洲国产日韩在线一区模特| 久久免费偷拍视频| 久久久999| 久久精品国产视频| 欧美一区二区视频观看视频| 亚洲欧美www| 亚洲女性喷水在线观看一区| 亚洲午夜激情在线| 亚洲午夜一区二区三区| 夜夜嗨av色一区二区不卡| 亚洲精品在线视频| 日韩午夜精品| 正在播放亚洲| 亚洲一区二区精品在线观看| 中日韩男男gay无套| 亚洲性人人天天夜夜摸| 亚洲午夜久久久久久久久电影院| 99re6这里只有精品视频在线观看| 亚洲第一久久影院| 亚洲欧洲日夜超级视频| 亚洲肉体裸体xxxx137| 亚洲卡通欧美制服中文| 日韩写真视频在线观看| 一区二区三区欧美日韩| 中文一区二区| 久久国产精品一区二区三区四区| 久久九九免费| 女生裸体视频一区二区三区| 亚洲国产精品成人精品| 99re在线精品| 亚洲一区二区三区四区在线观看| 午夜精品一区二区三区四区 | 在线视频日韩精品| 午夜精品成人在线视频| 久久久91精品国产| 欧美日韩大片一区二区三区| 国产精品一区久久| 狠狠色丁香婷婷综合| 亚洲精美视频| 午夜精品一区二区三区电影天堂| 久久国产精品免费一区| 亚洲丰满在线| 亚洲在线视频网站| 久久精品一区二区国产| 欧美激情综合五月色丁香小说| 国产精品久久久久久久app| 黄色成人在线网址| 一区二区久久久久久| 久久久久国产一区二区三区四区 | 欧美国产精品va在线观看| 一区二区高清在线| 美女脱光内衣内裤视频久久网站| 欧美日韩国产首页在线观看| 国产亚洲va综合人人澡精品| 亚洲日韩欧美一区二区在线| 欧美在线一二三四区| 亚洲激情综合| 欧美在线视频一区二区三区| 欧美精品一区二区蜜臀亚洲| 国产欧美激情| 一本色道久久综合一区 | 这里只有精品丝袜| 另类国产ts人妖高潮视频| 亚洲久久在线| 久久久噜噜噜久久狠狠50岁| 国产精品视频免费观看www| 亚洲黄色一区二区三区| 久久福利一区| 亚洲午夜视频在线观看| 欧美国产一区二区在线观看| 精品动漫3d一区二区三区免费| 亚洲直播在线一区| 亚洲精品在线免费|