daily pastebin goal
66%
SHARE
TWEET

ttt

a guest Mar 25th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <algorithm>
  2. #include <vector>
  3. #include <iostream>
  4. #include <set>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     int n, k;
  10.     vector<int> a;
  11.     set<pair<int, int>> s;
  12.     cin >> n;
  13.     vector<int> m(n, -1), x(n, -1);
  14.     for (int i = 0; i < n; i++) {
  15.         cin >> k;
  16.         a.push_back(k);
  17.         auto j = upper_bound(s.begin(), s.end(), make_pair(k, 0));
  18.         if (j != s.end()) {
  19.             m[i] = (*j).second;
  20.         }
  21.         s.insert(make_pair(k, i));
  22.     }
  23.     s.clear();
  24.     for (int i = 0; i < n; i++) {
  25.         auto j = upper_bound(s.begin(), s.end(), make_pair(a[i] * (-1), 0));
  26.         if (j != s.end()) {
  27.             x[i] = (*j).second;
  28.         }
  29.         s.insert(make_pair(a[i] * (-1), i));
  30.     }
  31.     for (int i = 1; i < n; i++) {
  32.         cout << a[max(m[i], x[i])] << ' ';
  33.     }
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top