锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲无吗在线,欧美午夜精品久久久久久浪潮,欧美人牲a欧美精品http://www.shnenglu.com/master0503/category/8194.html涓嶉爤璦堣純鑸囧畨鎺?闋樺彇鑰屼粖鐝懼湪zh-cnMon, 24 Nov 2008 06:36:18 GMTMon, 24 Nov 2008 06:36:18 GMT602182 Lost Cowshttp://www.shnenglu.com/master0503/articles/67624.html騫繪氮澶╃┖棰嗕富騫繪氮澶╃┖棰嗕富Sat, 22 Nov 2008 12:36:00 GMThttp://www.shnenglu.com/master0503/articles/67624.htmlhttp://www.shnenglu.com/master0503/comments/67624.htmlhttp://www.shnenglu.com/master0503/articles/67624.html#Feedback0http://www.shnenglu.com/master0503/comments/commentRss/67624.htmlhttp://www.shnenglu.com/master0503/services/trackbacks/67624.htmlLost 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;
}



騫繪氮澶╃┖棰嗕富 2008-11-22 20:36 鍙戣〃璇勮
]]>
国产一区二区三区久久| 久久精品国产清自在天天线 | 亚洲精品无码久久不卡| 97精品依人久久久大香线蕉97| 久久线看观看精品香蕉国产| 无码八A片人妻少妇久久| 94久久国产乱子伦精品免费| 亚洲国产另类久久久精品黑人| 久久精品无码一区二区三区日韩| 99久久99这里只有免费的精品| 久久精品国产AV一区二区三区 | 深夜久久AAAAA级毛片免费看| 久久91亚洲人成电影网站| 国产日韩欧美久久| 国产午夜精品理论片久久| 久久这里只有精品首页| 久久国产AVJUST麻豆| 久久婷婷色综合一区二区| 国内精品久久久久久中文字幕 | 99久久99久久| 久久人人爽人人爽人人AV东京热 | 91久久国产视频| 无码久久精品国产亚洲Av影片 | 久久人与动人物a级毛片| 久久国产精品免费| 亚洲国产精品久久| 97久久精品人妻人人搡人人玩| 久久久国产打桩机| 中文字幕精品无码久久久久久3D日动漫| 久久精品成人国产午夜| 久久国产精品无码HDAV| 老司机国内精品久久久久| 伊人久久大香线焦AV综合影院| 亚洲国产天堂久久久久久| 久久无码国产| 久久综合九色综合网站| 亚洲天堂久久久| 蜜桃麻豆WWW久久囤产精品| 99精品国产免费久久久久久下载| 久久影视国产亚洲| 欧美成人免费观看久久|