一天,小魂正和一个数列玩得不亦乐乎。
小魂的数列一共有n个元素,第i个数为Ai。
他发现,这个数列的一些子序列中的元素是严格递增的。
他想知道,这个数列一共有多少个长度为K的子序列是严格递增的。
请你帮帮他,答案对998244353取模。
对于100%的数据,1≤ n ≤ 500,000,2≤ K ≤ 10,1≤ Ai ≤ 109。
输入描述:
第一行包含两个整数n,K,表示数列元素的个数和子序列的长度。
第二行包含n个整数,表示小魂的数列。
输出描述:
一行一个整数,表示长度为K的严格递增子序列的个数对998244353取模的值。
示例1
输入
5 3
2 3 3 5 1
输出
2
说明
两个子序列分别是2 3 3 5 1和2 3 3 5 1。
#include<bits/stdc++.h>
typedef unsigned long long ull;
typedef long long ll;
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define nep(i,r,l) for(int i=r;i>=l;i--)
void sc(int &x){scanf("%d",&x);}
void sc(int &x,int &y){scanf("%d%d",&x,&y);}
void sc(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void sc(ll &x){scanf("%lld",&x);}
void sc(ll &x,ll &y){scanf("%lld%lld",&x,&y);}
void sc(ll &x,ll &y,ll &z){scanf("%lld%lld%lld",&x,&y,&z);}
void sc(char *x){scanf("%s",x);}
void sc(char *x,char *y){scanf("%s%s",x,y);}
void sc(char *x,char *y,char *z){scanf("%s%s%s",x,y,z);}
void out(int x){printf("%d\n",x);}
void out(ll x){printf("%lld\n",x);}
void out(int x,int y){printf("%d %d\n",x,y);}
void out(ll x,ll y){printf("%lld %lld\n",x,y);}
void out(int x,int y,int z){printf("%d %d %d\n",x,y,z);}
void out(ll x,ll y,ll z){printf("%lld %lld %lld\n",x,y,z);}
using namespace std;
const int N=5e5+5,mod=998244353;
int n,k,a[N],hs[N];
ll bit[N],b[N];
void add(int x,ll v)
{
while(x<=n) bit[x]=(bit[x]+v)%mod,x+=x&-x;
}
ll query(ll x)
{
ll ans=0;
while(x) ans+=bit[x],x-=x&-x;
return ans%mod;
}
int main()
{
sc(n,k);
rep(i,1,n) sc(a[i]),b[i]=1,hs[i]=a[i];
sort(hs+1,hs+1+n);
rep(i,1,n) a[i]=lower_bound(hs+1,hs+1+n,a[i])-hs;
rep(s,1,k-1)
{
memset(bit,0,sizeof(bit));
rep(i,1,n)
{
add(a[i],b[i]);
b[i]=query(a[i]-1);
};
}
ll ans=0;
rep(i,1,n) ans=(ans+b[i])%mod;
out(ans);
return 0;
}