Maybe think this problem are about girls and ladies.
But you ' re wrong. ' Left dress ' means ' Eyes left '. It ' s used in armed forces. It'll make a square more orderly.
Now several soldiers stand on a line. They is in diffient height or the same. When all of them eyes left, the first man he would see was the nearest man higher than him.
For each soldier, your should tell me the height of the first man he'll see when he eyes left.
Input
This problem has several cases.
The first line of all case are an integer N (1 < N <= 1 000 000).
Then follows a line with N integers. Indicates the height of each man. (1 <= Height <= 1 000 000).
Output
For each case, you should output everyone's first man ' s position. If one has the no first man and then output-1.
Sample input
5
1 3 2) 5 8
4
5 4 3 2
Sample output
-1-1 1-1-1
-1 0 1 2
Tips
No
Source
Xadillax
Operation
I remember writing this question a long time ago, the method is yy out of
The original method
The recent monotonous stacks are frequently appearing, so it is intended to learn the next
/************************************************************************* > File Name:NOJ1175.cpp > Auth Or:alex > Mail: [email protected] > Created time:2015 May 07 Thursday 18:03 26 seconds ******************************** ****************************************/#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>#include <queue>#include <stack>#include <map>#include <bitset>#include <set>#include <vector>using namespace STD;Const DoublePI =ACOs(-1.0);Const intINF =0x3f3f3f3f;Const DoubleEPS =1e-15;typedef Long LongLL;typedefPair <int,int> PLL;Static Const intN =1000100; Stack <PLL>StintArr[n];intAns[n];intMain () {intN while(~scanf("%d", &n)) { for(inti =0; I < n; ++i) {Ans[i] =-1;scanf("%d", &arr[i]); } while(!st.empty ()) {St.pop (); } for(inti = n-1; I >=0; -I.) {if(St.empty ()) {St.push (Make_pair (arr[i], i)); }Else{ while(!st.empty ()) {PLL u = st.top ();if(U.first >= Arr[i]) { Break; } st.pop (); Ans[u.second] = i; } st.push (Make_pair (arr[i], i)); } }printf("%d", ans[0]); for(inti =1; I < n; ++i) {printf("%d", Ans[i]); }printf("\ n"); }return 0;}
NOJ1175---Dress, left dress! (Monotonic Stack)