QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#188435#5504. Flower GardenAPJifengcWA 4ms60940kbC++144.2kb2023-09-25 20:25:452023-09-25 20:25:46

Judging History

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

  • [2023-09-25 20:25:46]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:60940kb
  • [2023-09-25 20:25:45]
  • 提交

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] = 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]);
}
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;
        while (stk[top] != u) {
            int p = stk[top--];
            inStack[p] = 0, scc[p] = id;
        }
        inStack[u] = 0, scc[u] = id, inStack[u] = 0;
    }
}
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]);
            }
        }
        // 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[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
*/

詳細信息

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 60940kb

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!