fork download
  1. //Believe in yourself ,( try and try and then try ), You can do it
  2. //You don't have to be great to start but you have to start to be great
  3. #include <iostream>
  4. #include<algorithm>
  5. #include<cmath>
  6. #include<string>
  7. #include<vector>
  8. #include <utility>
  9. #include <stack>
  10. #include <set>
  11. #include <map>
  12. // 2D vector vector<vector<int>>v(n,vector<int>(m));
  13. // sort and reverse in vector sort(v.begin(), v.end(), greater<int>());
  14. // str.erase(pos,len); erase in string
  15. using namespace std;
  16. #define ll long long
  17.  
  18. ll gcd(ll a, ll b)
  19. {
  20. while (b != 0)
  21. {
  22. ll a2 = a;
  23. a = b;
  24. b = a2 % b;
  25. }
  26. return a;
  27. }
  28.  
  29. ll lcm(ll a, ll b)
  30. {
  31. return a / gcd(a, b) * b;
  32. }
  33.  
  34. void soso()
  35. {
  36. ios::sync_with_stdio(0);
  37. cin.tie(NULL);
  38. cout.tie(NULL);
  39. }
  40.  
  41. int arr[100005];
  42. int main()
  43. {
  44. soso();
  45. int n; cin >> n;
  46. for (int i = 0; i < n; i++)
  47. {
  48. cin >> arr[i];
  49. }
  50. int left = 0, right = n - 1;
  51. int q; cin >> q;
  52. set<int>st;
  53. while (q--)
  54. {
  55. char c; cin >> c;
  56. if (c == 'L')
  57. {
  58. st.insert(arr[left]);
  59. left++;
  60. }
  61. if (c == 'R')
  62. {
  63. st.insert(arr[right]);
  64. right--;
  65. }
  66. if (c == 'Q')
  67. {
  68. if (st.empty())
  69. cout << -1;
  70. else
  71. {
  72. auto it=st.end();
  73. cout << *it - 1 << "\n";
  74. st.erase(*it);
  75. }
  76. }
  77. }
  78. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty