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>
- #include <algorithm>
- using namespace std;
- typedef long long ll;
- stack <ll> s, d;
- ll a[100000], l[100000], r[100000];
- int main()
- {
- ll n;
- cin >> n;
- for (int i = 0; i < n; i++)
- cin >> a[i];
- cout << 1 << endl;
- s.push(a[0]);
- l[0] = 0;
- for (int i = 1; i < n; i++)
- {
- ll x = s.top();
- s.pop();
- while (1)
- {
- if (s.empty())
- break;
- if (s.top() >= x)
- break;
- s.pop();
- }
- s.push(x);
- l[i] = s.size();
- s.push(a[i]);
- }
- reverse(a, a + n);
- d.push(a[0]);
- r[0] = 0;
- for (int i = 1; i < n; i++)
- {
- ll x = d.top();
- d.pop();
- while (1)
- {
- if (d.empty())
- break;
- if (d.top() >= x)
- break;
- d.pop();
- }
- d.push(x);
- 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