题意:求满足条件的排列,1:从左往右会遇到a个比当前数大的数,(每次遇到更大的数会更换当前数)2.从右往左会遇到b个比当前数大的数.
题解:1-n的排列,n肯定是从左往右和从右往左的最后一个数.
考虑\(S(n,m)\)是1-n排列中从左往右会遇到m个比当前数大的数,考虑把1放在最左边,即\(S(n-1,m-1)\),考虑1不在最左边,有n-1个位置,1不可能会更换\((n-1)*S(n,m)\).即\(S(n,m)=S(n-1,m-1)+(n-1)*S(n-1,m)\)
\(S(n,m)\)即第一类斯特林数.答案即\(S(n-1,a+b-2)*C(a+b-2,a-1)\)
\(S(n,*)\)的生成函数即\(\prod_{i=0}^{n-1}(x+i)\),即x的n次上升幂.
\(F_n(x)=\prod_{i=0}^{n-1}(x+i)\),\(F_n(x+n)=\prod_{i=0}^{n-1}(x+n+i)\)
\(F_{2n}(x)=F_n(x)*F_n(x+n)\)
\(F_n(x)=\sum_{i=0}^{n-1}a_ix^i\),\(F_n(x+n)=\sum_{i=0}^{n-1}x^i*\sum_{j=i}^{n-1}\frac{j!}{i!*(j-i)!}n^{j-i}a_j\)
先卷积出\(F_n(x+n)\),然后卷积出\(F_{2n}(x)\),当n不能整除2时,单独考虑乘(x+n-1).
递归处理,复杂度\(O(nlogn)\)
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include
//#include
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
//#define pi acos(-1.0)
#define ll long long
#define vi vector
#define mod 998244353
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair
#define pil pair
#define pli pair
#define pii pair
#define ull unsigned long long
#define bpc __builtin_popcount
#define base 1000000000000000000ll
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
templateinline T const& MAX(T const &a,T const &b){return a>b?a:b;}
templateinline T const& MIN(T const &a,T const &b){return a>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=mul(ans,a,c);a=mul(a,a,c),b>>=1;}return ans;}
using namespace std;
//using namespace __gnu_pbds;
const ld pi = acos(-1);
const ull ba=233;
const db eps=1e-5;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+10,maxn=2000000+10,inf=0x3f3f3f3f;
ll x[N<<3],y[N<<3];
int rev[N<<3];
void getrev(int bit)
{
for(int i=0;i<(1<>1]>>1) | ((i&1)<<(bit-1));
}
void ntt(ll *a,int n,int dft)
{
for(int i=0;i=mod)v[i+j]-=mod;
}
}
else
{
for(int i=0;in)return 0*puts("0");
if(n==1)
{
if(a==b&&a==1)puts("1");
else puts("0");
return 0;
}
vi v=solve(n-1);
printf("%lld\n",1ll*v[a+b-2]*C(a+b-2,a-1)%mod);
return 0;
}
/********************
********************/