For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed that the answer is not greater than 8·1018.
Input
First line contain two integer values n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 10) — the length of sequence and the number of elements in increasing subsequences.
Next n lines contains one integer ai (1 ≤ ai ≤ n) each — elements of sequence. All values ai are different.
Output
Print one integer — the answer to the problem.
Examples
Input
5 2 1 2 3 5 4
Output
7
#pragma comment(linker, "/STACK:102400000,102400000")
#include<bits/stdc++.h>
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ll long long
const int maxn =3e5+5;
const int mod=1e9+7;
/*
题目意思很清楚。
在树状数组的概念里,
参有很多贡献的思维。
这道题中tree[i][j]树状数组维护的是,
前i个数中递增长度小于等于j的数量,
其中递增的含义是DP值赋予的,
那么这样的tree[i][j],是由什么贡献而来的呢,
是由dp[i][j]贡献的,代表以i位置结尾长度为j的数量,
tree[i][j]可以写成dp的二重求和形式。
首先树状数组的操作还是全部都是套路,且是1—base。
下面有个问题,dp数组如何更新,
按正常的dp思维,
dp[i][j]=sigma p:p<i&&a[p]<a[i], dp[p][j-1];
(以i位置为结尾的长度为j的数量)
而这样的数值可以通过树状数组查询做差即可得到。
至此,这道题主体思想已经有了。
再注意下区间的闭合问题即可,详见代码。
*/
ll dp[maxn][15],tree[maxn][15];
int x;
int lowbit(int x)
{
return x&(-x);
}
void add(int x,int y,ll v)///在指定位置上加数
{
int tp=x;
while(y<15)
{
for(x=tp;x<maxn;tree[x][y]+=v,x+=lowbit(x));
y+=lowbit(y);
}
}
ll sum(int x,int y)///在指定位置上加数
{
ll ret=0;
int tp=x;
while(y>0)
{
for(x=tp;x>0;ret+=tree[x][y],x-=lowbit(x));
y-=lowbit(y);
}
return ret;
}
int n,k;
int main()
{
scanf("%d%d",&n,&k);k++;
memset(dp,0,sizeof(dp));
memset(tree,0,sizeof(tree));
dp[0][0]=1;
for(int i=1;i<=n;i++)
{
scanf("%d",&x);
if(i==1)
{
for(int j=0;j<=k&&j<=i;j++)
{
if(j==0) dp[i][j]+=dp[i-1][j];
else if (j==1)
{
dp[i][j]=1;
add(x,j,dp[i][j]);///等于号是要取到的,所以原位操作无偏移
}
}
continue;
}
for(int j=0;j<=k&&j<=i;j++)
{
if(j==0) dp[i][j]=dp[i-1][j];
else
{
if(j==1) dp[i][j]=1;///怎么算都是一,因为是计算以当前数字开头的
else dp[i][j]=sum(x-1,j-1)-sum(x-1,j-2);///比x小的dp值的前缀统计
add(x,j,dp[i][j]);
}
}
}
ll ans=0;
for(int i=1;i<=n;i++) ans+=dp[i][k];
printf("%lld\n",ans);
return 0;
}