QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#592277#9319. Bull FarmlaonongminTL 2623ms36224kbC++173.8kb2024-09-26 21:43:332024-09-26 21:43:34

Judging History

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

  • [2024-09-26 21:43:34]
  • 评测
  • 测评结果:TL
  • 用时:2623ms
  • 内存:36224kb
  • [2024-09-26 21:43:33]
  • 提交

answer

#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define N 2005
#define Q 1000005
#define MOD 998244353
using namespace std;

vector<int> e[N];
int dfn[N], low[N], tot, st[N], inst[N], top, fa[N];
void tarjan(int u)
{
    dfn[u] = low[u] = ++tot;
    st[++top] = u; inst[u] = 1;
    for(auto &&v:e[u])
    {
        if(!dfn[v])
        {
            tarjan(v);
            low[u] = min(low[u], low[v]);
        }
        else if(inst[v]) low[u] = min(low[u], dfn[v]);
    }
    if(dfn[u] == low[u])
    {
        int v;
        do{
            v = st[top--]; inst[v] = 0;
            fa[v] = u;
        }while(v != u);
    }
}
int rt(int x)
{
    while(x!=fa[x]) x=fa[x]=fa[fa[x]];
    return x;
}

bitset<N> vis;
void dfs(int u)
{
    for(auto &&v:e[u])
    {
        if(vis[v]) continue;
        vis[v]=1;
        dfs(v);
    }
}

int t[N][N];
int nt[N];
bitset<Q> ans;
struct query{
    int a,b,id;
};
vector<query> qs[N];
void solve()
{
    int n,l,q;
    cin>>n>>l>>q;
    for(int i=1;i<=n;++i) {e[i].clear(); fa[i]=i;}
    for(int i=1;i<=l;++i) {qs[i].clear();}

    for(int i=1;i<=l;++i)
    {
        string s;
        cin>>s;
        for(int j=1;j<=n;++j) t[i][j] = (s[2*(j-1)]-48)*50 + (s[2*(j-1)+1]-48);
    }
    for(int i=1;i<=q;++i)
    {
        string s;
        cin>>s;
        int a = (s[0]-48)*50 + (s[1]-48);
        int b = (s[2]-48)*50 + (s[3]-48);
        int c = (s[4]-48)*50 + (s[5]-48);
        // cout<<a<<' '<<b<<' '<<c<<'\n';
        qs[c].push_back({a,b,i});
    }

    for(auto &&[a,b,id]:qs[0]) ans[id]=(a==b);
    for(int c=1;c<=l;++c)
    {
        
        // add
        for(int i=1;i<=n;++i) nt[i] = 0;
        int t1=0,t2=0;
        int ok=2;
        for(int i=1;i<=n;++i)
        {
            if(!nt[t[c][i]]) nt[t[c][i]] = i;
            else
            {
                t1=i; t2=nt[t[c][i]];
                ok -= 1;
            }
        }
        if(!t1 && !t2)
        {
            for(int i=1;i<=n;++i)
            {
                if(rt(i) != rt(t[c][i]))
                    e[rt(i)].push_back(rt(t[c][i]));
            }
        }
        else if(ok>0)
        {
            for(int i=1;i<=n;++i)
            {
                if(!nt[i])
                {
                    int z=i;
                    t1=rt(t1), t2=rt(t2), z=rt(z);
                    if(t1 != z) e[t1].push_back(z);
                    if(t2 != z) e[t2].push_back(z);
                    break;
                }
            }
        }

        // tarjan
        tot=0; top=0;
        for(int i=1;i<=n;++i) {dfn[i]=0; inst[i]=0;}
        for(int i=1;i<=n;++i) if(!dfn[i] && rt(i)==i) tarjan(i);
        for(int i=1;i<=n;++i)
        {
            if(rt(i) != i) 
            {
                for(auto &&v:e[i]) if(rt(v) != rt(i)) e[rt(i)].push_back(rt(v));
                e[i].clear();
            }
        }
        for(int i=1;i<=n;++i)
        {
            if(rt(i) == i)
            {   
                for(int i=1;i<=n;++i) vis[i]=0;
                vector<int> pe = e[i];
                e[i].clear();
                for(auto &&v:pe)
                {
                    v=rt(v);
                    if(v != i && !vis[v]) {e[i].push_back(v); vis[v]=1;}
                }
            }
        }

        // cal
        for(auto &&[a,b,id]:qs[c])
        {
            for(int i=1;i<=n;++i) vis[i]=0;
            a=rt(a); b=rt(b);
            
            vis[a]=1;
            dfs(a);
            ans[id] = vis[b];
        }
    }
    // for(int i=1;i<=n;++i) cout<<rt(i)<<'\n';
    for(int i=1;i<=q;++i) cout<<ans[i];
    cout<<'\n';
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin>>T;
    while(T--)
    {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3728kb

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: 0ms
memory: 3708kb

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: 90ms
memory: 5116kb

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: 0
Accepted
time: 1324ms
memory: 15452kb

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:

000101000101100010001000000010010110000001000001001100000000010000100001000000101100000000010000001000000001110000010110100000111100100000001000000000011001010001000001001000100000000100011001100110010000010000101100000011111000000010000101010010000000010101000001010111100000100000000000000101000100...

result:

ok single line: '000101000101100010001000000010...0101000101000000000010101001000'

Test #5:

score: 0
Accepted
time: 2623ms
memory: 36224kb

input:

1
2000 2000 1000000
FVAaH7GRPO;_11Da5J18@3SMG==\G8E8S^6:M4L0JH>MN5IXT>2<7WJ3U8LVJS=;;3F13>0D0>VOIIU@EPHG6ABL6;K?T1PXDERLG07]5C9^GDKG<SBMIW;`4W8P3=469TIPKH0O34523_J5C2MJ17D25Z@=K8H@M>WK<CMK7EO]BPD7B6AW741J5YIHIa1:ERSG>L3N2^F3<4F`DLE@2AA5=8GZK6:192FB736[WMV7:^DA2C:<LK040VJBM3M]WXU50`407TR_?PLF@5VL7OSL...

output:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

ok single line: '111111111111111111111111111111...1111111111111111111111111111111'

Test #6:

score: -100
Time Limit Exceeded

input:

1
2000 2000 1000000
0102030405060708090:0;0<0=0>0?0@0A0B0C0D0E0F0G0H0I0J0K0L0M0N0O0P0Q0R0S0T0U0V0W0X0Y0Z0[0\0]0^0_0`0a101112131415161718191:1;1<1=1>1?1@1A1B1C1D1E1F1G1H1I1J1K1L1M1N1O1P1Q1R1S1T1U1V1W1X1Y1Z1[1\1]1^1_1`1a202122232425262728292:2;2<2=2>2?2@2A2B2C2D2E2F2G2H2I2J2K2L2M2N2O2P2Q2R2S2T2U2V2W2X...

output:


result: