Lost cows
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 9646 |
|
Accepted: 6207 |
Description
N (2 <= n <= 8,000) cows has 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 be Fore Dinner. When it was time-to-line up for their evening meal, they do not line up in the required ascending numerical order of thei R brands.
Regrettably, FJ does not has a-to sort them. Furthermore, he ' s not very good at observing problems. Instead of writing cow ' s brand, he determined a rather silly statistic:for each cow on line, he knows the Numbe R of cows that precede that cow on line that does, in fact, has 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 has brands smaller than th At cow. Of course, no cows precede the first cow in line, so she was not listed. Line 2 of the input describes the number of preceding cows whose brands is smaller than the cow in slot #2; Line 3 describes the number of preceding cows whose brands is 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 on line; Line 2 tells the brand of the second cow; And so on.
Sample Input
51210
Sample Output
24531
Source
Usaco 2003 U S Open Orange
Knock over the code:
1#include <cstdio>2#include <cmath>3#include <cstring>4#include <string>5#include <algorithm>6#include <iostream>7#include <stack>8 using namespacestd;9 #defineSize 8000Ten structnode{ One intL,r,snum; A }; -Node node[size*4+5]; - intFir[size+5],brand[size+5]; the voidBuildintRootintLintR) { -Node[root].l=l; -Node[root].r=R; -node[root].snum=r-l+1; + if(l==R) { - return; + } A intMid= (L+R)/2; atBuild (root*2, l,mid); -Build (root*2+1, mid+1, R); - } - intQueryintRootintk) { -node[root].snum--; - if(node[root].l==NODE[ROOT].R) { in returnNODE[ROOT].L; - } to if(node[root*2].snum>=k) { + returnQuery (root*2, k);//in a tree rooted in root, you can make this number a K. - } the Else{ * returnQuery (root*2+1, k-node[root*2].snum); $ }Panax Notoginseng } - intMain () { the //freopen ("D:\\input.txt", "R", stdin); + intN; A while(SCANF ("%d", &n)! =EOF) { theBuild1,1, n); + intI=2; -fir[1]=0; $ for(; i<=n;i++) scanf ("%d",&fir[i]); $ for(i=n;i>=1; i--){ -Brand[i]=query (1, fir[i]+1); - } the for(i=1; i<=n;i++){ -cout<<brand[i]<<Endl;Wuyi } the } - return 0; Wu}
POJ 2182 Lost Cows