91B.md (1768B)
1 Source: https://codeforces.com/problemset/problem/91/B 2 3 B. Queue 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 There are *n* walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the *n*-th walrus stands at the beginning of the queue. The *i*-th walrus has the age equal to *a**i*. 22 23 The *i*-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such *j* (*i* < *j*), that *a**i* > *a**j*. The displeasure of the *i*-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the *i*-th one. That is, the further that young walrus stands from him, the stronger the displeasure is. 24 25 The airport manager asked you to count for each of *n* walruses in the queue his displeasure. 26 27 Input 28 29 The first line contains an integer *n* (2 ≤ *n* ≤ 105) — the number of walruses in the queue. The second line contains integers *a**i* (1 ≤ *a**i* ≤ 109). 30 31 Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. 32 33 Output 34 35 Print *n* numbers: if the *i*-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the *i*-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. 36 37 Examples 38 39 Input 40 41 ``` 42 6 43 10 8 5 3 50 45 44 ``` 45 46 Output 47 48 ``` 49 2 1 0 -1 0 -1 50 ``` 51 52 Input 53 54 ``` 55 7 56 10 4 6 3 2 8 15 57 ``` 58 59 Output 60 61 ``` 62 4 2 1 0 -1 -1 -1 63 ``` 64 65 Input 66 67 ``` 68 5 69 10 3 1 10 11 70 ``` 71 72 Output 73 74 ``` 75 1 0 -1 -1 -1 76 ```