Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. // 오큰수
  2.  
  3. #include <iostream>
  4. #include <cstring>
  5. using namespace std;
  6. #include <fstream>
  7. #include <cstdio>
  8. #include <cmath>
  9. #include <ctime>
  10. #include <vector>
  11. #include <stack>
  12. #include <queue>
  13. #include <functional>
  14. #include <deque>
  15. #include <numeric>
  16. #include <set>
  17. #include <climits>
  18. #include <utility>
  19. #include <map>
  20. #include <algorithm>
  21. #define INF 987654321
  22. #define MOD 1000000007
  23. typedef long long ll;
  24. typedef unsigned long long ull;
  25. inline int max( int x, int y ){ return x > y ? x : y ; }
  26. inline int min( int x, int y ){ return x < y ? x : y ; }
  27. inline ll max( ll x, ll y ){ return x > y ? x : y ; }
  28. inline ll min( ll x, ll y ){ return x < y ? x : y ; }
  29. inline ull max( ull x, ull y ){ return x > y ? x : y ; }
  30. inline ull min( ull x, ull y ){ return x < y ? x : y ; }
  31.  
  32.  
  33. int main(){
  34.  
  35. int N;
  36. int arr[1000000];
  37. int ans[1000000];
  38.  
  39. scanf("%d", &N);
  40. memset( arr, 0, sizeof(arr) );
  41. memset( ans, 0, sizeof(ans) );
  42. for( int i=0; i<N; ++i ){
  43. scanf("%d", arr+i );
  44. }
  45. stack<int> s;
  46.  
  47. for( int i=0; i<N; ++i ){
  48. if( s.empty() ){
  49. s.push( i );
  50. }else{
  51. while( !s.empty() && arr[s.top()] < arr[i] ){
  52. ans[s.top()] = arr[i];
  53. s.pop();
  54. }
  55. s.push( i );
  56. }
  57. }
  58.  
  59. while( !s.empty() ){
  60. ans[s.top()] = -1;
  61. s.pop();
  62. }
  63.  
  64. for( int i=0; i<N; ++i ){
  65. printf("%d ", ans[i]);
  66. }
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement