Advertisement
Dennnhhhickk

ВКОШП D

Nov 5th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. // ConsoleApplication8.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <iomanip>
  7. #include <stack>
  8. #include <algorithm>
  9.  
  10. using namespace std;
  11.  
  12. typedef long long ll;
  13.  
  14. stack <ll> s, d;
  15. ll a[100000], l[100000], r[100000];
  16.  
  17. int main()
  18. {
  19.     ll n;
  20.     cin >> n;
  21.     for (int i = 0; i < n; i++)
  22.         cin >> a[i];
  23.     cout << 1 << endl;
  24.     s.push(a[0]);
  25.     l[0] = 0;
  26.     for (int i = 1; i < n; i++)
  27.         {
  28.             ll x = s.top();
  29.             s.pop();
  30.             while (1)
  31.             {
  32.                 if (s.empty())
  33.                     break;
  34.                 if (s.top() >= x)
  35.                     break;
  36.                 s.pop();
  37.             }
  38.             s.push(x);
  39.             l[i] = s.size();
  40.             s.push(a[i]);
  41.         }
  42.     reverse(a, a + n);
  43.     d.push(a[0]);
  44.     r[0] = 0;
  45.     for (int i = 1; i < n; i++)
  46.     {
  47.         ll x = d.top();
  48.         d.pop();
  49.         while (1)
  50.         {
  51.             if (d.empty())
  52.                 break;
  53.             if (d.top() >= x)
  54.                 break;
  55.             d.pop();
  56.         }
  57.         d.push(x);
  58.         r[i] = d.size();
  59.         d.push(a[i]);
  60.     }
  61.     reverse(r, r + n);
  62.     for (int i = 0; i < n; i++)
  63.     {
  64.         char ch;
  65.         cin >> ch;
  66.         if (ch == 'L')
  67.             cout << l[i] << ' ';
  68.         else
  69.             cout << r[i] << ' ';
  70.     }
  71.     cout << endl;
  72.     system("pause");
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement