QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#258894 | #7761. 物理实验 | grass8cow | 10 | 524ms | 16332kb | C++17 | 3.8kb | 2023-11-20 13:05:11 | 2023-11-20 13:05:11 |
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[10010],od2[10010];
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: 5
Accepted
Test #1:
score: 5
Accepted
time: 516ms
memory: 14580kb
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:
107146521 488242901 833543364 942893118 320285439 306745340 85380418 480027337 540734953 491950738 458848527 302817505 548924517 963679504 322777659 657420416 538451400 200569821 907146642 940780727 947566362 523285833 942400409 151786157 800926749 797312944 150412848 483203343 637066163 296999542 7...
result:
ok 7500 numbers
Test #2:
score: 0
Accepted
time: 518ms
memory: 14392kb
input:
7500 7499 673240178 1 7499 5325 2885 1225 7126 4988 4269 658 4221 3543 5162 3938 4780 143 2660 6991 5150 5888 6531 6373 6826 2873 5241 5052 793 5475 6299 3991 2399 5665 3786 7339 2749 1696 2681 583 936 5639 6299 4560 3177 6767 3089 4368 4458 650 6558 504 6277 5953 486 6093 1002 7466 5944 952 1796 26...
output:
109401794 751123382 342076416 876406297 327121602 311591650 658676729 820335019 101216944 433427180 230881034 816626094 344216982 198597590 550358617 514078855 683479653 690443997 798617649 473086234 4628208 388804376 899390057 607945374 81999043 497907004 96630466 310290755 759301009 878290881 3611...
result:
ok 7499 numbers
Subtask #2:
score: 5
Accepted
Dependency #1:
100%
Accepted
Test #3:
score: 5
Accepted
time: 524ms
memory: 14488kb
input:
100000 7500 118222194 1 7500 3879 2242 3106 4127 506 5025 480 5913 2013 3740 650 2202 1577 2978 6555 6199 5338 381 936 7430 993 4028 5741 6540 6422 4252 2131 7437 5068 987 4811 7124 6065 6410 2109 6632 1991 995 78 4504 4427 2610 5727 3929 1822 1439 1017 4818 7129 5473 5854 3349 5040 4434 7465 3155 1...
output:
282177948 793195087 371410272 216302166 754838287 635906627 439235084 549238170 147552281 407585707 39424623 564372511 864932973 510959225 287498668 535739056 868188763 901535442 654683909 226988238 902028211 161262841 221883186 568157461 482406651 216671554 376345332 170647927 14316551 761201715 90...
result:
ok 7500 numbers
Test #4:
score: 0
Accepted
time: 517ms
memory: 16332kb
input:
100000 7499 747110152 1 7499 5187 1708 2112 4578 2265 288 4560 2351 944 4258 6394 3390 697 4182 532 833 82 3658 533 5870 5590 3592 6478 144 3929 4926 1845 2566 1063 4570 4748 5802 34 1128 876 3815 2323 4979 1508 4139 4002 4135 5945 611 1844 2457 6689 3266 6857 6852 2214 3486 5429 5273 1659 3586 7195...
output:
66587322 285203560 2811948 574520751 858297444 536639754 74432038 182648309 281510238 841004083 735652999 528557891 469508052 915681980 763925994 45174777 229418630 803369770 610703721 893113152 894067444 913745695 914305706 556012225 267456134 482474991 686056644 746085405 285733366 751933635 95587...
result:
ok 7499 numbers
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:
100%
Accepted
Dependency #3:
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:
100%
Accepted
Dependency #5:
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%