牛客OI周赛15-普及组 树状数组 + 离散化

在这里插入图片描述
题意:n在1e5 m在50以内 存在多少个m元组满足条件
思路:从三元组的扩展 对于数组中的某一个点 对答案的贡献就是 左边小于他的数 x 右边大于他的数
所以考虑构造m个树状数组来维护和查询

#include <bits/stdc++.h>

using namespace std;

#define LL long long
#define mes(x,a) memset(x,a,sizeof(x));
#define sca(a) scanf("%d",&a)
#define lowbit(x)  x & (-x)
#define fi first
#define se second
#define pii pair<int, int>

inline int read()
{
    int x=0,flag_read=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
            flag_read=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*flag_read;
}

const double eps=1e-9;
const double pi=acos(-1);
const int N = 100050;
const int M = 1e7+5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;

LL c[N][51],a[N],b[N];

void update(LL x,LL k,LL v)
{
    for(;x < N ;x += lowbit(x))
        c[x][k] = (c[x][k] + v)%mod;
}

LL query(LL x,LL k)
{
    LL res = 0;

    for(;x > 0 ;x -= lowbit(x))
        res = (res + c[x][k])%mod;

    return res;
}

int main()
{
    int n,m;

    n = read();
    m = read();

    for(int i = 1;i <= n;i ++)
        a[i] = b[i] = read();

    sort(b + 1,b + 1 + n);

    int len = unique(b + 1,b + 1 + n) - b - 1;

    for(int i = 1;i <= n;i ++)
        a[i] = lower_bound(b + 1,b + 1 + len,a[i]) - b;

    for(int i = 1;i <= n;i ++)
    {
        update(a[i],1,1);

        for(int j = 2;j <= m;j ++)
            update(a[i],j,query(a[i] - 1,j - 1));
    }

    printf("%lld\n",query(n,m));

    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值