Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication8.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <iomanip>
- #include <stack>
- using namespace std;
- typedef long long ll;
- stack <ll> s, d;
- ll a[100000], l[100000], r[100000];
- stack <ll> rec(stack <ll> t, ll x)
- {
- stack <ll> tt;
- if (x <= t.top())
- {
- ll data = t.top();
- t.pop();
- while (1)
- {
- tt = t;
- if (t.size())
- t = rec(t, data);
- if (tt == t)
- break;
- }
- t.push(data);
- }
- else
- t.pop();
- return t;
- }
- int main()
- {
- ll n;
- cin >> n;
- for (int i = 0; i < n; i++)
- cin >> a[i];
- s.push(a[0]);
- l[0] = 0;
- for (int i = 1; i < n; i++)
- {
- s = rec(s, s.top());
- l[i] = s.size();
- s.push(a[i]);
- }
- reverse(a, a + n);
- cout << endl;
- d.push(a[0]);
- r[0] = 0;
- for (int i = 1; i < n; i++)
- {
- d = rec(d, d.top());
- r[i] = d.size();
- d.push(a[i]);
- }
- reverse(r, r + n);
- for (int i = 0; i < n; i++)
- {
- char ch;
- cin >> ch;
- if (ch == 'L')
- cout << l[i] << ' ';
- else
- cout << r[i] << ' ';
- }
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement