QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#259724 | #7761. 物理实验 | grass8cow | 35 | 633ms | 21924kb | C++17 | 4.5kb | 2023-11-21 12:04:21 | 2023-11-21 12:04:22 |
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;
}
vi sol(vi q,int l,int r){
if(!r)return {qpow(q[0],mod-2)};
int om=max(l-(int)q.size(),0);
vi q_;for(int i=0;i<(int)q.size();i++)q_.pb((i&1)?(-q[i]):q[i]);
vi e=q*q_,e_;for(int i=0;i<(int)e.size();i+=2)e_.pb(e[i]);
e=sol(e_,(om+1)/2,r/2);e_.clear();
for(int i=om,j=0;i<=r;i++){
if(i&1)e_.pb(0);
else e_.pb(e[j]),j++;
}
q_=q_*e_;vi ans;
for(int i=l;i<=r;i++)ans.pb(q_[i-om]);
return ans;
}
int m,P,a[101000],b[100100],c[300100];
int od[20010],od2[20010];
vi nmd(){
vi a_,b_,e;a_.pb(0),b_.pb(0);
for(int i=1;i<=m;i++)a_.pb(a[i]),b_.pb(b[i]);e=a_*b_;
for(int i=0;i<=m*2;i++){
(c[i+m]-=e[i])%=mod;
if(2*m+2-i<=m)(c[2*m+2-i+m]-=e[i])%=mod;
}
reverse(b_.begin(),b_.end()),e=a_*b_;
//i+m-j
for(int i=0;i<=m*2;i++)(c[i]+=e[i])%=mod;
od[m]=1;
vi f;
for(int i=0;i<m;i++){
memset(od2,0,sizeof(od2));
int as=0;
for(int j=m-i;j<=m+i;j++)if(od[j]){
(as+=1ll*od[j]*c[j]%mod)%=mod;
(od2[j]+=1ll*od[j]*(1-P*2)%mod)%=mod;
(od2[j-1]+=1ll*od[j]*P%mod)%=mod;
(od2[j+1]+=1ll*od[j]*P%mod)%=mod;
}
for(int j=m-(i+1);j<=m+(i+1);j++)od[j]=od2[j];
f.pb(as);
}
return f;
}
int n,lp,rp;
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 q=A.a[0][1];
reverse(q.begin(),q.end());
vi f=nmd();
f=f*q;while((int)f.size()>m)f.pop_back();
int lo=max(0,lp-m);
vi ans=sol(q,lo,rp);
ans=ans*f;for(int i=lp;i<=rp;i++)printf("%d ",(ans[i-lo]+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: 465ms
memory: 16784kb
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: 455ms
memory: 18800kb
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: 468ms
memory: 18840kb
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: 464ms
memory: 16704kb
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: 10
Accepted
Test #5:
score: 10
Accepted
time: 573ms
memory: 21880kb
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:
768801558
result:
ok 1 number(s): "768801558"
Test #6:
score: 0
Accepted
time: 563ms
memory: 21692kb
input:
100000 7499 356847081 883948227 883948227 549 2423 3380 3811 4666 3645 5857 7184 7137 861 2619 519 409 1607 2298 7164 2216 2856 6790 6857 405 1928 5391 2949 6345 4839 2372 2974 4699 2688 6768 684 2012 3642 6225 6948 5313 6936 876 38 3004 7440 4671 208 4906 4714 7067 3424 3163 6165 115 4974 2178 4613...
output:
701047464
result:
ok 1 number(s): "701047464"
Subtask #4:
score: 15
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Test #7:
score: 15
Accepted
time: 633ms
memory: 21924kb
input:
100000 7500 324870432 583103598 583203597 2819 6279 3295 3707 2120 6990 14 1246 3567 6766 4198 4413 2123 5272 6818 7182 6920 287 2185 5195 5539 6080 2986 1536 1159 3669 2790 3383 1417 768 3646 7228 1888 1231 2202 2896 472 1958 5142 3740 5892 378 6359 7270 7407 2208 4685 5740 3022 2649 1295 5114 2256...
output:
740225554 688730085 666338385 475276155 807064812 500095659 44309318 861772879 78356182 988358620 585724905 640424989 556057537 35424100 767966489 880447110 762909851 944339643 717703315 580178270 484495737 516036394 173065791 387258514 936550519 895732005 888643466 153736055 198030515 42309462 7892...
result:
ok 100000 numbers
Test #8:
score: 0
Accepted
time: 625ms
memory: 21372kb
input:
100000 7499 630543739 241932849 242032848 501 910 423 2058 6677 2965 5408 5680 3673 2582 5674 3945 6662 6669 5390 3600 6128 2874 3694 3702 6779 6604 6079 5505 2311 3671 4824 4653 699 3240 6174 5130 5060 7175 3448 5470 6804 2594 2766 3609 5041 3162 6459 4693 540 1051 2084 5495 5715 1474 668 1217 3525...
output:
633608521 78518409 282090790 7883019 256910681 101897243 255895014 370356142 570297806 913428964 313184022 540665339 429163505 78289603 950233320 684974444 894229044 439189457 289387477 996682288 970455571 301701443 936585230 465151269 3458883 412009636 967020579 569371310 680578235 121138004 650394...
result:
ok 100000 numbers
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:
100%
Accepted
Dependency #5:
0%
Subtask #8:
score: 0
Skipped
Dependency #7:
0%
Subtask #9:
score: 0
Skipped
Dependency #6:
0%
Subtask #10:
score: 0
Skipped
Dependency #4:
100%
Accepted
Dependency #8:
0%