Advertisement
bibaboba12345

Untitled

Dec 10th, 2022
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. // clang-format off
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <bitset>
  6. #include <vector>
  7. #include <algorithm>
  8. #include <random>
  9. #include <map>
  10. #include <string>
  11. #include <set>
  12. #include <deque>
  13. #include <cassert>
  14.  
  15.  
  16.  
  17. const int N = 3e5 + 7, A = 26, C = 2, MOD = 998244353, bl = 350;
  18. #define int long long
  19. const long long INF = 2e9;
  20. using namespace std;
  21. using ll = long long;
  22. using ld = long double;
  23.  
  24. const ld EPS = 1e-9;
  25. int n, m;
  26.  
  27. struct Index {
  28. int ind;
  29. };
  30.  
  31. int a[N];
  32.  
  33. bool operator < (Index a1, Index b1) {
  34. return a[a1.ind] > a[b1.ind];
  35. }
  36.  
  37. set<Index> s;
  38.  
  39. char answ[N];
  40. bool taken[N];
  41.  
  42. void solve() {
  43. cin >> n;
  44. for (int i = 0; i < n; i++) {
  45. if (i % 2) {
  46. answ[i] = ')';
  47. }
  48. else {
  49. answ[i] = '(';
  50. }
  51. taken[i] = 0;
  52. }
  53. s.clear();
  54. for (int i = 0; i < n; i++) {
  55. cin >> a[i];
  56. }
  57. for (int j = 0; j < 1; j++) {
  58. s.clear();
  59. for (int i = 0; i < n; i++) {
  60. if (answ[i] == '(') {
  61. if (s.empty() || a[(s.begin()->ind)] < a[i]) {
  62. continue;
  63. }
  64. int ind = s.begin()->ind;
  65. answ[ind] = '(';
  66. answ[i] = ')';
  67. s.erase(s.begin());
  68. s.insert({ i });
  69. }
  70. else {
  71. s.insert({ i });
  72. }
  73. }
  74. }
  75. for (int i = 0; i < n; i++) {
  76. cout << answ[i];
  77. }
  78. cout << "\n";
  79. }
  80.  
  81. signed main() {
  82. #ifdef _DEBUG
  83. freopen("input.txt", "r", stdin);
  84. #else
  85. std::ios::sync_with_stdio(false);
  86. cin.tie(0);
  87. #endif
  88. int t;
  89. cin >> t;
  90. while (t--) {
  91. solve();
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement