QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#258893 | #7761. 物理实验 | grass8cow | 0 | 514ms | 16712kb | C++17 | 3.8kb | 2023-11-20 13:04:44 | 2023-11-20 13:04:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pb push_back
const int mod=998244353,G=3,GI=(mod+1)/3,inv2=(mod+1)/2;
int qpow(int a,int b){
int c=1;for(;b;b>>=1){
if(b&1)c=1ll*a*c%mod;
a=1ll*a*a%mod;
}
return c;
}
int L,lb[1<<20];
void init(int n){
L=1;while(L<=n)L<<=1;
for(int i=0;i<L;i++)lb[i]=(lb[i>>1]>>1)|((i&1)?(L>>1):0);
}
void NTT(vi &a,int fl){
for(int i=0;i<L;i++)if(i>lb[i])swap(a[i],a[lb[i]]);
for(int o=1;o<L;o<<=1){
int Wn=qpow(fl?G:GI,(mod-1)/(o<<1));
for(int i=0;i<L;i+=(o<<1))for(int j=0,w=1;j<o;j++,w=1ll*w*Wn%mod){
int x=a[i+j],y=1ll*w*a[i+j+o]%mod;
a[i+j]=(x+y)%mod,a[i+j+o]=(x-y)%mod;
}
}
if(!fl){
int I=qpow(L,mod-2);
for(int i=0;i<L;i++)a[i]=1ll*a[i]*I%mod;
}
}
vi operator * (vi a,vi b){
if(a.empty()||b.empty())return {};
vi c;int n=a.size()+b.size()-1;init(n);
a.resize(L),b.resize(L),NTT(a,1),NTT(b,1);
for(int i=0;i<L;i++)a[i]=1ll*a[i]*b[i]%mod;
NTT(a,0);
while((int)a.size()>n)a.pop_back();
return a;
}
vi operator + (vi a,vi b){
if(a.empty())return b;if(b.empty())return a;
if(a.size()<b.size())swap(a,b);int sz=b.size();
for(int i=0;i<sz;i++)(a[i]+=b[i])%=mod;return a;
}
vi mulT(vi a,vi b){
//注意:第二个是常量!c_j=sum a_{i-j}b_j a_i=sum c_{i+j}b_{m-1-j}
int n=a.size(),m=b.size();reverse(b.begin(),b.end());
b=a*b;
for(int i=0;i<n;i++)a[i]=b[i+m-1];
return a;
}
vi az[401000];
void cs(int p,int l,int r,vi &x){
if(l==r){
az[p].resize(2);
az[p][0]=1,az[p][1]=-x[l];
return;
}
int mid=(l+r)>>1;cs(p<<1,l,mid,x),cs(p<<1|1,mid+1,r,x);
az[p]=az[p<<1]*az[p<<1|1];
}
void cs2(int p,int l,int r,vi &x){
if(l==r){
az[p].resize(2);
az[p][0]=-x[l],az[p][1]=1;
return;
}
int mid=(l+r)>>1;cs2(p<<1,l,mid,x),cs2(p<<1|1,mid+1,r,x);
az[p]=az[p<<1]*az[p<<1|1];
}
vi WT;
vi Inv(vi &a,int n){
if(n==1)return vi(1,qpow(a[0],mod-2));
vi b=Inv(a,(n+1)>>1);
init(2*n);b.resize(L),WT.resize(L);
for(int i=0;i<n;i++)WT[i]=a[i];
for(int i=n;i<L;i++)WT[i]=0;
NTT(WT,1),NTT(b,1);
for(int i=0;i<L;i++)b[i]=1ll*b[i]*(2-1ll*b[i]*WT[i]%mod)%mod;
NTT(b,0);b.resize(n);return b;
}
void Sol(int p,int l,int r,vi x,vi &y){
x.resize(r-l+1);
if(l==r){y[l]=x[0];return;}
int mid=(l+r)>>1;
Sol(p<<1,l,mid,mulT(x,az[p<<1|1]),y);
Sol(p<<1|1,mid+1,r,mulT(x,az[p<<1]),y);
}
vi Qz(vi a,vi b,int n){
a.resize(n+1),b.resize(n);
vi c;cs(1,0,n-1,b);
c.resize(n);
Sol(1,0,n-1,mulT(a,Inv(az[1],n+1)),c);
return c;
}
struct mat{vi a[2][2];};
mat operator * (const mat &a,const mat &b){
mat c;for(int k=0;k<2;k++)for(int i=0;i<2;i++)for(int j=0;j<2;j++){
vi xp=a.a[i][k]*b.a[k][j];
c.a[i][j]=c.a[i][j]+xp;
}
return c;
}
int n,m,P,lp,rp,a[101000],b[100100],f[101000];
int od[5010],od2[5010];
int main(){
scanf("%d%d%d%d%d",&n,&m,&P,&lp,&rp);
P=1ll*P*(1-P)%mod;
vi a1,a2;
for(int i=0;i<m;i++)a1.pb(0),a2.pb(0);
for(int i=0,x;i<n;i++)scanf("%d",&x),a1[x]++,a2[(m-x)%m]++;
a1=a1*a2;
for(int i=0;i<(int)a1.size();i++){int e=i%m;e=min(e,m-e);(a[e]+=a1[i])%=mod;}
for(int i=1;i<m;i++)a[i]=1ll*a[i]*inv2%mod,b[i]=min(i,m-i);m--;
mat A,B;A.a[0][0]={(2*P-1)%mod,1},A.a[0][1]={1};
B.a[0][0]={(2*P-1)%mod,1},B.a[0][1]={1},B.a[1][0]={-(int)(1ll*P*P%mod)};
for(int o=m;o;o>>=1){if(o&1)A=A*B;B=B*B;}
vi on=A.a[0][1];
for(int i=1;i<=m;i++)od[i]=a[i];
for(int i=0;i<m;i++){
memset(od2,0,sizeof(od2));
for(int j=1;j<=m;j++)(f[i]+=1ll*od[j]*b[j]%mod)%=mod;
for(int j=1;j<=m;j++){
(od2[j+1]+=1ll*od[j]*P%mod)%=mod;
(od2[j-1]+=1ll*od[j]*P%mod)%=mod;
(od2[j]+=1ll*od[j]*(1-P*2)%mod)%=mod;
}
for(int j=1;j<=m;j++)od[j]=od2[j];
}
for(int i=m;i<=rp;i++){
for(int j=0;j<m;j++)
(f[i]-=1ll*f[i-m+j]*on[j]%mod)%=mod;
}
for(int i=lp;i<=rp;i++)printf("%d ",(f[i]+mod)%mod);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 514ms
memory: 16712kb
input:
7500 7500 96132844 1 7500 1791 817 5559 4742 5272 3988 6672 1355 2783 5552 6885 5321 5996 6495 3072 2241 5527 856 6250 2741 4223 1560 6529 5330 3517 2637 6577 244 1739 5147 2648 6466 1479 7340 7355 176 183 1417 2943 5134 3879 3574 734 4880 7451 3778 1466 5237 2015 1334 6105 4859 1331 5805 3175 4795 ...
output:
173178355 244555175 56636352 513400009 233170045 652797616 443134801 527957651 183269900 858191601 743838253 50818122 688505848 941158208 120660251 688580025 852601792 810593097 212799776 879197432 355123379 334131454 928812205 873176663 541773943 883178425 504757768 58079971 302569476 899789620 628...
result:
wrong answer 1st numbers differ - expected: '107146521', found: '173178355'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Time Limit Exceeded
Test #5:
score: 0
Time Limit Exceeded
input:
100000 7500 500440646 935892941 935892941 3280 7218 1216 489 4036 7029 5538 4805 2544 568 4303 816 739 2284 1294 6062 808 3029 3565 4344 7124 3917 705 3637 6076 2019 4233 2032 7327 5672 2872 2593 22 1534 2071 5782 3228 5460 1217 5138 7285 3679 2751 213 2242 2673 2746 7041 7001 860 2591 7347 3330 213...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Time Limit Exceeded
Test #9:
score: 0
Time Limit Exceeded
input:
100000 50000 559705157 50000 50000 27437 48841 4744 41269 30017 24703 22660 38617 9707 42083 31500 14053 45335 20769 16455 30887 31847 6833 44822 14557 15400 18868 15093 47184 35490 48961 45686 45613 297 31598 7021 9194 30432 14570 44495 39114 21800 16034 12668 49738 20083 31717 22713 34958 46363 35...
output:
result:
Subtask #6:
score: 0
Skipped
Dependency #2:
0%
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #7:
0%
Subtask #9:
score: 0
Skipped
Dependency #6:
0%
Subtask #10:
score: 0
Skipped
Dependency #4:
0%