QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#111657#5504. Flower GardennamelessguguguWA 3362ms187908kbC++145.2kb2023-06-07 20:26:222023-06-07 20:26:26

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-07 20:26:26]
  • 评测
  • 测评结果:WA
  • 用时:3362ms
  • 内存:187908kb
  • [2023-06-07 20:26:22]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cassert>
#define FILEIO(filename) (freopen(filename ".in", "r", stdin), freopen(filename ".out", "w", stdout))
typedef long long ll;
typedef unsigned long long ull;
const int N = 500005;
int Test;
int n, q, nn, rt, pos[N];
struct Limit
{
    int a, b, c, d;
} e[N];
int id[N], ls[N], rs[N], tot;
std::vector<int> E[N];
int build(int l, int r, int ty)
{
    if(l == r)
    {
        if(ty == 0)
        {
            int x = ++tot;
            id[x] = l, pos[l] = x;
            return x;
        }
        else
            return pos[l];
    }
    int x = ++tot;
    int mid = (l + r) >> 1;
    ls[x] = build(l, mid, ty);
    rs[x] = build(mid + 1, r, ty);
    if (ty == 0)
    {
        E[ls[x]].push_back(x);
        E[rs[x]].push_back(x);
    }
    else
    {
        E[x].push_back(ls[x]);
        E[x].push_back(rs[x]);
    }
    return x;
}
void add(int x, int l, int r, int ql, int qr, int v, int ty)
{
    if(l >= ql && r <= qr)
    {
        if(ty == 0)
            E[x].push_back(v + 9 * n - 2);
        else
            E[v + 9 * n - 2].push_back(x);
        return;
    }
    int mid = (l + r) >> 1;
    if(ql <= mid)
        add(ls[x], l, mid, ql, qr, v, ty);
    if(qr > mid)
        add(rs[x], mid + 1, r, ql, qr, v, ty);
    return;
}
std::vector<int> G[2][N];
int dfn[N], low[N], tt;
int stk[N], top;
bool ins[N];
int cnt;
int bel[N], siz[N];
void tarjan(int x)
{
    dfn[x] = low[x] = ++tt;
    stk[++top] = x, ins[x] = 1;
    for(int y : E[x])
    {
        if(!dfn[y])
            tarjan(y), low[x] = std::min(low[x], low[y]);
        else if(ins[y])
            low[x] = std::min(low[x], dfn[y]);
    }
    if(dfn[x] == low[x])
    {
        ++cnt;
        for (int tmp = -1; tmp != x;)
        {
            tmp = stk[top--], ins[tmp] = 0;
            bel[tmp] = cnt;
            if (id[tmp])
                ++siz[cnt];
        }
    }
    return;
}
int col[N];
char ans[N];
int main(void) // Rose:0 Violet:1
{
    scanf("%d", &Test);
    while(Test--)
    {
        scanf("%d%d", &n, &q), nn = 9 * n + q - 2;
        memset(pos, 0, sizeof(int) * (3 * n + 5));
        tot = 0;
        for (int i = 1; i <= 9 * n + 5; ++i)
            E[i].clear(), id[i] = ls[i] = rs[i] = 0;
        for (int o = 0; o < 2;++o)
            for (int i = 1; i <= nn + 5; ++i)
                G[o][i].clear();
        memset(dfn, 0, sizeof(int) * (nn + 5)), tt = 0;
        memset(low, 0, sizeof(int) * (nn + 5));
        cnt = 0;
        memset(bel, 0, sizeof(int) * (nn + 5));
        memset(siz, 0, sizeof(int) * (nn + 5));
        memset(col, 0, sizeof(int) * (nn + 5));
        memset(ans, 0, sizeof(char) * (nn + 5));
        for (int i = 1; i <= q;++i)
            scanf("%d%d%d%d", &e[i].a, &e[i].b, &e[i].c, &e[i].d);
        rt = build(1, 3 * n, 0);
        for (int i = 1; i <= q; ++i)
            add(rt, 1, 3 * n, e[i].a, e[i].b, i, 0);
        rt = build(1, 3 * n, 1);
        for (int i = 1; i <= q;++i)
            add(rt, 1, 3 * n, e[i].c, e[i].d, i, 1);
        assert(tot == 9 * n - 2);
        for (int i = 1; i <= nn; ++i)
            if (!dfn[i])
                tarjan(i);
        for (int i = 1; i <= nn;++i)
            for(int j : E[i])
                if(bel[i] != bel[j])
                    G[0][bel[i]].push_back(bel[j]), G[1][bel[j]].push_back(bel[i]);
        int big = -1;
        for (int i = 1; i <= cnt;++i)
            if(siz[i] >= n)
            {
                big = i;
                break;
            }
        bool flag = 0;
        if (big == -1)
        {
            flag = 1;
            int now = 0;
            for (int i = 1; now < n && i <= cnt;++i)
                col[i] = 1, now += siz[i];
            assert(now >= n && now <= 2 * n);
        }
        else
        {
            for (int o = 0; o < 2; ++o)
            {
                for (int i = 1; i <= cnt;++i)
                    col[i] = o;
                col[big] = o ^ 1;
                if(o == 0)
                {
                    for (int i = big; i >= 1; --i)
                        if (col[i] != o)
                            for (int j : G[o][i])
                                col[j] = o ^ 1;
                }
                else
                {
                    for (int i = big; i <= cnt; ++i)
                        if(col[i] != o)
                            for(int j : G[o][i])
                                col[j] = o ^ 1;
                }
                int now = 0;
                for (int i = 1; i <= cnt;++i)
                    now += col[i] * siz[i];
                if(now >= n && now <= 2 * n)
                {
                    flag = 1;
                    break;
                }
            }
        }
        if(!flag)
            puts("NIE");
        else
        {
            puts("TAK");
            int sss = 0;
            for (int i = 1; i <= 3 * n;++i)
                ans[i] = col[bel[pos[i]]] ? 'F' : 'R', sss += ans[i] == 'F';
            assert(sss >= n && sss <= 2 * n);
            puts(ans + 1);
        }
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 58356kb

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: 3362ms
memory: 172916kb

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: -100
Wrong Answer
time: 3141ms
memory: 187908kb

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:

wrong answer zla odpowiedz!