QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#69651#5031. 核zhouhuanyi60 1983ms354784kbC++112.5kb2022-12-29 14:14:442022-12-29 14:14:47

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-29 14:14:47]
  • 评测
  • 测评结果:60
  • 用时:1983ms
  • 内存:354784kb
  • [2022-12-29 14:14:44]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define N 10000001
#define Base 100000
using namespace std;
int read()
{
    char c=0;
    int sum=0;
    while (c<'0'||c>'9') c=getchar();
    while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
    return sum;
}
int n,q,invq,mod,pwa[N+1],pwb[N+1],pw[N+1],s1[N+1],s2[N+1],invs[N+1],invpw[N+1],qnum[N+1],qfac[N+1],invqfac[N+1],dp[N+1],ans;
void Adder(int &x,int d)
{
    x+=d;
    if (x>=mod) x-=mod;
    return;
}
void Adder2(int &x,int d)
{
    x+=d;
    if (x<0) x+=mod;
    return;
}
int MD(int x)
{
    return (x>=mod)?x-mod:x;
}
int MD2(int x)
{
    return (x<0)?x+mod:x;
}
int fast_pow(int a,int b)
{
    int res=1,mul=a;
    while (b)
    {
	if (b&1) res=1ll*res*mul%mod;
	mul=1ll*mul*mul%mod,b>>=1;
    }
    return res;
}
int qC(int x,int y)
{
    if (x<y) return 0;
    return 1ll*qfac[x]*invqfac[y]%mod*invqfac[x-y]%mod;
}
int get_fast_pow(int x)
{
    return 1ll*pwa[x%Base]*pwb[x/Base]%mod;
}
int main()
{
    int cst,rst,kst,dst=1,rest,delta,ds,d1,d2;
    n=read(),q=read(),mod=read(),qfac[0]=pw[0]=invpw[0]=pwa[0]=pwb[0]=s1[0]=s2[n+2]=1,cst=MD2(q-1),rst=fast_pow(cst,mod-2),invq=fast_pow(q,mod-2),rest=1ll*cst*invq%mod;
    for (int i=1;i<=Base;++i) pwa[i]=3ll*pwa[i-1]%mod;
    for (int i=1;i<=Base;++i) pwb[i]=1ll*pwb[i-1]*pwa[Base]%mod;
    for (int i=1;i<=n+1;++i) pw[i]=1ll*pw[i-1]*q%mod,invpw[i]=1ll*invpw[i-1]*invq%mod;
    delta=1ll*MD2(pw[n+1]-pw[n])*rest%mod,ds=MD(MD2(pw[n+1]-pw[n])+rest);
    for (int i=1;i<=n+1;++i) s1[i]=1ll*s1[i-1]*MD2(1-pw[i])%mod;
    for (int i=n+1;i>=1;--i) s2[i]=1ll*s2[i+1]*MD2(1-pw[i])%mod;
    kst=fast_pow(s1[n+1],mod-2);
    for (int i=1;i<=n+1;++i) invs[i]=1ll*s1[i-1]*s2[i+1]%mod*kst%mod;
    for (int i=1;i<=n+1;++i) qnum[i]=1ll*MD2(pw[i]-1)*rst%mod;
    for (int i=1;i<=n+1;++i) qfac[i]=1ll*qfac[i-1]*qnum[i]%mod;
    invqfac[n+1]=fast_pow(qfac[n+1],mod-2);
    for (int i=n;i>=0;--i) invqfac[i]=1ll*invqfac[i+1]*qnum[i+1]%mod;
    dp[0]=1,dp[1]=MD2(MD2(pw[n]-pw[n-1])-1);
    for (int i=2;i<=n;++i)
    {
	d1=MD2(MD(1ll*MD(cst+rest)*pw[i-1]%mod+1ll*MD2(pw[n]-pw[n-1])*invpw[i-1]%mod)-ds);
	d2=MD2(1ll*cst*rest%mod*pw[i-2]%mod-delta);
	dp[i]=1ll*MD(1ll*d1*dp[i-1]%mod+1ll*d2*dp[i-2]%mod)*invs[i]%mod;
    }
    for (int i=0;i<=n;++i) dp[i]=1ll*dp[i]*invqfac[n-i]%mod;
    for (int i=1;i<=n;++i) dst=1ll*dst*q%(mod-1);
    for (int i=0,res=1;i<=n;++i,res=1ll*res*dst%(mod-1)) Adder(ans,1ll*dp[n-i]*get_fast_pow(res)%mod);
    printf("%lld\n",1ll*ans*qfac[n]%mod);
    return 0;
}

详细

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 5ms
memory: 4488kb

input:

1 2 540053233

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: 0
Accepted
time: 5ms
memory: 4528kb

input:

2 2 156542707

output:

43046970

result:

ok 1 number(s): "43046970"

Test #3:

score: 0
Accepted
time: 5ms
memory: 4348kb

input:

1 2 186225229

output:

9

result:

ok 1 number(s): "9"

Test #4:

score: 0
Accepted
time: 1ms
memory: 4344kb

input:

3 3 109884329

output:

100602209

result:

ok 1 number(s): "100602209"

Test #5:

score: 0
Accepted
time: 5ms
memory: 4356kb

input:

1 2 144802297

output:

9

result:

ok 1 number(s): "9"

Subtask #2:

score: 20
Accepted

Dependency #1:

100%
Accepted

Test #6:

score: 20
Accepted
time: 2ms
memory: 4424kb

input:

20 21992843 328859143

output:

110137213

result:

ok 1 number(s): "110137213"

Test #7:

score: 0
Accepted
time: 5ms
memory: 4288kb

input:

22 332524739 654888401

output:

410922781

result:

ok 1 number(s): "410922781"

Test #8:

score: 0
Accepted
time: 5ms
memory: 4452kb

input:

26 302215049 566649113

output:

221720840

result:

ok 1 number(s): "221720840"

Test #9:

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

input:

15 111009527 722130737

output:

648834664

result:

ok 1 number(s): "648834664"

Test #10:

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

input:

82 110032063 394529383

output:

111730592

result:

ok 1 number(s): "111730592"

Test #11:

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

input:

9 11172911 259650437

output:

68381774

result:

ok 1 number(s): "68381774"

Test #12:

score: 0
Accepted
time: 5ms
memory: 4348kb

input:

86 12016027 354886243

output:

263687778

result:

ok 1 number(s): "263687778"

Test #13:

score: 0
Accepted
time: 5ms
memory: 4592kb

input:

91 273689959 454097881

output:

114436127

result:

ok 1 number(s): "114436127"

Test #14:

score: 0
Accepted
time: 5ms
memory: 4492kb

input:

73 148878967 694206977

output:

176215101

result:

ok 1 number(s): "176215101"

Test #15:

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

input:

45 205982233 227598247

output:

156769598

result:

ok 1 number(s): "156769598"

Subtask #3:

score: 10
Accepted

Dependency #2:

100%
Accepted

Test #16:

score: 10
Accepted
time: 2ms
memory: 4500kb

input:

2778 122825869 147297463

output:

43419574

result:

ok 1 number(s): "43419574"

Test #17:

score: 0
Accepted
time: 1ms
memory: 4360kb

input:

289 7729669 589652893

output:

552952137

result:

ok 1 number(s): "552952137"

Test #18:

score: 0
Accepted
time: 6ms
memory: 4484kb

input:

2281 35651417 203950963

output:

21659018

result:

ok 1 number(s): "21659018"

Test #19:

score: 0
Accepted
time: 6ms
memory: 4508kb

input:

1684 258745639 373223677

output:

355596229

result:

ok 1 number(s): "355596229"

Test #20:

score: 0
Accepted
time: 6ms
memory: 4524kb

input:

2107 86850989 455823859

output:

245960059

result:

ok 1 number(s): "245960059"

Test #21:

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

input:

1323 43290799 791120419

output:

509649562

result:

ok 1 number(s): "509649562"

Test #22:

score: 0
Accepted
time: 3ms
memory: 4536kb

input:

2401 34064903 185314627

output:

70571452

result:

ok 1 number(s): "70571452"

Test #23:

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

input:

1073 82288187 564447959

output:

168200843

result:

ok 1 number(s): "168200843"

Test #24:

score: 0
Accepted
time: 6ms
memory: 4416kb

input:

1926 29995039 129122281

output:

60921463

result:

ok 1 number(s): "60921463"

Test #25:

score: 0
Accepted
time: 6ms
memory: 4460kb

input:

3000 66915659 765705179

output:

222619979

result:

ok 1 number(s): "222619979"

Subtask #4:

score: 20
Accepted

Test #26:

score: 20
Accepted
time: 212ms
memory: 39568kb

input:

998818 198334853 998244353

output:

153251445

result:

ok 1 number(s): "153251445"

Test #27:

score: 0
Accepted
time: 202ms
memory: 36452kb

input:

914379 128814383 998244353

output:

477606145

result:

ok 1 number(s): "477606145"

Test #28:

score: 0
Accepted
time: 194ms
memory: 37720kb

input:

944474 478445339 998244353

output:

174204073

result:

ok 1 number(s): "174204073"

Test #29:

score: 0
Accepted
time: 196ms
memory: 37640kb

input:

948637 711592127 998244353

output:

178256114

result:

ok 1 number(s): "178256114"

Test #30:

score: 0
Accepted
time: 185ms
memory: 36900kb

input:

927564 14465663 998244353

output:

315244613

result:

ok 1 number(s): "315244613"

Test #31:

score: 0
Accepted
time: 204ms
memory: 37260kb

input:

934615 392799073 998244353

output:

892700270

result:

ok 1 number(s): "892700270"

Test #32:

score: 0
Accepted
time: 181ms
memory: 36732kb

input:

917196 124972031 998244353

output:

782017412

result:

ok 1 number(s): "782017412"

Test #33:

score: 0
Accepted
time: 201ms
memory: 38132kb

input:

957149 392606173 998244353

output:

159348443

result:

ok 1 number(s): "159348443"

Test #34:

score: 0
Accepted
time: 202ms
memory: 39396kb

input:

997042 184649453 998244353

output:

464643024

result:

ok 1 number(s): "464643024"

Test #35:

score: 0
Accepted
time: 196ms
memory: 37820kb

input:

953353 14071961 998244353

output:

391688875

result:

ok 1 number(s): "391688875"

Subtask #5:

score: 0
Time Limit Exceeded

Test #36:

score: 10
Accepted
time: 1947ms
memory: 352792kb

input:

9909956 720431399 720431401

output:

86883659

result:

ok 1 number(s): "86883659"

Test #37:

score: 0
Accepted
time: 1983ms
memory: 353420kb

input:

9924163 267052829 267052831

output:

75754681

result:

ok 1 number(s): "75754681"

Test #38:

score: 0
Accepted
time: 1924ms
memory: 354784kb

input:

9967885 197873129 197873131

output:

16653739

result:

ok 1 number(s): "16653739"

Test #39:

score: 0
Accepted
time: 1966ms
memory: 354244kb

input:

9952642 101872151 101872153

output:

0

result:

ok 1 number(s): "0"

Test #40:

score: 0
Accepted
time: 1958ms
memory: 354604kb

input:

9955909 167874431 167874433

output:

130012020

result:

ok 1 number(s): "130012020"

Test #41:

score: -10
Time Limit Exceeded

input:

9994785 399509567 399509569

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

0%