QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#616624#4212. Bracketsucup-team3659RE 0ms0kbC++172.5kb2024-10-06 09:20:152024-10-06 09:20:17

Judging History

你现在查看的是最新测评结果

  • [2024-10-06 09:20:17]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-06 09:20:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int read() {
    int x = 0, f = 1; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -f; c = getchar();}
    while (c >= '0' && c <= '9') {x = x * 10 + (c ^ 48); c = getchar();}
    return x * f;
}
const int N = 1e6 + 5, INF = 0x3f3f3f3f;
int n, ans;
int a[N << 1], vis[N], nxt[N << 1], b[N << 1];
struct Seg {
    #define lx x << 1
    #define rx x << 1 | 1
    int mn[N << 3], tag[N << 3];
    void upd(int x, int w) {
        mn[x] += w;
        tag[x] += w;
    }
    void pushup(int x) {
        mn[x] = min(mn[lx], mn[rx]);
    }
    void pushdown(int x) {
        if (!tag[x]) return;
        upd(lx, tag[x]); upd(rx, tag[x]);
        tag[x] = 0;
    }
    void change(int x, int l, int r, int w, int L, int R) {
        if (l <= L && R <= r) return upd(x, w);
        pushdown(x);
        int mid = L + R >> 1;
        if (l <= mid) change(lx, l, r, w, L, mid);
        if (r > mid) change(rx, l, r, w, mid + 1, R);
        pushup(x);
    }
    int query(int x, int l, int r, int L, int R) {
        if (l <= L && R <= r) return mn[x];
        pushdown(x);
        int mid = L + R >> 1, res = INF;
        if (l <= mid) res = min(res, query(lx, l, r, L, mid));
        if (r > mid) res = min(res, query(rx, l, r, mid + 1, R));
        return res;
    }
} seg;
void Solve() {
    n = read();
    if (n & 1) return void(puts("("));
    for (int i = 1; i <= n * 2; i++) a[i] = read();
    for (int i = 1; i <= n * 2; i += 2) seg.change(1, 1, i, 1, 1, n * 2);
    for (int i = n * 2; i; i--) {
        nxt[i] = b[a[i]];
        b[a[i]] = i;
    }
    for (int i = 1; i <= n * 2; i++) b[i] = 0;
    for (int i = 1; i <= n * 2; i++) {
        if (vis[a[i]]) continue;
        vis[a[i]] = 1;
        int x = i, y = nxt[i];
        if (seg.query(1, 1, x, 1, n * 2) > 1 && seg.query(1, 1, y, 1, n * 2)) {
            b[x] = b[y] = 0;
            seg.change(1, 1, x, -1, 1, n * 2);
            seg.change(1, 1, y, -1, 1, n * 2);
        }
        else b[x] = b[y] = 1;
    }
    int cnt0 = 0, fl = 1;
    for (int i = 1; i <= n * 2; i++) {
        if (!b[i]) cnt0++;
        else cnt0--;
        if (cnt0 < 0) fl = 0;
    }
    if (!fl) return void(puts("("));
    for (int i = 1; i <= n * 2; i++) putchar(b[i] + '('); putchar('\n');
}
int main() {
    freopen("fate.in", "r", stdin);
    freopen("fate.out", "w", stdout);
    int _ = 1;
    while (_--) Solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

2
1 2 1 2

output:


result: