QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#370804 | #619. 多项式求逆 | black_moonrise | 0 | 433ms | 70212kb | C++14 | 2.9kb | 2024-03-29 16:41:30 | 2024-03-29 16:41:30 |
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);
for(int i=0; i<n; i++) a[i] = rand() + 1;
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: 13ms
memory: 20216kb
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:
638459068 281687141 306971880 504518308 970564803 255105139 226609471 762309482 768225103 155331068 617924867 685482540 899180598 255399231 686431132 382607304 43914423 513503379 36244999 728623086 952769501 912566968 584769325 791031895 290084242 392757294 897391890 128920120 125959551 784859645 95...
result:
wrong answer 1st numbers differ - expected: '890391751', found: '638459068'
Test #2:
score: 0
Wrong Answer
time: 26ms
memory: 20588kb
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:
570281270 247780735 231280773 739369298 384766007 663602300 972279695 238730799 107233115 789096469 102709392 776698975 363301797 798959529 70987497 875323993 876037449 801460344 458105500 59411606 463329849 699428877 527141022 223814153 230430272 774187253 652889913 537434895 312548605 936570545 85...
result:
wrong answer 1st numbers differ - expected: '682334353', found: '570281270'
Test #3:
score: 0
Wrong Answer
time: 32ms
memory: 21792kb
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:
573883483 330800939 391173193 922912815 422120515 722576148 364235888 154020444 406249408 185227148 35134296 284964370 638834476 238135343 852049710 902337081 772848922 854566899 267777914 513980471 468382523 164624896 470059903 798304357 981771216 538142191 763800242 234480529 649568754 365489815 9...
result:
wrong answer 1st numbers differ - expected: '357845866', found: '573883483'
Test #4:
score: 0
Wrong Answer
time: 63ms
memory: 25832kb
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:
802344806 175904983 432185990 664310821 419511667 809606765 177967477 724519092 585788813 619098804 128464928 347609315 421199013 137993096 760691594 726859665 84157402 159123610 399896342 537623360 485462883 56928080 281024219 390384001 735712342 601563339 546275730 664693692 546909830 727501003 73...
result:
wrong answer 1st numbers differ - expected: '152663231', found: '802344806'
Test #5:
score: 0
Wrong Answer
time: 433ms
memory: 70212kb
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:
478053820 864112165 653858565 562777011 435241818 881006239 433898868 943578779 681906475 223724044 946278531 423458725 686016761 917165097 783444724 524087972 409067175 336723169 601315859 450326630 908068570 929510293 52023590 283148227 353710264 383855958 40374505 939971894 766684661 937627167 49...
result:
wrong answer 1st numbers differ - expected: '132989151', found: '478053820'