QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#86208#5412. 甩锅Crysfly100 ✓93ms15512kbC++176.1kb2023-03-09 15:26:152023-03-09 15:27:33

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-09 15:27:33]
  • 评测
  • 测评结果:100
  • 用时:93ms
  • 内存:15512kb
  • [2023-03-09 15:26:15]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	for(;!isdigit(c);c=getchar())f^=!(c^45);
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	if(f)x=-x;return x;
}
 
#define mod 998244353
struct modint{
	int x;
	modint(int o=0){x=o;}
	modint &operator = (int o){return x=o,*this;}
	modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
	modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
	modint &operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint &operator /=(modint o){return *this *=o^=mod-2;}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	friend modint operator ^(modint a,int b){return a^=b;}
	friend bool operator ==(modint a,int b){return a.x==b;}
	friend bool operator !=(modint a,int b){return a.x!=b;}
	bool operator ! () {return !x;}
	modint operator - () {return x?mod-x:0;}
	bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}

vector<modint> fac,ifac,iv;
inline void initC(int n)
{
	if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
	int m=iv.size(); ++n;
	if(m>=n)return;
	iv.resize(n),fac.resize(n),ifac.resize(n);
	For(i,m,n-1){
		iv[i]=iv[mod%i]*(mod-mod/i);
		fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
	}
}
inline modint C(int n,int m){
	if(m<0||n<m)return 0;
	return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define poly vector<modint>
const modint G=3,Ginv=modint(1)/3;
inline poly one(){poly a;a.push_back(1);return a;}
vector<int>rev;
vector<modint>rts;
inline int ext(int n){
	int k=0;
	while((1<<k)<n)++k;return k; 
}
inline void init(int k){
	int n=1<<k;
	if(rev.size()==n)return;
	rev.resize(n);
	For(i,0,n-1)rev[i]=(rev[i>>1]>>1)|((i&1)<<(k-1));
	if(rts.size()>=n)return;
	int lst=max(1,(int)rts.size()); rts.resize(n);
	for(int mid=lst;mid<n;mid<<=1){
		modint wn=G^((mod-1)/(mid<<1));
		rts[mid]=1;
		For(i,1,mid-1)rts[i+mid]=rts[i+mid-1]*wn;
	}
}
void ntt(poly&a,int k,int typ)
{
	int n=1<<k;
	if(typ<0) reverse(a.begin()+1,a.end());
	For(i,0,n-1)if(i<rev[i])swap(a[i],a[rev[i]]); 
	for(int mid=1;mid<n;mid<<=1)
		for(int r=mid<<1,j=0;j<n;j+=r)
			for(int k=0;k<mid;++k){
				modint x=a[j+k],y=rts[mid+k]*a[j+k+mid];
				a[j+k]=x+y,a[j+k+mid]=x-y;
			}
	if(typ<0){
		modint inv=modint(1)/n;
		For(i,0,n-1)a[i]*=inv;
	}
}
 
poly operator +(poly a,poly b){
	int n=max(a.size(),b.size());a.resize(n),b.resize(n);
	For(i,0,n-1)a[i]+=b[i];return a;
}
poly operator -(poly a,poly b){
	int n=max(a.size(),b.size());a.resize(n),b.resize(n);
	For(i,0,n-1)a[i]-=b[i];return a;
}
poly operator *(poly a,modint b){
	int n=a.size();
	For(i,0,n-1)a[i]*=b;return a;
} 
poly operator *(poly a,poly b){
	if(!a.size()||!b.size())return {};
	if((int)a.size()<=32 || (int)b.size()<=32){
		poly c(a.size()+b.size()-1,0);
		for(int i=0;i<a.size();++i)
			for(int j=0;j<b.size();++j)
				c[i+j]+=a[i]*b[j];
		return c; 
	}
	int n=(int)a.size()+(int)b.size()-1,k=ext(n);
	a.resize(1<<k),b.resize(1<<k),init(k);
	ntt(a,k,1),ntt(b,k,1);
	For(i,0,(1<<k)-1)a[i]*=b[i];
	ntt(a,k,-1),a.resize(n);return a;
}

poly Tmp;
poly pmul(poly a,poly b,int n,bool ok=0)
{
	int k=ext(n); init(k);
	a.resize(1<<k),ntt(a,k,1);
	if(!ok) b.resize(1<<k),ntt(b,k,1),Tmp=b;
	For(i,0,(1<<k)-1)a[i]*=Tmp[i];
	ntt(a,k,-1),a.resize(n);
	return a;
}
poly inv(poly a,int n)
{
	a.resize(n);
	if(n==1){
		poly f(1,1/a[0]);
		return f;
	}
	poly f0=inv(a,(n+1)>>1),f=f0;
	poly now=pmul(a,f0,n,0);
	for(int i=0;i<f0.size();++i)now[i]=0;
	now=pmul(now,poly(0),n,1);
	f.resize(n);
	for(int i=f0.size();i<n;++i)f[i]=-now[i];
	return f;
}
poly inv(poly a){return inv(a,a.size());}

poly deriv(poly a){
	int n=(int)a.size()-1;
	For(i,0,n-1)a[i]=a[i+1]*(i+1);
	a.resize(n);return a;
}
poly inter(poly a){
	int n=a.size()+1;a.resize(n);
	Rep(i,n-1,1)a[i]=a[i-1]/i;
	a[0]=0;return a;
}
poly ln(poly a){
	int n=a.size();
	a=inter(deriv(a)*inv(a));
	a.resize(n);return a;
}
poly exp(poly a,int k){
	int n=1<<k;a.resize(n);
	if(n==1)return one();
	poly f0=exp(a,k-1);f0.resize(n);
	return f0*(one()+a-ln(f0)); 
}
poly exp(poly a){
	int n=a.size();
	a=exp(a,ext(n));a.resize(n);return a;
}
poly div(poly a,poly b){
	int n=a.size(),m=b.size(),k=ext(n-m+1);
	reverse(a.begin(),a.end()),reverse(b.begin(),b.end());
	a.resize(n-m+1),b.resize(n-m+1);
	a=a*inv(b),a.resize(n-m+1),reverse(a.begin(),a.end()); return a;
}
poly modulo(poly a,poly b){
	if(b.size()>a.size())return a;
	int n=b.size()-1;
	a=a-div(a,b)*b;a.resize(n);return a;
}

poly valF;
vector<poly>solveE(int l,int r){
	if(l==r)return {{valF[l]},{1,(mod-l)%mod}};
	int mid=l+r>>1;
	auto fl=solveE(l,mid),fr=solveE(mid+1,r);
	return {fl[0]*fr[1]+fl[1]*fr[0],fl[1]*fr[1]};
}
poly transE(poly f){
	int n=f.size();valF=f;
	vector<poly>g=solveE(0,n-1);
	poly res=g[0]*inv(g[1]); res.resize(n);
	For(i,0,n-1)res[i]*=ifac[i];
	return res;
}
poly shift(poly f,modint v){
	int n=f.size(); poly g(n); initC(n);
	For(i,0,n-1)f[i]*=fac[i];
	modint pw=1;
	For(i,0,n-1)g[i]=ifac[i]*pw,pw*=v;
	reverse(f.begin(),f.end()),f=f*g,reverse(f.begin(),f.end());
	f.resize(n);
	For(i,0,n-1)f[i]*=ifac[i];
	return f;
}
poly mult(poly a,poly b){
	int n=a.size();
	reverse(a.begin(),a.end());
	a=a*b,a.resize(n);reverse(a.begin(),a.end());return a;
}

#define maxn 200005
#define inf 0x3f3f3f3f

int k,n;
poly a;

signed main()
{
	k=read();
	n=1<<k,a.resize(n),a[0]=1;
	For(i,1,n-1)a[i]=read(),a[0]+=a[i],a[i]=-a[i];
	init(k),ntt(a,k,1);
	modint res=1;
	For(i,0,n-1)res*=a[i];
	cout<<res.x;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 2ms
memory: 3380kb

input:

3
145945299 772422151 790720776 412632502 193160068 209134170 435597365

output:

641984640

result:

ok single line: '641984640'

Test #2:

score: 5
Accepted
time: 2ms
memory: 3356kb

input:

3
784588695 85511664 582093918 158811338 84572384 40774093 899812324

output:

969243361

result:

ok single line: '969243361'

Test #3:

score: 5
Accepted
time: 2ms
memory: 3372kb

input:

3
372855041 795539653 63895070 294291056 540596778 687439382 423447319

output:

245789031

result:

ok single line: '245789031'

Test #4:

score: 5
Accepted
time: 2ms
memory: 3356kb

input:

3
630504220 179019282 194220559 18788951 153735450 52733880 504873263

output:

626600242

result:

ok single line: '626600242'

Test #5:

score: 5
Accepted
time: 2ms
memory: 3320kb

input:

8
825156030 146354743 712313249 867321154 204493968 996915669 320486339 989082662 931432388 751585313 149649648 865009828 792359405 51217619 81763086 15975149 695762327 992907563 310266205 87119808 531107648 582718579 880199149 12372572 761737861 923424763 878410930 764478366 976158643 234044896 659...

output:

732911747

result:

ok single line: '732911747'

Test #6:

score: 5
Accepted
time: 3ms
memory: 3436kb

input:

8
229623257 564908155 30978890 338535481 561765248 716244482 335821764 594817950 351552393 556700865 981216695 799215728 567553640 21436520 330250795 106015624 696927149 924173798 465348699 375049270 741805577 579243324 569894211 686733621 336503336 69807378 50166896 30436230 992420600 453049467 732...

output:

255015305

result:

ok single line: '255015305'

Test #7:

score: 5
Accepted
time: 2ms
memory: 3436kb

input:

8
439746803 660236486 89547006 916312558 711338884 734403888 736978555 757551418 677399375 264844303 662231538 486685174 702104863 36199784 529527345 124101879 93949298 321791342 177701195 895768124 830378694 823500899 488204420 801321931 853514182 467533517 919670289 192141258 801487167 683954014 5...

output:

674920898

result:

ok single line: '674920898'

Test #8:

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

input:

8
44212817 153968574 233335803 308952639 18135674 212025413 843915148 354446719 656522067 176576864 854367439 565408855 430046176 810592622 524526782 547080627 974655343 496152722 57780005 787923190 76668817 682065469 741481624 619016585 811141984 37190332 304792788 234547623 392120389 891762731 723...

output:

48726919

result:

ok single line: '48726919'

Test #9:

score: 5
Accepted
time: 2ms
memory: 3428kb

input:

12
874298968 20903746 658972437 118046836 341907679 654925800 829333114 494156645 30365595 390043919 234200098 147341368 301312694 610625803 135070099 249617468 433912476 237342996 142946470 787053361 239553467 387879647 598599802 451734283 221824871 558904006 534044231 884094611 282678549 749476344...

output:

953342244

result:

ok single line: '953342244'

Test #10:

score: 5
Accepted
time: 2ms
memory: 3368kb

input:

12
705160062 915446750 23550257 825800203 282134750 51907814 630304809 835514273 154228021 11171371 671447525 356409503 626824142 91103613 144538947 531990473 717398025 602253075 204100501 637885298 20196736 64943737 675616533 131646911 808288369 598446458 162643077 199075636 380026740 926869362 362...

output:

184898696

result:

ok single line: '184898696'

Test #11:

score: 5
Accepted
time: 3ms
memory: 3424kb

input:

12
625195457 29156019 635443577 580014560 826143058 281617142 55304000 582239365 230657668 256063835 150535001 12547905 149161722 345251484 511540829 883008713 649524417 353438126 819277404 215830876 552291629 557439629 510051084 903300521 269900017 702718488 431997391 18004616 142130856 122510950 4...

output:

966607944

result:

ok single line: '966607944'

Test #12:

score: 5
Accepted
time: 2ms
memory: 3424kb

input:

12
919550950 169351223 561060462 496253428 481673823 899550972 39007945 328319155 568798566 45720435 239274574 172173322 343168572 123293992 319625788 571159912 481399126 156633354 462921674 499449351 757728320 641821270 454783986 111193816 665516558 22539977 803640327 364116738 597299127 144390162 ...

output:

693321728

result:

ok single line: '693321728'

Test #13:

score: 5
Accepted
time: 93ms
memory: 15088kb

input:

20
952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 952573197 9525731...

output:

426654118

result:

ok single line: '426654118'

Test #14:

score: 5
Accepted
time: 59ms
memory: 15080kb

input:

20
194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 194681918 1946819...

output:

733227743

result:

ok single line: '733227743'

Test #15:

score: 5
Accepted
time: 69ms
memory: 15452kb

input:

20
646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 646441218 6464412...

output:

448778523

result:

ok single line: '448778523'

Test #16:

score: 5
Accepted
time: 72ms
memory: 15512kb

input:

20
503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 503996067 5039960...

output:

125288045

result:

ok single line: '125288045'

Test #17:

score: 5
Accepted
time: 76ms
memory: 15412kb

input:

20
818441877 273504401 727037070 180301226 448317616 59828958 72304160 381246388 607117624 516456907 196622739 465928987 972505952 384935668 787696325 149967357 511578504 955182169 707492117 840779840 804190013 865023357 400188471 475398357 149223252 359600148 278732258 343905170 7797013 782728324 2...

output:

731141069

result:

ok single line: '731141069'

Test #18:

score: 5
Accepted
time: 78ms
memory: 15424kb

input:

20
397554611 736410065 273461366 341905432 106415888 471126159 687558115 551173041 9521368 268191004 102506648 865073293 755445670 447707387 891766845 453139682 953556863 422100067 215235400 507135383 362946898 172487685 24035007 574583185 109714434 23071354 524660762 765617511 41089692 318699494 22...

output:

911592446

result:

ok single line: '911592446'

Test #19:

score: 5
Accepted
time: 66ms
memory: 15408kb

input:

20
251667677 46412782 916653691 782933634 120583065 296303275 739419522 620064813 311112078 944060339 435846539 150806724 832299936 143493240 474429332 671559678 91083981 765549737 632871878 328087771 880147538 253354801 680357822 126781301 886401134 784750696 859882726 840925043 725838720 823802938...

output:

17722065

result:

ok single line: '17722065'

Test #20:

score: 5
Accepted
time: 88ms
memory: 15084kb

input:

20
97378693 122542862 414654097 651390240 298552171 865036074 792919706 800911593 890378971 662526326 164251214 507560399 389589792 181868653 28480348 861524812 262865926 350332923 880492254 634641792 657667110 466844827 288240202 166187684 91531482 546498116 531553217 662868878 121171396 447281051 ...

output:

573280498

result:

ok single line: '573280498'