QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#370805 | #619. 多项式求逆 | black_moonrise | 0 | 420ms | 70216kb | C++14 | 2.8kb | 2024-03-29 16:41:56 | 2024-03-29 16:41:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxsize = (1 << 21) + 10;
ll qpow (ll x, ll k, ll mod){return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1, mod)*(k&1?x:1)%mod;}
//NTT head - START
template <const int mod, const int proot> struct ntt {
int n, M, w_pre[maxsize], inv[maxsize];
ntt() {
M = 1; while (M*2<maxsize) M <<= 1;
int w = qpow(proot, (mod-1)/M, mod);
w_pre[0] = 1;
for (int i=1; i<=M; i++) w_pre[i] = 1ll*w_pre[i-1]*w%mod;
inv[1] = 1;
for (int i=2; i<maxsize; i++) inv[i] = mod-1ll*inv[mod%i]*(mod/i)%mod;
}
void FFTinit(int sz) {
n = 1; while (n<sz) n <<= 1;
assert(n<=M);
}
void FFT(int a[], int coef) {
typedef unsigned long long ull;
const ull mod2=1ull*mod*mod;
static ull na[maxsize];
for (int i=0, j=0; i<n; i++) {
na[j] = a[i]<0? a[i]+mod: a[i];
for (int l=n>>1; (j^=l)<l; l>>=1) continue;
}
static int w[maxsize];
for (int l=1; l<n; l<<=1) {
int l2=l+l, u=M/l2;
if (coef==1) {
for (int j=0, t=0; j<l; j++, t+=u) w[j] = w_pre[t];
} else {
for (int j=0, t=M; j<l; j++, t-=u) w[j] = w_pre[t];
}
for (int i=0; i<n; i+=l2) {
for (int j=0; j<l; j++) {
ull tmp = na[i+j+l]%mod*w[j];
na[i+j+l] = na[i+j]-tmp+mod2;
na[i+j] += tmp;
}
}
if(l==(1<<8)||l==(1<<16)) for (int i=0; i<n; i++) na[i] %= mod;
}
for (int i=0; i<n; i++) a[i] = 1ll*na[i]%mod*(coef==-1?inv[n]:1)%mod;
}
vector<int> multi(const vector<int> &A, const vector<int> &B, int N=-1) {
if (N==-1) N = max(0, int(A.size()+B.size())-1);
FFTinit(A.size()+B.size());
static int a[maxsize], b[maxsize];
for (int i=0; i<n; i++) a[i] = i<A.size()? A[i]%mod: 0;
for (int i=0; i<n; i++) b[i] = i<B.size()? B[i]%mod: 0;
FFT(a,1), FFT(b,1);
for (int i=0; i<n; i++) a[i] = 1ll*a[i]*b[i]%mod;
FFT(a,-1);
vector<int> ret(N);
for (int i=0; i<N; i++) ret[i] = a[i];
return ret;
}
vector<int> calcinv(const vector<int> &A, int m) {
vector<int> ret(m);
if(m == 1) {
ret[0] = qpow(A[0], mod - 2, mod);
return ret;
}
auto B = calcinv(A, (m+1) / 2);
static int a[maxsize], b[maxsize];
FFTinit(min(int(A.size()), m) + B.size() * 2 - 2);
for(int i=0; i<n; i++) a[i] = i<A.size() ? A[i] % mod : 0;
for(int i=0; i<n; i++) b[i] = i<B.size() ? B[i] % mod : 0;
FFT(a, 1); FFT(b, 1);
for(int i=0; i<n; i++) a[i] = (mod + 2 - 1ll * a[i] * b[i] % mod) * b[i] % mod;
FFT(a, -1);
for(int i=0; i<m; i++) ret[i] = a[i];
return ret;
}
};
ntt <998244353, 3> MS;
int n, a[1000111];
int main() {
scanf("%d", &n);
for(int i=0; i<n; i++) scanf("%d", a+i);
auto B = MS.calcinv(vector<int>(a, a+n), n);
for(auto v : B) printf("%d ", v);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 15ms
memory: 20792kb
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:
451427886 670640521 923188579 526968882 760411228 667588983 735096642 956355036 226173120 68296221 351973161 931893585 105266045 420508552 110680600 814634307 918484317 433406920 636974424 77350125 408318477 11561304 713804572 633341788 538568323 806377369 94752372 274636133 552879681 403860241 6410...
result:
wrong answer 1st numbers differ - expected: '890391751', found: '451427886'
Test #2:
score: 0
Wrong Answer
time: 21ms
memory: 20792kb
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:
637406161 986594628 303012478 399371220 29500428 549336963 727542308 292659141 366234819 908431996 335653803 308513312 460497517 326759597 281519233 219434627 157893370 326027836 50254222 552420300 105978804 120424459 822380352 796308847 311681923 571377925 339307021 145542944 94233454 354873779 253...
result:
wrong answer 1st numbers differ - expected: '682334353', found: '637406161'
Test #3:
score: 0
Wrong Answer
time: 33ms
memory: 23436kb
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:
145146743 166297715 201159709 21629997 414797959 713236449 646792169 394782726 334907325 813267543 663539832 783247933 942459819 570618466 760536482 988525485 114786783 738399705 140066817 308085135 163693389 40058531 653760941 397102918 170004020 572432265 681093715 480206445 887997887 630209049 11...
result:
wrong answer 1st numbers differ - expected: '357845866', found: '145146743'
Test #4:
score: 0
Wrong Answer
time: 63ms
memory: 26036kb
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:
46757739 803763979 104959310 72905486 927231784 663679055 482740028 331034260 964839530 197478288 260821160 132405729 437121092 918133441 457472343 482786489 303560727 176110939 708221180 849853461 515569698 602192797 303850819 263868309 461834907 784624898 469941294 996153117 135180451 841989333 82...
result:
wrong answer 1st numbers differ - expected: '152663231', found: '46757739'
Test #5:
score: 0
Wrong Answer
time: 420ms
memory: 70216kb
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:
550353464 881807366 391538353 939897090 307698441 865125906 742826504 539181032 52152250 417587663 771759048 428834003 37170471 688266031 843349537 558713027 648133419 343957177 319924446 169603000 653638026 363411793 860258276 282775202 810230861 377582357 851456449 734240518 13749147 457184648 147...
result:
wrong answer 1st numbers differ - expected: '132989151', found: '550353464'