Advertisement
tiom4eg

openol G 100

Jan 16th, 2023
721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.03 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. // tiom4eg's precompiler options
  3. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  4. // IO settings
  5. #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
  6. // Quick types
  7. #define ll long long
  8. #define ld long double
  9. #define ull unsigned long long
  10. #define pii pair <int, int>
  11. #define vi vector <int>
  12. #define mi vector <vector <int>>
  13. // Quick functions
  14. #define endl "\n"
  15. #define F first
  16. #define S second
  17. #define all(a) a.begin(), a.end()
  18. #define sz(a) (int)(a.size())
  19. #define pb push_back
  20. #define mp make_pair
  21. // Quick fors
  22. #define FOR(i, a, b) for (int i = a; i < b; ++i)
  23. #define FORS(i, a, b, c) for (int i = a; i < b; i += c)
  24. #define RFOR(i, a, b) for (int i = a; i >= b; --i)
  25. #define EACH(e, a) for (auto& e : a)
  26. // Pragmas
  27. #ifndef TIOM4EG
  28. #pragma GCC optimize("O3,unroll-loops") // let the chaos begin!
  29. #pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt,tune=native")
  30. #pragma GCC comment(linker, "/stack:200000000")
  31. #endif
  32. // PBDS
  33. #include <ext/pb_ds/assoc_container.hpp>
  34. #include <ext/pb_ds/tree_policy.hpp>
  35. #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
  36. #define ook order_of_key
  37. #define fbo find_by_order
  38. using namespace __gnu_pbds;
  39. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  40. using namespace std;
  41. mt19937 rng(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count());
  42. //#define int long long
  43. const int INF = 1e9 + 7, INFLL = 1e13 + 7, MD = 998244353, MAX = 1 << 19, MOD = 1e9 + 7, LG = 30, B = 31, S = 10008;
  44.  
  45. int n, R, v[MAX], d[MAX];
  46. char ans[MAX];
  47.  
  48. void build() {
  49.     FOR(i, 0, n) v[R + i] = (n - i) / 2;
  50.     RFOR(i, R - 1, 1) v[i] = min(v[2 * i], v[2 * i + 1]);
  51.     FOR(i, 0, R + n) d[i] = 0;
  52. }
  53.  
  54. void push(int nd) {
  55.     v[nd] -= d[nd];
  56.     if (nd < R) d[2 * nd] += d[nd], d[2 * nd + 1] += d[nd];
  57.     d[nd] = 0;
  58. }
  59.  
  60. void upd(int ql, int qr, int nd = 1, int nl = 0, int nr = R) {
  61.     push(nd);
  62.     if (qr <= nl || nr <= ql) return;
  63.     if (ql <= nl && nr <= qr) {
  64.         ++d[nd], push(nd);
  65.         return;
  66.     }
  67.     int nm = (nl + nr) / 2;
  68.     upd(ql, qr, 2 * nd, nl, nm), upd(ql, qr, 2 * nd + 1, nm, nr);
  69.     v[nd] = min(v[2 * nd], v[2 * nd + 1]);
  70. }
  71.  
  72. int get(int ql, int qr, int nd = 1, int nl = 0, int nr = R) {
  73.     push(nd);
  74.     if (qr <= nl || nr <= ql) return INF;
  75.     if (ql <= nl && nr <= qr) return v[nd];
  76.     int nm = (nl + nr) / 2;
  77.     return min(get(ql, qr, 2 * nd, nl, nm), get(ql, qr, 2 * nd + 1, nm, nr));
  78. }
  79.  
  80. void solve() {
  81.     cin >> n;
  82.     R = 1; while (R < n) R <<= 1;
  83.     FOR(i, 0, n) ans[i] = ')';
  84.     build();
  85.     vector <pii> pos(n);
  86.     FOR(i, 0, n) cin >> pos[i].F, pos[i].S = i;
  87.     sort(all(pos)), reverse(all(pos));
  88.     int c = 0;
  89.     FOR(i, 0, n) {
  90.         if (c == n / 2) break;
  91.         if (!get(0, pos[i].S + 1)) continue;
  92.         ++c, ans[pos[i].S] = '(', upd(0, pos[i].S + 1);
  93.     }
  94.     FOR(i, 0, n) cout << ans[i];
  95.     cout << endl;
  96. }
  97.  
  98.  
  99. signed main() {
  100.     fastIO;
  101.     int tc; cin >> tc;
  102.     while (tc--) solve();
  103. }
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement