QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#669978#8338. Quad Kingdoms ChessczcWA 3ms39780kbC++232.1kb2024-10-23 20:09:372024-10-23 20:09:38

Judging History

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

  • [2024-10-23 20:09:38]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:39780kb
  • [2024-10-23 20:09:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=998244353;
const int maxn=2e5+5;
int n,q;
int jc[maxn],inv[maxn];
inline int C(int x,int y){
    if(x<y || x<0 || y<0) return 0;
    return (ll)jc[x]*inv[y]%mod*inv[x-y]%mod;
}
int k[maxn];
int book[maxn];
vector<int> b[maxn];
int hz[700][maxn],qz[40][maxn];
const int inv2=(mod+1)/2;
int pw[maxn];
int main(){
    scanf("%d%d",&n,&q);
    jc[0]=1;
    for(int i=1;i<maxn;i++) jc[i]=(ll)jc[i-1]*i%mod;
    inv[0]=inv[1]=1;
    for(int i=2;i<maxn;i++) inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod;
    for(int i=2;i<maxn;i++) inv[i]=(ll)inv[i]*inv[i-1]%mod;
    pw[0]=1;
    for(int i=1;i<maxn;i++) pw[i]=(ll)pw[i-1]*inv2%mod;
    for(int i=1;i<=q;i++){
        scanf("%d",&k[i]);
        b[i].resize(k[i]+2,0);
        for(int j=1;j<=k[i];j++) scanf("%d",&b[i][j]);
        b[i][k[i]+1]=2*n;
        book[i]=k[i];
    }
    sort(book+1,book+q+1);
    int tot=unique(book+1,book+q+1)-(book+1);
    for(int i=1;i<=tot;i++){
        int kk=book[i];
        for(int p=n*2-1;p>=0;p--){
            if(p>=n) hz[i][p]=(ll)C(p-kk-1,n-kk-1)*pw[p]%mod;
            hz[i][p]=(hz[i][p]+hz[i][p+1])%mod;
        }
    }
    for(int i=0;i<40;i++){
        for(int p=0;p<=n*2;p++){
            qz[i][p]=(ll)C(p-i-1,n-1)*pw[p]%mod;
            if(p) qz[i][p]=(qz[i][p]+qz[i][p-1])%mod;
        }
    }
    for(int i=1;i<=q;i++){
        int kk=k[i];
        int ans=0;
        if(b[i][kk]>=n && b[i][kk]<2*n) ans=(ll)pw[b[i][kk]]*C(b[i][kk]-kk,n-kk)%mod;
        if(kk>=40){
            for(int j=0;j<=kk;j++){
                for(int p=b[i][j]+1;p<b[i][j+1];p++){
                    ans=(ans+(ll)pw[p]*C(p-j-1,n-1)%mod)%mod;
                }
            }
        }
        else{
            for(int j=0;j<=kk;j++){
                if(b[i][j]+1<=b[i][j+1]-1){
                    ans=(ans+qz[j][b[i][j+1]-1]-qz[j][b[i][j]])%mod;
                    ans=(ans+mod)%mod;
                }
            }
        }
        ans=(ans+hz[lower_bound(book+1,book+tot+1,kk)-book][b[i][kk]+1])%mod;
        printf("%d\n",ans*2%mod);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 39780kb

input:

5
1 2 3 4 5
5
5 4 3 2 1
8
1 1 5
1 4 2
1 2 4
1 5 1
1 5 5
2 1 4
2 3 5
2 5 5

output:

499122177

result:

wrong answer 1st words differ - expected: 'NO', found: '499122177'