QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#188451#5504. Flower GardenAPJifengcWA 3ms69120kbC++144.7kb2023-09-25 20:40:002023-09-25 20:40:00

Judging History

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

  • [2023-09-25 20:40:00]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:69120kb
  • [2023-09-25 20:40:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1200005;
int T;
int n, q, tot;
int t1[MAXN], t2[MAXN];
vector<int> e[MAXN], t[MAXN];
int dfn[MAXN], low[MAXN], dcnt, inStack[MAXN], stk[MAXN], top;
int scc[MAXN], scccnt, siz[MAXN];
bool vis[MAXN];
#define lc (i << 1)
#define rc (i << 1 | 1)
void build(int i = 1, int l = 1, int r = 3 * n) {
    if (l == r) {
        t1[i] = t2[i] = l;
        return;
    }
    t1[i] = ++tot, t2[i] = ++tot;
    int mid = (l + r) >> 1;
    build(lc, l, mid), build(rc, mid + 1, r);
    e[t1[lc]].push_back(t1[i]), e[t1[rc]].push_back(t1[i]);
    e[t2[i]].push_back(t2[lc]), e[t2[i]].push_back(t2[rc]);
}
void add1(int a, int b, int v, int i = 1, int l = 1, int r = 3 * n) {
    if (a <= l && r <= b) {
        e[t1[i]].push_back(v);
        return;
    }
    int mid = (l + r) >> 1;
    if (a <= mid) add1(a, b, v, lc, l, mid);
    if (b > mid) add1(a, b, v, rc, mid + 1, r);
}
void add2(int a, int b, int v, int i = 1, int l = 1, int r = 3 * n) {
    if (a <= l && r <= b) {
        e[v].push_back(t2[i]);
        return;
    }
    int mid = (l + r) >> 1;
    if (a <= mid) add2(a, b, v, lc, l, mid);
    if (b > mid) add2(a, b, v, rc, mid + 1, r);
}
void tarjan(int u) {
    stk[++top] = u;
    inStack[u] = 1;
    dfn[u] = low[u] = ++dcnt;
    for (int v : e[u]) {
        if (!dfn[v]) {
            tarjan(v);
            low[u] = min(low[u], low[v]);
        } else if (inStack[v]) {
            low[u] = min(low[u], dfn[v]);
        }
    }
    if (low[u] == dfn[u]) {
        int id = ++scccnt;
        // printf("%d: ", id);
        while (stk[top] != u) {
            int p = stk[top--];
            // printf("%d ", p);
            inStack[p] = 0, scc[p] = id;
        }
        // printf("%d\n", u);
        inStack[u] = 0, scc[u] = id, inStack[u] = 0, top--;
    }
}
int deg[MAXN];
int main() {
    scanf("%d", &T);
    while (T--) {
        scanf("%d%d", &n, &q);
        tot = 3 * n;
        build();
        for (int i = 1; i <= q; i++) {
            int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
            int v = ++tot;
            add1(a, b, v), add2(c, d, v);
        }
        for (int i = 1; i <= tot; i++) if (!dfn[i]) tarjan(i);
        for (int i = 1; i <= 3 * n; i++) siz[scc[i]]++;
        for (int u = 1; u <= tot; u++) {
            for (int v : e[u]) {
                if (scc[u] != scc[v]) t[scc[u]].push_back(scc[v]);
            }
        }
        // for (int i = 1; i <= tot; i++) {
        //     printf("scc[%d]=%d\n", i, scc[i]);
        // }
        // for (int i = 1; i <= tot; i++) {
        //     for (int j : t[i]) {
        //         printf("%d %d\n", i, j);
        //     }
        // }
        // case 1:
        queue<int> q;
        for (int i = 1; i <= scccnt; i++) deg[i] = t[i].size();
        for (int i = 1; i <= scccnt; i++) if (!deg[i]) q.push(i);
        int sum = 0;
        while (!q.empty()) {
            int u = q.front(); q.pop();
            if (siz[u] >= n) continue;
            sum += siz[u];
            vis[u] = 1;
            if (n <= sum && sum <= 2 * n) {
                vis[0] = 1;
                goto nxt;
            }
            for (int v : t[u]) {
                if (!--deg[v]) q.push(v);
            }
        }
        // case 2:
        for (int p = 1; p <= scccnt; p++) if (siz[p] >= n) {
            for (int i = 1; i <= scccnt; i++) deg[i] = vis[i] = 0;
            vis[p] = 1;
            for (int i = 1; i <= scccnt; i++) for (int j : t[i]) deg[j]++;
            while (!q.empty()) q.pop();
            for (int i = 1; i <= scccnt; i++) if (!deg[i]) q.push(i);
            while (!q.empty()) {
                int u = q.front(); q.pop();
                for (int v : t[u]) {
                    vis[v] |= vis[u];
                    if (!--deg[v]) q.push(v);
                }
            }
            sum = 0;
            for (int i = 1; i <= scccnt; i++) if (vis[i]) sum += siz[i];
            if (n <= sum && sum <= 2 * n) {
                vis[0] = 1;
                goto nxt;
            }
        }
        nxt:;
        if (vis[0]) {
            puts("TAK");
            for (int i = 1; i <= 3 * n; i++) putchar("FR"[vis[scc[i]]]);
            putchar('\n');
        } else {
            puts("NIE");
        }
        vis[0] = 0;
        while (!q.empty()) q.pop();
        for (int i = 1; i <= tot; i++) {
            e[i].clear(), t[i].clear();
            dfn[i] = low[i] = scc[i] = siz[i] = 0;
            deg[i] = 0;
            vis[i] = 0;
        }
        dcnt = scccnt = 0;
    }
    return 0;
}
/*
2
1 3
1 1 2 2
1 2 3 3
1 1 3 3
1 3
1 1 2 2
2 2 3 3
3 3 1 1
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 69120kb

input:

2
1 3
1 1 2 2
1 2 3 3
1 1 3 3
1 3
1 1 2 2
2 2 3 3
3 3 1 1

output:

TAK
FFR
NIE

result:

wrong answer odpowiedz nie spelnia wymogow!