QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#97639 | #6328. Many Products | poi | TL | 1042ms | 99464kb | C++ | 4.9kb | 2023-04-17 18:21:43 | 2023-04-17 18:21:47 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define vi vector<int>
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define mp make_pair
#define rep( i , a , b ) for( int i = (a) , i##end = b ; i <= i##end ; ++ i )
#define per( i , a , b ) for( int i = (a) , i##end = b ; i >= i##end ; -- i )
#define mem( a ) memset( a , 0 , sizeof (a) )
#define all( x ) x.begin() , x.end()
//#define int long long
typedef long long ll;
const int P = 998244353;
const int MAXN = 6e5 + 10;
int Pow( int x , int a ) {
int ret = 1;
while( a ) {
if( a & 1 ) ret = 1ll * ret * x % P;
x = 1ll * x * x % P , a >>= 1;
}
return ret;
}
int Wn[2][MAXN];
void getwn( int len ) {
for( int mid = 1 ; mid < len ; mid <<= 1 ) {
int w0 = Pow( 3 , ( P - 1 ) / ( mid << 1 ) ) , w1 = Pow( 3 , P - 1 - ( P - 1 ) / ( mid << 1 ) );
Wn[0][mid] = Wn[1][mid] = 1;
rep( i , 1 , mid - 1 )
Wn[0][mid + i] = 1ll * Wn[0][mid + i - 1] * w0 % P,
Wn[1][mid + i] = 1ll * Wn[1][mid + i - 1] * w1 % P;
}
}
int rev[MAXN];
void getr( int len ) {
int t = __builtin_ctz( len );
for( int i = 1 ; i < len ; ++ i ) rev[i] = ( rev[i >> 1] >> 1 ) | ( ( i & 1 ) << t - 1 );
}
void NTT( vi& A , int len , int f ) {
for( int i = 0 ; i < len ; ++ i ) if( i < rev[i] ) A[i] ^= A[rev[i]] , A[rev[i]] ^= A[i] , A[i] ^= A[rev[i]];
for( int mid = 1 ; mid < len ; mid <<= 1 )
for( int i = 0 ; i < len ; i += ( mid << 1 ) )
for( int k = 0 ; k < mid ; ++ k ) {
int t1 = A[i + k] , t2 = 1ll * A[i + k + mid] * Wn[f][mid + k] % P;
A[i + k] = ( t1 + t2 ) % P , A[i + k + mid] = ( t1 + P - t2 ) % P;
}
if( f ) for( int i = 0 , iv = Pow( len , P - 2 ) ; i < len ; ++ i ) A[i] = 1ll * A[i] * iv % P;
}
int J[MAXN] , iJ[MAXN];
int C( int a , int b ) {
if( a < b || a < 0 || b < 0 ) return 0;
return J[a] * 1ll * iJ[b] % P * iJ[a - b] % P;
}
vi& mul( vi& a , vi& b , int fuck = 0 ) { // a = a * b
int len = 1 , sz = ( a.size() + b.size() - 2 );
while( len <= sz ) len <<= 1;
getr( len ) , getwn( len );
a.resize( len ) , b.resize( len );
NTT( a , len , 0 ) , NTT( b , len , 0 );
rep( i , 0 , len - 1 ) a[i] = 1ll * a[i] * b[i] % P;
NTT( a , len , 1 );
if( fuck ) NTT( b , len , 1 );
a.resize( sz + 1 );
return a;
}
int n; ll m;
int A[MAXN];
vector<pair<ll,int>> vec;
int num[63] , ff[63] , gg[63] , pre[63][63];
map<ll,vector<int>> M;
int res = 0;
void dfs( int step ) {
if( step == vec.size() ) {
ll d = 1; int pt = 0;
rep( i , 0 , vec.size() - 1 ) {
rep( t , 1 , num[i] ) d *= vec[i].fi;
pt += num[i];
}
rep( len , 1 , pt ) {
ff[len] = 1;
rep( i , 0 , vec.size() - 1 )
ff[len] = ff[len] * 1ll * C( num[i] + len - 1 , len - 1 ) % P;
}
per( len , pt , 1 ) {
gg[len] = 0;
rep( j , 0 , len ) {
if( len - j & 1 ) gg[len] = ( gg[len] + P - C( len , j ) * 1ll * ff[j] % P ) % P;
else gg[len] = ( gg[len] + C( len , j ) * 1ll * ff[j] ) % P;
}
}
if( d == 1 ) gg[0] = 1;
else gg[0] = 0;
vector<int> v;
rep( i , 0 , pt ) v.pb( gg[i] );
M[d] = v;
return;
}
rep( i , 0 , vec[step].se ) num[step] = i , dfs( step + 1 );
}
vi fs[MAXN];
vi& solve( int l , int r ) {
if( l == r ) return fs[l];
int mid = l + r >> 1;
return mul( solve( l , mid ) , solve( mid + 1 , r ) );
}
int cc[MAXN][51];
vi ret;
int work( int k , int t ) {
if( pre[k][t] ) return pre[k][t];
rep( l , 0 , n )
pre[k][t] = ( pre[k][t] + ret[l] * 1ll * cc[l][k] % P * cc[n - l][t] ) % P;
return pre[k][t];
}
void solve() {
getwn( 1 << 19 );
cin >> n >> m;
// n = 2e5 , m = 200560490130;
J[0] = iJ[0] = 1;
rep( i , 1 , 500000 ) J[i] = J[i - 1] * 1ll * i % P;
iJ[500000] = Pow( J[500000] , P - 2 );
per( i , 500000 , 1 ) iJ[i - 1] = iJ[i] * 1ll * i % P;
int prod = 1;
rep( i , 1 , n ) scanf("%d",A + i) , prod = prod * 1ll * ( A[i] + 1 ) % P;
// rep( i , 1 , n ) A[i] = rand() % 10000;
if( m == 1 ) {
printf("%d\n",prod);
return;
}
ll c = m;
for( int t = 2 ; t * 1ll * t <= c ; ++ t ) if( c % t == 0 ) {
int w = 0;
while( c % t == 0 ) c /= t , ++ w;
vec.eb( t , w );
}
if( c != 1 ) vec.eb( c , 1 );
rep( i , 1 , n ) fs[i].pb( 1 ) , fs[i].pb( A[i] );
ret = solve( 1 , n );
// puts("mul");
rep( l , 0 , n ) rep( k , 0 , 50 ) cc[l][k] = C( l , k );
// puts("prework");
dfs( 0 );
for( auto& t : M ) {
ll d = t.fi;
const vi& g = t.se , > = M[m / d];
rep( i , 0 , g.size() - 1 ) rep( j , 0 , gt.size() - 1 ) if( g[i] && gt[j] )
res = ( res + work( i , j ) * 1ll * g[i] % P * gt[j] % P * ( m / d % P ) ) % P;
}
cout << res << endl;
}
signed main() {
// freopen("in","r",stdin);
// freopen("out","w",stdout);
// int T;cin >> T;while( T-- ) solve();
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 30644kb
input:
2 3 0 1
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 0
Accepted
time: 4ms
memory: 33300kb
input:
5 1 0 1 2 3 4
output:
120
result:
ok 1 number(s): "120"
Test #3:
score: 0
Accepted
time: 16ms
memory: 31012kb
input:
10 314159265358 0 1 2 3 4 5 6 7 8 9
output:
658270849
result:
ok 1 number(s): "658270849"
Test #4:
score: 0
Accepted
time: 553ms
memory: 98408kb
input:
200000 999999999989 823489320 406308599 710963770 183707427 192930969 941365774 318564299 391028855 945374838 651744270 515755727 220857626 599403217 214957584 335628890 771694833 40989299 34892948 630275822 869708185 432704750 924850167 707864789 232688853 406616372 529994171 782650336 979286144 65...
output:
777405593
result:
ok 1 number(s): "777405593"
Test #5:
score: 0
Accepted
time: 569ms
memory: 98444kb
input:
199999 999999999331 969252353 737776924 108584656 914893031 394348303 484491127 481944452 120707790 396027156 912223841 673218447 285837840 782450963 144940963 892852383 782342131 655814479 1324532 794011279 219428289 470995270 489684781 347978895 102371386 546635675 585575402 940741300 644383693 67...
output:
573300948
result:
ok 1 number(s): "573300948"
Test #6:
score: 0
Accepted
time: 679ms
memory: 98288kb
input:
200000 742073813481 681694404 632869785 595996398 549654767 229574822 571126931 469341419 702184356 904366313 746328903 842820475 578092052 586236587 796973195 766841610 123554290 666934376 118830348 326368534 40766155 790927880 880528134 890721558 357539968 885997091 937508042 5345140 189162897 200...
output:
998002127
result:
ok 1 number(s): "998002127"
Test #7:
score: 0
Accepted
time: 1042ms
memory: 99464kb
input:
199999 963761198400 124206358 425059813 396286827 293468808 45861386 890748681 587148852 2565459 137729579 865441288 710978415 682768035 62610967 490442955 426217252 132942846 314800009 680954919 208583546 438814504 79283475 26876485 718279429 714019319 799517726 874565672 262935553 180792133 654326...
output:
150795568
result:
ok 1 number(s): "150795568"
Test #8:
score: -100
Time Limit Exceeded
input:
200000 549755813888 154464482 922506517 440386473 592872114 740241030 65093066 195263806 140372279 686442905 168161853 216221623 831551102 203181658 450884227 451817602 487635386 545548989 216183567 218772329 189773367 217113749 131736290 966799162 875967103 93914434 521722337 383140644 765520582 20...