QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#629519#9319. Bull FarmAndyqian7WA 3482ms45332kbC++204.3kb2024-10-11 12:54:572024-10-11 12:54:57

Judging History

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

  • [2024-10-11 12:54:57]
  • 评测
  • 测评结果:WA
  • 用时:3482ms
  • 内存:45332kb
  • [2024-10-11 12:54:57]
  • 提交

answer

#include <bits/stdc++.h>
#define LL unsigned long long
#define rep(i, s, e) for (int i = s; i <= e; i++)
using namespace std;
const int N = 2048;
int n, l, q, t[N][N];
struct node
{
    int a, b, no, ans;
    friend bool operator<(node x, node y)
    {
        return x.no < y.no;
    }
};
void qr(int &x)
{
    x = (getchar() - 48) * 50 + getchar() - 48;
}
struct BIT
{
    vector<LL> t;
    BIT()
    {
        t.resize(N >> 6);
    }
    bool operator[](size_t n)
    {
        int ind = n >> 6, bit = n & 63;
        return t[ind] >> bit & 1;
    }
    void set(size_t n, bool val)
    {
        int ind = n >> 6, bit = n & 63;
        t[ind] |= 1lu << bit;
    }
    BIT operator~()
    {
        BIT cpy = *this;
        for (int i = 0; i < N >> 6; i++)
        {
            cpy.t[i] = ~cpy.t[i];
        }
        return cpy;
    }
    void operator|=(const BIT &b)
    {
        for (int i = 0; i < N >> 6; i++)
        {
            t[i] |= b.t[i];
        }
    }
    void operator&=(const BIT &b)
    {
        for (int i = 0; i < N >> 6; i++)
        {
            t[i] &= b.t[i];
        }
    }
    int _Find_first()
    {
        int ind = 0;
        while (ind << 6 < N && !t[ind])
            ind++;
        if (ind < N)
            return ind << 6 | __builtin_ctzll(t[ind]);
        return N;
    }
    int _Find_next(int n)
    {
        int ind = n >> 6, bit = n & 63;
        int tmp = t[ind];
        tmp ^= 1lu << bit;
        tmp ^= tmp & ((1lu << bit) - 1);
        if (tmp)
        {
            return ind << 6 | __builtin_ctzll(tmp);
        }
        ind++;
        while (ind << 6 < N && !t[ind])
            ind++;
        if (ind < N)
            return ind << 6 | __builtin_ctzll(t[ind]);
        return N;
    }
};
int main()
{
    int T;
    scanf("%d", &T);
    while (T--)
    {
        scanf("%d%d%d\n", &n, &l, &q);
        rep(i, 1, l)
        {
            rep(j, 1, n)
            {
                qr(t[i][j]);
            }
            getchar();
        }
        BIT back[N], pre[N];
        rep(i, 1, n)
        {
            back[i].set(i, 1), pre[i].set(i, 1);
        }
        vector<node> v[N];
        rep(i, 1, q)
        {
            int a, b, c;
            qr(a), qr(b), qr(c), getchar();
            v[c].push_back({a, b, i});
        }
        for (auto &[a, B, _, ans] : v[0])
        {
            ans = back[a][B];
        }
        auto add = [&](int a, int b)
        {
            BIT back1[N], pre1[N];
            rep(i, 1, n)
                back1[i] = back[i],
                pre1[i] = pre[i];
            BIT newbacka = back[b], newpreb = pre[a];
            newbacka &= ~back[a], newpreb &= ~pre[b];
            for (int i = newbacka._Find_first(); i < N; i = newbacka._Find_next(i))
            {
                pre[i] |= pre1[a];
            }
            for (int i = newpreb._Find_first(); i < N; i = newpreb._Find_next(i))
            {
                back[i] |= back1[b];
            }
        };
        rep(i, 1, l)
        {
            int cnt[N] = {};
            rep(j, 1, n)
                cnt[t[i][j]]++;
            int c = 0, emp;
            rep(j, 1, n) c += !cnt[j];
            if (c <= 1)
            {
                if (!c)
                {
                    rep(j, 1, n)
                    {
                        add(j, t[i][j]);
                    }
                }
                else
                {
                    vector<int> C;
                    rep(j, 1, n)
                    {
                        if (!cnt[j])
                            emp = j;
                        if (cnt[t[i][j]] == 2)
                            C.push_back(j);
                    }
                    for (auto c : C)
                        add(c, emp);
                }
            }
            for (auto &[a, B, _, ans] : v[i])
            {
                ans = back[a][B];
            }
        }
        vector<node> all;
        rep(i, 0, l)
        {
            for (auto j : v[i])
                all.push_back(j);
        }
        sort(all.begin(), all.end());
        for (auto i : all)
        {
            putchar(i.ans + 48);
        }
        puts("");
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 6356kb

input:

2
5 2 4
0305040201
0404040404
030300
020500
050102
020501
6 2 4
030603010601
010203060504
030202
060402
050602
060401

output:

1011
0100

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 6132kb

input:

1
3 3 6
020202
030301
030201
020102
030203
010201
010303
020303
010202

output:

010101

result:

ok single line: '010101'

Test #3:

score: 0
Accepted
time: 3482ms
memory: 6512kb

input:

200
10 10 5000
01060:04020305080709
0103070:060204050908
09070503080401060:02
050308010204090:0607
03010502040607080:09
03080109020504060:07
06050:09040302080107
07080305010409060:02
030809010:0204060507
0:060908070201050304
060700
090:03
09080:
070405
010703
0:0100
080601
030600
070206
0:0:09
08040...

output:

011110001101101111111111111111111101111111110111011110110110111011010111111111111111111101111111111110111111110111111111111101111111111110111111111111111111110001100111111111111111111111111011101111111111111111111111111111111111111111011011110100111110111111110111111100111111101110111111111101111110...

result:

ok 200 lines

Test #4:

score: -100
Wrong Answer
time: 577ms
memory: 45332kb

input:

1
2000 1 1000000
M=:]A@8UAY7W2JJ4KEHIA[HSCQ1ENSC`JXR;F3PJ:_@41P9Z=9HR8P<<:DUXRR9^WOQFL?NZP6S@=J0^WE32=6;\U0?88]Q_RNPUMT6YU<4<S]H?:7OCQYOT4YAV1^764ENWSDBED>M7A:BI>KSIR48JQ9B=N\5T3N4A2aF0@>3TI81<G7;YE>W`NMP<:IT4CI3D0=GZC3I\CLQJQBA9BDIS9SAM55KaVA<Z@D=>:Y?CQHUQ5U3a6UVI8OKX9_FAF^7=5M85;<0;8YPAM<7Z7PP7A=N...

output:

000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000010000000000000100000000000100000000000000000000000000000000000000000000001000000000000000000000000000000...

result:

wrong answer 1st lines differ - expected: '000101000101100010001000000010...0101000101000000000010101001000', found: '000000000000000000000000000000...0000000000000000000000000000000'