QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#856329#618. 多项式乘法wxqwq0 754ms114644kbC++141.8kb2025-01-13 21:16:062025-01-13 21:16:08

Judging History

This is the latest submission verdict.

  • [2025-01-13 21:16:08]
  • Judged
  • Verdict: 0
  • Time: 754ms
  • Memory: 114644kb
  • [2025-01-13 21:16:06]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

inline int rd()
{
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0' || ch>'9') {if(ch=='-') f=1;ch=getchar();}
	while(ch>='0' && ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return f?-x:x;
}

#define x first
#define y second
#define vec vector
#define mp make_pair
#define pb emplace_back
#define upb upper_bound
#define lowb lower_bound
#define isz(x) (int)x.size()
#define gmx(a,b) (a=max(a,b))
#define gmn(a,b) (a=min(a,b))
#define fil(a,x) memset(a,x,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)

/*

*/

typedef __int128 i128;
typedef long long LL;
typedef long double LD;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef set<int>::iterator iter;
const int N=3e6+10;
const double PI=acos(-1);

int n1,n2,n,bit;
int rev[N];
struct comp {
	double x,y;
	comp operator+(comp b) {return {x+b.x,y+b.y};}
	comp operator-(comp b) {return {x-b.x,y-b.y};}
	comp operator*(comp b) {return {x*b.x-y*b.y,x*b.y+y*b.x};}
}a[N],b[N],w[N];

void FFT(comp a[],int inv) {
	if(inv==-1) for(int i=0;i<n;i++) w[i].y=-w[i].y;
	for(int i=0;i<n;i++) if(rev[i]>i) swap(a[i],a[rev[i]]);
	for(int d=1,t=n>>1;d<n;d<<=1,t>>=1) for(int i=0;i<n;i+=(d<<1)) for(int j=0;j<d;j++) {
		comp v=w[t*j]*a[i+j+d];
		a[i+j+d]=a[i+j]-v;
		a[i+j]=a[i+j]+v;
	}
	if(inv==-1) for(int i=0;i<n;i++) w[i].y=-w[i].y;
}

signed main()
{
	n1=rd(),n2=rd();
	rep(i,0,n1) a[i].x=rd();
	rep(i,0,n2) b[i].x=rd();
	while((1<<bit)<=n1+n2) ++bit,n=1<<bit;
	for(int i=0;i<n;i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<(bit-1));
	for(int i=0;i<n;i++) w[i]={cos(2*i*PI/n),sin(2*i*PI/n)};
	FFT(a,1),FFT(b,1);
	for(int i=0;i<n;i++) a[i]=a[i]*b[i];
	FFT(a,-1);
	rep(i,0,n1+n2) printf("%lld ",(LL)(a[i].x/n+0.5));
	
	return 0;
}

详细


Pretests


Final Tests

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 8144kb

input:

96 96
600395131 184265451 942971382 534262851 830366882 542271170 294355449 501371170 797809599 964826049 276651245 375755165 662619442 941920605 328216963 507795473 460271147 874920847 818231910 156789488 590591583 732194508 793983630 93566697 836155866 305319153 432040686 621119061 835023373 57138...

output:

293317256442959872 622165877277235200 1148384202335130624 1744330057081987072 1860706225583700992 2797555036758913024 2251669196605142016 2733962690963818496 2956161153011294208 3386689821974899712 4171909363448899584 3443615585976890368 3892200345118502912 4222713817313616896 4684195158345955328 46...

result:

wrong answer 1st numbers differ - expected: '683858396', found: '293317256442959872'

Test #2:

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

input:

4992 4994
471194390 313639917 705341086 119536186 430124603 244978845 185588341 13731324 707132801 88167972 927324568 846658454 523684029 5133605 767200778 502476309 539772401 778154025 266136872 183516351 260704325 49303370 475056182 928574546 740424153 277920667 708439854 746983628 839491869 53579...

output:

134473066251681792 542666022104989696 904382502867533824 1309766133309669376 1350017506451849216 1550932542357504000 1748252215163715584 1784442257412194304 1696086726028427264 2047234800667885568 1943750560816660480 2719201956130750464 3192358180280696832 3385082672675094528 3552133728642859008 418...

result:

wrong answer 1st numbers differ - expected: '700935456', found: '134473066251681792'

Test #3:

score: 0
Wrong Answer
time: 11ms
memory: 9420kb

input:

29995 29992
417238081 53580806 733071257 224121793 786137422 127072245 129083351 988357079 246853229 150935424 596994106 975796660 838029970 619117898 328485797 948485083 574261409 79312345 596346086 489787404 929520168 515647000 211731260 50868568 811515357 428215135 498099163 644485329 802849075 3...

output:

333096846126743552 168127337662513152 959380886288596992 803298363027488768 1575256244477231104 1528350218922229760 1729129116290514944 2670982509184417792 2072069924366843904 2609407495264796672 3183494419512295424 3065007329337933824 4107487652428644352 4220986916462919680 5187908794046218240 5048...

result:

wrong answer 1st numbers differ - expected: '115270920', found: '333096846126743552'

Test #4:

score: 0
Wrong Answer
time: 60ms
memory: 20132kb

input:

100000 99993
812398607 947396010 797321381 883949986 56052416 586258761 193247973 611124334 773505112 142179482 565466227 140875825 79890768 893500101 553768089 648879319 480419657 915530184 799329430 494818755 793895824 851865180 459534006 259473419 610037701 472768430 868914058 887444584 588850309...

output:

462564215069081600 752354318984675328 817168602900725760 1159286459395473408 866250444156960768 1213131176420573184 1519025181804199936 1733602411934646272 2736704129087832064 2920908816956522496 3368153919526010880 3549256500526448640 2672722148536090624 3450543017827500032 3238543165160947712 3759...

result:

wrong answer 1st numbers differ - expected: '821875273', found: '462564215069081600'

Test #5:

score: 0
Wrong Answer
time: 754ms
memory: 114644kb

input:

999993 999994
388529697 811245378 165909114 295553883 667981275 78502012 400874009 139394758 249494489 4636487 997712665 259780805 431039016 716944209 709300152 356513646 823185021 699568300 650937921 859190797 899514799 785648601 933470757 627225124 349752104 471458923 456404256 48134357 315599086 ...

output:

208919996334604288 762534324149944320 1119084467953074176 1110166014315724800 996696216861409280 1209667789795622912 1638540798976851968 1498675824453222400 1313288483070017536 1597669150027677696 2394878301781884928 1999648512010092544 2701351539359875072 2471100347649622016 2674227558702120960 370...

result:

wrong answer 1st numbers differ - expected: '199012842', found: '208919996334604288'