QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#375979#5116. ContestsschrodingerstomWA 3ms62616kbC++142.7kb2024-04-03 19:13:322024-04-03 19:13:32

Judging History

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

  • [2024-04-03 19:13:32]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:62616kb
  • [2024-04-03 19:13:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
bool memBeg;
template<typename T,typename TT> void chkmin(T &x,TT y) {if(x>y) x=y;}
template<typename T,typename TT> void chkmax(T &x,TT y) {if(x<y) x=y;}
constexpr int mod=998244353;
void inc(int &x,int y) {x+=y; x-=(x>=mod)*mod;}
void dec(int &x,int y) {x-=y; x+=(x<0)*mod;}
constexpr int add(int x,int y) {return (x+y>=mod)?x+y-mod:x+y;}
constexpr int sub(int x,int y) {return (x<y)?x-y+mod:x-y;}
constexpr int quick_pow(int x,ll times,int ret=1) {
    for(;times;times>>=1,x=1ll*x*x%mod) if(times&1) ret=1ll*ret*x%mod;
    return ret;
}
constexpr int maxm=7;
constexpr int maxn=1e5+5;
constexpr int maxlg=20;//17
int n,m,a[maxm][maxn],pos[maxn][maxm],jp[maxn][maxlg][maxm];
bool memEn;
void fl() {
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
}
int main() {
    fprintf(stderr,"%.24lf\n",fabs(&memEn-&memBeg)/1024.0/1024.0);
    // fl();
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++) {
        for(int j=1;j<=n;j++) {
            scanf("%d",&a[i][j]);
            pos[a[i][j]][i]=j;
        }
    }
    memset(jp,0x3f,sizeof(jp));
    for(int i=1;i<=m;i++) {
        static int tmp[maxm];
        memset(tmp,0x3f,sizeof(tmp));
        for(int j=n;j>=1;j--) {
            for(int t=1;t<=m;t++) {
                chkmin(tmp[t],pos[a[i][j]][t]);
                chkmin(jp[a[i][j]][0][t],tmp[t]);
            }
        }
    }
    for(int lg=1;(1<<lg)<=n;lg++) {
        for(int i=1;i<=n;i++) {
            for(int t=1;t<=m;t++) {
                int x=a[t][jp[i][lg-1][t]];
                for(int p=1;p<=m;p++) {
                    chkmin(jp[i][lg][p],jp[x][lg-1][p]);
                }
            }
        }
    }
    int Q; scanf("%d",&Q);
    while(Q--) {
        int u,v;
        scanf("%d%d",&u,&v);
        if(u==v) {puts("0"); continue;}
        static int tmp[maxm],ptmp[maxm];
        memset(tmp,0x3f,sizeof(tmp));
        for(int i=1;i<=m;i++) tmp[i]=pos[u][i];
        auto check=[&]()->bool {
            for(int i=1;i<=m;i++) if(tmp[i]<=pos[v][i]) return false;
            return true;
        };
        if(!check()) {puts("1"); continue;}
        int ret=0;
        for(int lg=__lg(n);lg>=0;lg--) {
            memcpy(ptmp,tmp,sizeof(int)*(m+1));
            for(int i=1;i<=m;i++) {
                int x=a[i][ptmp[i]];
                for(int j=1;j<=m;j++) {
                    chkmin(tmp[j],jp[x][lg][j]);
                }
            }
            if(check()) ret|=1<<lg;
            else memcpy(tmp,ptmp,sizeof(int)*(m+1));
        }
        printf("%d\n",ret+2);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 2
1 3 2 5 4 6
2 1 4 3 6 5
4
1 4
5 3
6 1
5 2

output:

1
2
5
3

result:

ok 4 number(s): "1 2 5 3"

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 62616kb

input:

998 5
1 2 6 3 4 5 7 11 8 9 14 12 13 10 15 16 18 19 20 17 23 22 21 26 24 25 27 29 30 28 32 31 34 33 37 38 39 35 40 36 41 43 42 46 44 48 45 47 51 49 50 56 52 57 53 54 55 62 58 59 63 64 60 65 66 61 67 69 70 68 71 73 74 75 72 78 77 79 82 76 81 85 84 80 86 87 83 88 90 91 89 92 96 98 94 95 97 101 93 103 1...

output:

94
1025
1
1
1
21
1
153
1025
1
19
1025
25
1
1
1
80
1
1
1
1
1025
1
36
102
1
1
1
30
92
1
1
1025
37
36
60
1
1
1
1
1
1
1
1
16
1025
1025
1
1
1025
1025
1
1
140
1
1
77
1
60
1
1
1
4
90
1
1
1025
36
93
1
1
17
148
1
1
1
136
1025
1025
1
28
1025
1025
32
180
1
1025
1025
1
1
1
56
1025
75
25
115
122
1
1025
1
1
2
1
1...

result:

wrong answer 2nd numbers differ - expected: '-1', found: '1025'