QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#99139#5504. Flower GardenJohnsonloyWA 4763ms295908kbC++146.1kb2023-04-21 11:58:552023-04-21 11:58:57

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-21 11:58:57]
  • 评测
  • 测评结果:WA
  • 用时:4763ms
  • 内存:295908kb
  • [2023-04-21 11:58:55]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define db double
const int maxn = 2e6 + 10;

namespace IO {
void openfile() {
#ifndef ONLINE_JUDGE
    freopen("in.in", "r", stdin);
    freopen("out.out", "w", stdout);
#endif
}

inline int read() {
    int x = 0, f = 0;
    char c = getchar();
    while (!isdigit(c))
        f |= c == '-', c = getchar();
    while (isdigit(c))
        x = x * 10 + c - '0', c = getchar();
    if (f)
        x = -x;
    return x;
}
}  // namespace IO
using namespace IO;

int tot, n, m;
int rt1, rt2;
int dfn[maxn], low[maxn], tim, vis[maxn], sta[maxn], top, cnt, bl[maxn];
int x[maxn], y[maxn], bian, in[maxn], sz[maxn], ans[maxn];
vector<int> e[maxn], g[maxn], pos[maxn];

void add(int xx, int yy) {
    e[xx].push_back(yy);
    // cout << xx << ' ' << yy << endl;
    g[yy].push_back(xx);
    x[++bian] = xx, y[bian] = yy;
}

struct node {
    int l, r, ls, rs;
} t[maxn];

void build1(int& rt, int l, int r) {
    if (!rt)
        rt = ++tot;
    t[rt] = {l, r};
    if (l == r)
        return;
    int mid = (l + r) >> 1;
    build1(t[rt].ls, l, mid), build1(t[rt].rs, mid + 1, r);
    add(rt, t[rt].ls), add(rt, t[rt].rs);
}

void build2(int& rt, int l, int r) {
    if (!rt)
        rt = ++tot;
    t[rt] = {l, r};
    if (l == r)
        return add(rt - rt2 + 1, rt), void();
    int mid = (l + r) >> 1;
    build2(t[rt].ls, l, mid), build2(t[rt].rs, mid + 1, r);
    add(t[rt].ls, rt), add(t[rt].rs, rt);
}

void init() {
    for (int i = 1; i <= tot; i++)
        t[i] = {0, 0, 0, 0}, dfn[i] = low[i] = bl[i] = in[i] = sz[i] = vis[i] = 0, e[i].clear(),
        g[i].clear(), pos[i].clear();
    tot = tim = bian = cnt = top = rt1 = rt2 = 0;
}

void jia1(int rt, int l, int r, int x, int y, int d) {
    if (x <= l && r <= y)
        return add(d, rt), void();
    int mid = (l + r) >> 1;
    if (x <= mid)
        jia1(t[rt].ls, l, mid, x, y, d);
    if (mid < y)
        jia1(t[rt].rs, mid + 1, r, x, y, d);
}

void jia2(int rt, int l, int r, int x, int y, int d) {
    if (x <= l && r <= y)
        return add(rt, d), void();
    int mid = (l + r) >> 1;
    if (x <= mid)
        jia2(t[rt].ls, l, mid, x, y, d);
    if (mid < y)
        jia2(t[rt].rs, mid + 1, r, x, y, d);
}

void tarjan(int x) {
    vis[x] = 1, sta[++top] = x;
    low[x] = dfn[x] = ++tim;
    for (auto v : e[x]) {
        if (!dfn[v])
            tarjan(v), low[x] = min(low[x], low[v]);
        else if (vis[v])
            low[x] = min(low[x], dfn[v]);
    }
    if (dfn[x] == low[x]) {
        int y;
        cnt++;
        do {
            y = sta[top--];
            vis[y] = 0;
            bl[y] = cnt;
        } while (x != y);
    }
}

void topo() {
    queue<int> q;
    for (int i = 1; i <= cnt; i++)
        if (!in[i])
            q.push(i);
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        sta[++top] = x;
        for (auto v : e[x]) {
            in[v]--;
            if (!in[v])
                q.push(v);
        }
    }
}

void dfs(int x) {
    vis[x] = 1;
    for (auto v : e[x])
        if (!vis[v])
            dfs(v);
}

void dfs2(int x) {
    vis[x] = 0;
    for (auto v : g[x])
        if (vis[v])
            dfs2(v);
}

void solve() {
    n = read(), m = read();
    build1(rt1, 1, n * 3), build2(rt2, 1, n * 3);
    for (int i = 1; i <= m; i++) {
        int l1 = read(), r1 = read(), l2 = read(), r2 = read();
        int d1 = ++tot;
        jia2(rt2, 1, n * 3, l1, r1, d1), jia1(rt1, 1, n * 3, l2, r2, d1);
    }
    for (int i = 1; i <= tot; i++)
        if (!dfn[i])
            tarjan(i);
    for (int i = 1; i <= tot; i++)
        e[i].clear(), g[i].clear();
    for (int i = 1; i <= bian; i++) {
        if (bl[x[i]] == bl[y[i]])
            continue;
        e[bl[x[i]]].push_back(bl[y[i]]);
        in[bl[y[i]]]++;
    }
    for (int i = 1; i < rt2; i++)
        if (t[i].l == t[i].r)
            ++sz[bl[i]], pos[bl[i]].push_back(t[i].l);
    topo();
    int sum = 0, flag = 0;
    for (int i = 1; i <= top; i++) {
        sum += sz[i];
        if (sum >= n && sum <= n * 2) {
            flag = i;
            break;
        }
    }
    if (flag) {
        for (int i = 1; i <= top; i++)
            for (auto v : pos[i])
                ans[v] = (i <= flag);
        puts("TAK");
        for (int i = 1; i <= n * 3; i++)
            if (ans[i])
                putchar('F');
            else
                putchar('R');
        puts("");
        return;
    }
    for (int i = 1; i <= top; i++)
        if (sz[i] >= n) {
            for (int i = 1; i <= n; i++)
                vis[i] = 0;
            dfs(i);
            int sum = 0;
            for (int i = 1; i <= top; i++)
                if (vis[i])
                    sum += sz[i];
            if (sum >= n && sum <= n * 2) {
                for (int i = 1; i <= top; i++)
                    for (auto v : pos[i])
                        ans[v] = vis[i];
                puts("TAK");
                for (int i = 1; i <= n * 3; ++i)
                    if (ans[i])
                        putchar('F');
                    else
                        putchar('R');
                puts("");
                return;
            }
            for (int i = 1; i <= n; i++)
                vis[i] = 1;
            dfs2(i), sum = 0;
            for (int i = 1; i <= top; i++)
                if (vis[i])
                    sum += sz[i];
            if (sum >= n && sum <= n * 2) {
                for (int i = 1; i <= top; i++)
                    for (auto v : pos[i])
                        ans[v] = vis[i];
                puts("TAK");
                for (int i = 1; i <= n * 3; ++i)
                    if (ans[i])
                        putchar('F');
                    else
                        putchar('R');
                puts("");
                return;
            }
        }
    puts("NIE");
}

signed main() {
    openfile();
    int T = read();
    while (T--)
        init(), solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 24ms
memory: 144856kb

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
RRF
NIE

result:

ok good!

Test #2:

score: 0
Accepted
time: 4763ms
memory: 295908kb

input:

10
33333 100000
28701 40192 93418 95143
95902 97908 78378 78461
36823 44196 22268 23996
23977 24786 33315 48829
83965 90411 4923 8445
20235 21177 32543 47454
29598 35414 72477 73049
2014 12632 42163 46466
64305 65518 98825 99552
32331 41625 92772 96224
26500 54122 76990 77126
18249 20335 31165 36080...

output:

NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE

result:

ok good!

Test #3:

score: 0
Accepted
time: 4238ms
memory: 283312kb

input:

10
33333 100000
15207 33614 66276 66276
97173 97173 67589 73960
19673 36626 65207 65207
89825 98169 27079 27079
56067 56966 7560 7560
18170 35477 18752 18752
32621 36748 34460 34460
61595 61700 14117 14117
32395 36710 9064 9064
13172 13172 1728 4640
40462 41878 47171 47171
76965 82414 5767 5767
9225...

output:

TAK
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...

result:

ok good!

Test #4:

score: 0
Accepted
time: 3939ms
memory: 284388kb

input:

10
33333 100000
2646 2646 6430 6446
82226 82231 15128 15132
877 877 85831 88474
51389 79196 37573 37573
38030 38030 14248 14280
63032 68489 81074 81074
46468 46468 7403 7487
19864 20058 97979 97979
71640 71833 8558 8558
12121 12434 82481 82481
32901 32901 1899 2162
65312 77886 75969 75974
87983 8798...

output:

TAK
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFRRFFFFRFFRRFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF...

result:

ok good!

Test #5:

score: -100
Wrong Answer
time: 361ms
memory: 145020kb

input:

87005
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
1 1
1 3 2 3
1 2
1 1 2 2
2 2 1 1
1 2
1 3 1 1
1 1 1 3
4 20
3 5 6 12
4 5 7 11
1 1 2 2
3 4 7 12
3 5 10 10
3 5 8 8
4 4 9 11
4 4 7 7
1 1 9 10
3 4 6 9
3 5 11 12
3 3 7 9
3 5 2 2
4 5 2 2
1 1 7 11
1 1 10 10
3 5 7 8
4 4 2 2
1 1 2 2
4 5 8 10
4 12
11 ...

output:

TAK
RRF
NIE
TAK
RFF
TAK
FFR
NIE
TAK
RFRRRRFRFFRR
TAK
FFRRFFRRRRRR
NIE
TAK
FFFFRRRRRFRRRRR
TAK
FRRRRRRRFFFR
TAK
FFFRRRRRRRRF
TAK
FFFFFRRRRRRRRRR
TAK
FFRRRRRRRRFF
TAK
FFRRFFFRRRRRRRR
NIE
TAK
FFFFRRRRRRRR
NIE
TAK
FRFFFRRFF
NIE
TAK
FFFRRRRRR
TAK
RRRRRRFFFRRF
TAK
RRFFRFRFFFFFRFF
TAK
RRRRRRRFFFFR
NIE
TAK
...

result:

wrong answer zla odpowiedz!