QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#93015#619. 多项式求逆aoui#0 1487ms35152kbC++201.5kb2023-03-31 09:49:542023-03-31 09:51:03

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-31 09:51:03]
  • 评测
  • 测评结果:0
  • 用时:1487ms
  • 内存:35152kb
  • [2023-03-31 09:49:54]
  • 提交

answer

#include<cstdio>
#include<algorithm>
using namespace std;
#define mo 998244353
const int N=3e6+5,G=3;
int n,a[N],b[N],c[N],rev[N];
int fpow(int x,int y=mo-2)
{
	int res=1;
	for(;y;y>>=1,x=1ll*x*x%mo)if(y&1)res=1ll*res*x%mo;
	return res;
}
const int _G=fpow(G);
void Rev(int n)
{
	for(int i=0;i<n;i++)rev[i]=(rev[i>>1]>>1)|((i&1)?n>>1:0);
}
void ntt(int *f,int n,int op)
{
	for(int i=0;i<n;i++)
		if(i<rev[i])swap(f[i],f[rev[i]]);
	for(int i=1;i<n;i<<=1)
	{
		int _g=fpow(op?G:_G,(mo-1)/(i+i));
		for(int j=0;j<n;j+=i+i)
			for(int k=0,gg=1;k<i;k++,gg=1ll*gg*_g%mo)
			{
				int x=f[j|k],y=1ll*f[j|k|i]*gg%mo;
				f[j|k]=(x+y)%mo;
				f[j|k|i]=(x-y+mo)%mo;
			}
	}
	if(!op)
	{
		int ii=fpow(n);
		for(int i=0;i<n;i++)f[i]=1ll*f[i]*ii%mo;
	}
}
void Inv(int *f,int *g,int n)
{
	if(n==1)return g[0]=fpow(f[0]),void();
	if(n&1)
	{
		Inv(f,g,--n);
		int s=1;
		for(int i=0;i<n;i++)s=(s-1ll*g[i]*f[n-i]%mo+mo)%mo;
		g[n]=1ll*s*fpow(f[0])%mo;
	}
	else
	{
		Inv(f,g,n>>1);
		int lim=1;
		for(;lim<n;lim<<=1);
		Rev(lim);
		for(int i=0;i<lim;i++)c[i]=g[i];
		ntt(c,lim,1);
		for(int i=0;i<lim;i++)c[i]=1ll*c[i]*c[i]%mo;
		ntt(c,lim,0);
		lim<<=1;
		Rev(lim);
		ntt(c,lim,1);
		ntt(f,lim,1);
		for(int i=0;i<lim;i++)c[i]=1ll*c[i]*f[i]%mo;
		ntt(f,lim,0);
		ntt(c,lim,0);
		for(int i=(n>>1);i<n;i++)g[i]=(2ll*g[i]%mo-c[i]+mo)%mo;
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	Inv(a,b,n);
	for(int i=0;i<n;i++)printf("%d ",b[i]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 7724kb

input:

100
321704272 732147873 495950455 607498198 139258053 834073875 837326587 9642661 903437916 207412353 359180940 720085797 719290810 723076036 984279000 503225771 350175866 162829281 512559053 225874248 808881115 775602122 556705696 16814894 894905093 985867138 253650922 979472539 59109787 205995179 ...

output:

890391751 343178682 602097979 149308211 262856394 961389315 564599620 968498791 773671964 996203873 738699824 670659706 638239986 422234174 713114430 275708494 788049281 488336612 245951677 65330850 854582144 87507542 762287739 871648878 767168889 773999690 408899677 495834265 555589707 72770275 373...

result:

wrong answer 3rd numbers differ - expected: '709950581', found: '602097979'

Test #2:

score: 0
Wrong Answer
time: 10ms
memory: 7800kb

input:

5000
895174753 48640370 621768187 544696442 266653647 800854366 993400253 180889611 259138834 922465819 237366500 134204023 882884556 962623362 906378209 783980105 385064692 526608265 306798389 492937123 600567928 363960265 499995507 901802313 322681104 915889147 191761221 168327309 250045818 379937...

output:

682334353 436976416 775272797 222487943 472036074 816538561 913440174 91807434 602922613 552122755 249715302 936802363 339360060 357670982 333220525 316337622 553426432 16857850 651099745 675378248 686234200 237421431 83401153 420730810 363045132 865560836 48235461 297876667 988982869 765014945 1706...

result:

wrong answer 5th numbers differ - expected: '387482624', found: '472036074'

Test #3:

score: 0
Wrong Answer
time: 34ms
memory: 8244kb

input:

30000
433849057 26933151 94119735 348782922 994201565 286266085 253836562 391505281 561460922 76317536 151770395 626212470 835627785 278418333 560388198 586773695 43090005 450934659 716357773 746228248 47588293 745422420 131896260 923566007 275614901 981279191 966289868 111837778 850083076 346727100...

output:

357845866 278279787 640245539 292456088 309803128 414055211 833314024 291373169 491127698 973696611 405348198 662283589 197545612 334168202 67681604 11953067 794475209 675101045 749929293 634011650 80943232 401455454 542824741 682781170 23271499 605480647 39144964 585477643 486672912 54194229 931409...

result:

wrong answer 3rd numbers differ - expected: '282399673', found: '640245539'

Test #4:

score: 0
Wrong Answer
time: 170ms
memory: 9164kb

input:

100000
299085935 896290047 664961463 798136437 284888760 805376081 754380153 982440654 523416648 618138054 639229548 946675552 216492659 801950754 591895463 409803161 734598818 262678735 505505080 132772037 241184558 549895828 778274609 60046418 766879997 555641192 925835147 535599922 727361907 2850...

output:

152663231 835829855 886562062 936297234 979987826 68762201 511119017 346813014 232106825 749868736 818900569 123368826 330929818 511615636 807103317 737327776 806698961 802852151 843633493 383177508 3460107 922834222 307521686 621776191 946203608 500689578 427217193 212149520 394883428 70854062 7667...

result:

wrong answer 3rd numbers differ - expected: '733898831', found: '886562062'

Test #5:

score: 0
Wrong Answer
time: 1487ms
memory: 35152kb

input:

1000000
737044976 941398691 939287417 273413335 175365852 377721127 3862986 176449650 791765055 129385383 433663518 447033570 279210233 157228851 130509370 963480863 130226624 349605390 600289609 890766355 577960206 537162643 776878360 951933771 688851169 624945579 212339598 106077966 426859950 6284...

output:

132989151 967059052 919718246 790218950 710877494 104288850 548055862 755344821 464277311 210646055 173423183 54992203 9919981 846583638 262042192 676361484 223241966 467110396 807345462 734692333 576933651 500284119 563619114 453783158 633763014 746452169 768576804 42360429 450155858 347822796 3506...

result:

wrong answer 3rd numbers differ - expected: '786729095', found: '919718246'