fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. // Speed
  5. #define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  6.  
  7. // Typedefs
  8. #define int long long
  9. #define pb push_back
  10. #define ff first
  11. #define ss second
  12. #define all(x) (x).begin(), (x).end()
  13. #define rall(x) (x).rbegin(), (x).rend()
  14. #define sz(x) ((int)(x).size())
  15. #define endl '\n'
  16. #define yes cout << "yes\n"
  17. #define no cout << "no\n"
  18.  
  19. // Loops
  20. #define rep(i,a,b) for(int i=a;i<b;++i)
  21. #define per(i,a,b) for(int i=b-1;i>=a;--i)
  22. #define each(x, a) for (auto& x : a)
  23.  
  24. // Consts
  25. const int INF = 1e18;
  26. const int MOD = 1e9+7;
  27. const int N = 2e5 + 5;
  28.  
  29. // Math
  30. int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
  31. int lcm(int a, int b) { return (a / gcd(a, b)) * b; }
  32.  
  33. int power(int a, int b, int m = MOD) {
  34. int res = 1;
  35. while (b > 0) {
  36. if (b & 1) res = res * a % m;
  37. a = a * a % m;
  38. b >>= 1;
  39. }
  40. return res;
  41. }
  42.  
  43. int modinv(int a, int m = MOD) {
  44. return power(a, m - 2, m);
  45. }
  46.  
  47. bool isGood(int a[], int n, int &x) {
  48. for (int i = 0; i <= n - 5; ++i) {
  49. if (a[i] < a[i+1] && a[i+1] < a[i+2] && a[i+2] < a[i+3] && a[i+3] < a[i+4]) {
  50. x = i;
  51. return false;
  52. }
  53. if (a[i] > a[i+1] && a[i+1] > a[i+2] && a[i+2] > a[i+3] && a[i+3] > a[i+4]) {
  54. x = i;
  55. return false;
  56. }
  57. }
  58. return true;
  59. }
  60. // Logic
  61. void solve() {
  62. int n;
  63. cin >> n;
  64. int a[n];
  65. rep(i, 0, n) cin >> a[i];
  66.  
  67. int l = 0, r = n - 1;
  68. int res_ptr = 0;
  69. char res[n];
  70.  
  71. int temp[n];
  72. int len;
  73.  
  74. while (l <= r) {
  75. len = 0;
  76. for (int i = l; i <= r; ++i)
  77. temp[len++] = a[i];
  78.  
  79. int x = -1;
  80. if (isGood(temp, len, x)) {
  81. res[res_ptr++] = 'L';
  82. l++;
  83. } else {
  84. res[res_ptr++] = 'R';
  85. res[res_ptr++] = 'L';
  86. res[res_ptr++] = 'R';
  87. res[res_ptr++] = 'L';
  88. res[res_ptr++] = 'R';
  89.  
  90. l += 3;
  91. r -= 2;
  92. }
  93. }
  94.  
  95. rep(i, 0, res_ptr) cout << res[i];
  96. cout << endl;
  97. }
  98.  
  99. // Main
  100. int32_t main() {
  101. fast_io;
  102.  
  103. int t;
  104. cin >> t;
  105. while (t--) {
  106. solve();
  107. }
  108.  
  109. return 0;
  110. }
  111.  
Success #stdin #stdout 0.01s 5296KB
stdin
6
7
1 2 3 4 5 6 7
9
1 3 6 8 9 7 5 4 2
12
1 2 11 3 6 4 7 8 12 5 10 9
6
4 1 2 5 6 3
5
1 2 3 5 4
9
5 1 8 6 2 7 9 4 3
stdout
RLRLRLL
RLRLRLLLL
LLLLLLLLLLLL
LLLLLL
LLLLL
LLLLLLLLL