QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#111632#5504. Flower GardennamelessguguguWA 5831ms255524kbC++144.9kb2023-06-07 19:57:082023-06-07 19:57:09

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 19:57:09]
  • 评测
  • 测评结果:WA
  • 用时:5831ms
  • 内存:255524kb
  • [2023-06-07 19:57:08]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#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 + 6 * n - 1);
        else
            E[v + 6 * n - 1].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;
    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 <= 12 * 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)), tot = 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);
        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];
        }
        else
        {
            for (int o = 0; o < 2; ++o)
            {
                for (int i = 1; i <= cnt;++i)
                    col[i] = o;
                col[big] = o ^ 1;
                for (int i = 1; i <= cnt; ++i)
                    if(col[i] != o)
                    {
                        for(int j : G[o][i])
                            col[j] = o ^ 1;
                    }
                for (int i = cnt; i >= 1; --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");
            for (int i = 1; i <= nn;++i)
                if(id[i])
                    ans[id[i]] = col[bel[i]] ? 'F' : 'R';
            puts(ans + 1);
        }
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 5ms
memory: 58284kb

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

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:

TAK
RFFRRRRRRRRRRFRFRRRFRFRFRRFRRRRRRRRRRFRRRRFFRRRRRRRRRRFRFRRRFFRRRRFRFRRRFFRRRRRRFFRRRFFRRRRRRRRRRRFFRRRRRRRRRFRFFFRRRRFFRRRFRRRRRRRFRFRFFRRRRRRRRRFFRRRRRRFRRRFRFRRRRRRRRRRFFRFRFRRRRRFRFRRRRRRFFRRRFRRRRRFRRRRFRFRRRFFFRFRFRFRFRRRFRRRFRFRRRRFFRRRRFFRRFRFRFRRRRRFRRRFFFRRRRRFRRRRFRRRRRFRFRRRFFRFRRRFR...

result:

wrong answer zla odpowiedz!