2022百度之星 复赛 T3 最大值
题意
定义n个数字 \(a_1,...,a_n\)mx(a)=整个序列a的最大值。
对于一个序列a 记f(a)为整个序列最大值的数量
求序列长度为n 且\(1\le a_i\le m\)的不同序列的f之和。对998244353取模。
\(n\cdot m\le 10^{12}\)
显然n 和 m至少有一者小于\(10^6\)
当m小于\(10^6\) 单独考虑每一个位置的贡献 答案为\(n\sum_{i=1}^{m} i^{n-1}\) 直接计算。
当n小于\(10^6\) 上述式子显然可以拉格朗日插值 复杂度 nlogm.
code
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<ctime>
#include<cctype>
#include<queue>
#include<deque>
#include<stack>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<algorithm>
#include<utility>
#include<bitset>
#include<set>
#include<map>
#define ll long long
#define db double
#define INF 1000000000
#define inf 1000000000000000ll
#define ldb long double
#define pb push_back
#define put_(x) printf("%d ",x);
#define get(x) x=read()
#define gt(x) scanf("%d",&x)
#define gi(x) scanf("%lf",&x)
#define put(x) printf("%d\n",x)
#define putl(x) printf("%lld\n",x)
#define rep(p,n,i) for(ll i=p;i<=n;++i)
#define go(x) for(ll i=lin[x];i;i=nex[i])
#define fep(n,p,i) for(RE ll i=n;i>=p;--i)
#define vep(p,n,i) for(RE ll i=p;i<n;++i)
#define pii pair<ll,ll>
#define mk make_pair
#define RE register
#define P 13331ll
#define gf(x) scanf("%lf",&x)
#define pf(x) ((x)*(x))
#define uint unsigned long long
#define ui unsigned
#define EPS 1e-5
#define sq sqrt
#define S second
#define F first
#define mod 998244353
#define md 1000000007
#define max(x,y) ((x)<(y)?y:x)
#define a(i) t[i].a
#define b(i) t[i].b
using namespace std;
char buf[1<<15],*fs,*ft;
inline char getc()
{
return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;
}
inline ll read()
{
ll x=0,f=1;char ch=getc();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getc();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc();}
return x*f;
}
inline ll Read()
{
ll x=0,f=1;char ch=getc();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getc();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc();}
return x*f;
}
const ll MAXN=1000010;
ll n,m,ans;
ll f[MAXN],fac[MAXN],inv[MAXN];
inline ll ksm(ll b,ll p)
{
ll cnt=1;
while(p)
{
if(p&1)cnt=cnt*b%mod;
p=p>>1;b=b*b%mod;
}
return cnt;
}
inline void cz(int x)
{
if(x<=n+1){ans=f[x];return;}
fac[0]=1;
rep(1,n,i)fac[i]=fac[i-1]*i%mod;
inv[n]=ksm(fac[n],mod-2);
for(ll i=n-1;i>=0;--i)inv[i]=inv[i+1]*(i+1)%mod;
ll w1=1;
rep(1,n+1,j)w1=w1*(x-j)%mod;
rep(1,n+1,i)
{
ll w2=w1*ksm(x-i,mod-2)%mod;
w2=w2*inv[i-1]%mod*inv[n+1-i]%mod;
if((n+1-i)&1)w2=-w2+mod;
ans=(ans+w2*f[i])%mod;
}
if(ans<0)ans+=mod;
}
signed main()
{
freopen("1.in","r",stdin);
n=read();m=read();
if(m<=1000000)
{
rep(1,m,i)
{
ans=(ans+ksm(i,n-1))%mod;
}
ans=ans*n%mod;
printf("%d\n",ans);
//return 0;
}
ans=0;
rep(1,n+1,i)f[i]=(f[i-1]+ksm(i,n-1))%mod;
cz(m);
printf("%lld\n",ans*n%mod);
return 0;
}