QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#380729 | #7838. 往日之影 | C1942huangjiaxu | 0 | 1ms | 3864kb | C++14 | 1.6kb | 2024-04-07 09:53:56 | 2024-04-07 09:53:56 |
answer
#include<bits/stdc++.h>
using namespace std;
int T,P,n,a[4];
struct Fastmod{
typedef __uint128_t uLL;
typedef unsigned long long ull;
ull P,m;
void init(ull P){
this->P=P,m=(uLL(1)<<64)/P;
}
ull mod(ull a){
ull b=uLL(a)*m>>64;
ull r=a-b*P;
return r>=P?r-P:r;
}
}Z;
struct comp{
int a,b;
comp operator +(comp x){return {Z.mod(a+x.a),Z.mod(b+x.b)};}
comp operator +(int x){return {Z.mod(a+x),b};}
comp operator *(int x){return {Z.mod(1ll*x*a),Z.mod(1ll*x*b)};}
comp operator *(comp x){return {Z.mod(1ll*a*x.a+1ll*(P-b)*x.b),Z.mod(1ll*a*x.b+1ll*b*x.a)};}
}I,_I,ans;
int ksm(int x,long long y){
int res=1;
for(;y;y>>=1,x=Z.mod(1ll*x*x))if(y&1)res=Z.mod(1ll*res*x);
return res;
}
comp ksm(comp x,long long y){
comp res={1,0};
for(;y;y>>=1,x=x*x)if(y&1)res=res*x;
return res;
}
void solve(){
scanf("%d",&n);
for(int i=0;i<4;++i)scanf("%d",&a[i]);
ans={1+(a[1]+a[3]&1?-1:1),0},I={0,1},_I={0,P-1};
for(int i=0;i<4;++i)if(a[i]){
ans=(ans+ksm(_I,i)*ksm((I+1)*(P+1>>1),n-1)*a[i]);
ans=(ans+ksm(_I,i)*(a[1]+a[3]+i&1?P-1:1)*ksm((_I+1)*(P+1>>1),n-1)*a[i]);
ans=(ans+ksm(I,i)*ksm((_I+1)*(P+1>>1),n-1)*a[i]);
ans=(ans+ksm(I,i)*(a[1]+a[3]+i&1?P-1:1)*ksm((I+1)*(P+1>>1),n-1)*a[i]);
}
for(int i=0;i<4;++i)for(int j=0;j<4;++j){
int w;
if(i!=j)w=Z.mod(1ll*a[i]*a[j]);
else w=Z.mod(1ll*a[i]*(a[i]-1));
if(!w||a[1]+a[3]+j+i&1)continue;
ans=(ans+ksm(_I,i)*ksm(I,j)*ksm((I+1)*(P+1>>1),n-2)*ksm((_I+1)*(P+1>>1),n-2)*2*w);
}
printf("%d\n",Z.mod(1ll*ksm(P+1>>1,2*n)*ans.a));
}
int main(){
scanf("%d%d",&T,&P);
Z.init(P);
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 1ms
memory: 3804kb
input:
1 998244353 3 1 1 0 1
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
1 998244353 7 0 2 1 4
output:
998069185
result:
ok single line: '998069185'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
1 998244353 4 0 1 0 3
output:
0
result:
ok single line: '0'
Test #4:
score: -10
Wrong Answer
time: 0ms
memory: 3756kb
input:
1 998244353 2 1 0 1 0
output:
124780544
result:
wrong answer 1st lines differ - expected: '0', found: '124780544'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 1ms
memory: 3752kb
input:
999 999999001 2 2 0 0 0 3 3 0 0 0 4 4 0 0 0 5 5 0 0 0 6 6 0 0 0 7 7 0 0 0 8 8 0 0 0 9 9 0 0 0 10 10 0 0 0 11 11 0 0 0 12 12 0 0 0 13 13 0 0 0 14 14 0 0 0 15 15 0 0 0 16 16 0 0 0 17 17 0 0 0 18 18 0 0 0 19 19 0 0 0 20 20 0 0 0 21 21 0 0 0 22 22 0 0 0 23 23 0 0 0 24 24 0 0 0 25 25 0 0 0 26 26 0 0 0 27...
output:
374999626 874999126 359374641 919920956 691222454 586081873 33512082 496961574 790501684 206445579 708073277 492142887 486007979 21786019 802052117 198521403 854660059 658779344 904643630 538486221 357736277 949763680 94144464 342842045 695164947 276856011 552666277 813428208 572457238 910726512 177...
result:
wrong answer 1st lines differ - expected: '499999501', found: '374999626'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%