Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- // tiom4eg's precompiler options
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- // IO settings
- #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
- // Quick types
- #define ll long long
- #define ld long double
- #define ull unsigned long long
- #define pii pair <int, int>
- #define vi vector <int>
- #define mi vector <vector <int>>
- // Quick functions
- #define endl "\n"
- #define F first
- #define S second
- #define all(a) a.begin(), a.end()
- #define sz(a) (int)(a.size())
- #define pb push_back
- #define mp make_pair
- // Quick fors
- #define FOR(i, a, b) for (int i = a; i < b; ++i)
- #define FORS(i, a, b, c) for (int i = a; i < b; i += c)
- #define RFOR(i, a, b) for (int i = a; i >= b; --i)
- #define EACH(e, a) for (auto& e : a)
- // Pragmas
- #ifndef TIOM4EG
- #pragma GCC optimize("O3,unroll-loops") // let the chaos begin!
- #pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt,tune=native")
- #pragma GCC comment(linker, "/stack:200000000")
- #endif
- // PBDS
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
- #define ook order_of_key
- #define fbo find_by_order
- using namespace __gnu_pbds;
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- using namespace std;
- mt19937 rng(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count());
- //#define int long long
- const int INF = 1e9 + 7, INFLL = 1e13 + 7, MD = 998244353, MAX = 1 << 19, MOD = 1e9 + 7, LG = 30, B = 31, S = 10008;
- int n, R, v[MAX], d[MAX];
- char ans[MAX];
- void build() {
- FOR(i, 0, n) v[R + i] = (n - i) / 2;
- RFOR(i, R - 1, 1) v[i] = min(v[2 * i], v[2 * i + 1]);
- FOR(i, 0, R + n) d[i] = 0;
- }
- void push(int nd) {
- v[nd] -= d[nd];
- if (nd < R) d[2 * nd] += d[nd], d[2 * nd + 1] += d[nd];
- d[nd] = 0;
- }
- void upd(int ql, int qr, int nd = 1, int nl = 0, int nr = R) {
- push(nd);
- if (qr <= nl || nr <= ql) return;
- if (ql <= nl && nr <= qr) {
- ++d[nd], push(nd);
- return;
- }
- int nm = (nl + nr) / 2;
- upd(ql, qr, 2 * nd, nl, nm), upd(ql, qr, 2 * nd + 1, nm, nr);
- v[nd] = min(v[2 * nd], v[2 * nd + 1]);
- }
- int get(int ql, int qr, int nd = 1, int nl = 0, int nr = R) {
- push(nd);
- if (qr <= nl || nr <= ql) return INF;
- if (ql <= nl && nr <= qr) return v[nd];
- int nm = (nl + nr) / 2;
- return min(get(ql, qr, 2 * nd, nl, nm), get(ql, qr, 2 * nd + 1, nm, nr));
- }
- void solve() {
- cin >> n;
- R = 1; while (R < n) R <<= 1;
- FOR(i, 0, n) ans[i] = ')';
- build();
- vector <pii> pos(n);
- FOR(i, 0, n) cin >> pos[i].F, pos[i].S = i;
- sort(all(pos)), reverse(all(pos));
- int c = 0;
- FOR(i, 0, n) {
- if (c == n / 2) break;
- if (!get(0, pos[i].S + 1)) continue;
- ++c, ans[pos[i].S] = '(', upd(0, pos[i].S + 1);
- }
- FOR(i, 0, n) cout << ans[i];
- cout << endl;
- }
- signed main() {
- fastIO;
- int tc; cin >> tc;
- while (tc--) solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement