Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <stack>
- using namespace std;
- void add(deque<int> &q, int x) {
- while (!q.empty() && q.back() < x)
- q.pop_back();
- q.push_back(x);
- }
- void extract(deque<int> &q, int x) {
- if (!q.empty() && q.front() == x)
- q.pop_front();
- }
- int main() {
- ifstream fin("input.txt");
- ofstream fout("output.txt");
- int n, m;
- fin >> n;
- vector<int> array;
- deque<int> q;
- for (int i = 0; i < n; i++) {
- int tmp;
- fin >> tmp;
- array.push_back(tmp);
- }
- fin >> m;
- add(q, array[0]);
- int l = 0, r = 0;
- for (int i = 0; i < m; i++) {
- char tmp;
- fin >> tmp;
- if (tmp == 'R')
- add(q, array[++r]);
- else
- extract(q, array[l++]);
- fout << q.front() << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement