F、take ——概率+树状数组维护

Kanade has n boxes , the i-th box has p[i] probability to have an diamond of d[i] size. At the beginning , Kanade has a diamond of 0 size. She will open the boxes from 1-st to n-th. When she open a box,if there is a diamond in it and it’s bigger than the diamond of her , she will replace it with her diamond. Now you need to calculate the expect number of replacements. You only need to output the answer module 998244353. Notice: If x%998244353=y*d %998244353 ,then we denote that x/y%998244353 =d%998244353

输入描述: The first line has one integer n.

Then there are n lines. each line has two integers p[i]*100 and d[i].

输出描述: Output the answer module 998244353

备注: 1<= n <= 100000

1<=p[i]*100 <=100

1<=d[i]<=10^9

示例 1 输入 3 50 1 50 2 50 3 输出 499122178

给你 n个包,里面每个包有p[i]个几率有宝石,如果宝石比手上拿的大的话,就换,问换的步数的期望
树状数组维护概率,有可能有132的情况,在3的时候就把3之后的概率都去掉了。
还要加个离散化

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll maxn=1e5;
const ll mod=998244353;
ll lowbit(ll x)
{
    return x&(-x);
}
ll qpow(ll a,ll b)
{
    ll ans=1;
    ll ret=a;
    while(b)
    {
        if(b&1)
            ans=(ans*ret)%mod;
        ret=(ret*ret)%mod;
        b>>=1;
    }
    return ans;
}
ll gailv[maxn+5];
void add(ll x,ll val)
{
    for(ll i=x;i>=1;i-=lowbit(i))
    {
        gailv[i]=(gailv[i]*val)%mod;
    }
}
ll query(ll x)
{
    ll ans=1;
    for(ll i=x;i<=maxn;i+=lowbit(i))
    {
        ans=(ans*gailv[i])%mod;
    }
    return ans;
}
ll g[maxn+5],d[maxn+5],temp[maxn+5];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld%lld",&g[i],&d[i]);
        temp[i]=d[i];
    }
    sort(temp+1,temp+1+n);
    ll all=unique(temp+1,temp+1+n)-(temp+1);
    for(int i=1;i<=maxn;i++)
        gailv[i]=1;
    ll ans=0;
    ll inf=qpow(100,mod-2);
    for(int i=1;i<=n;i++)
    {
        int pos=lower_bound(temp+1,temp+all+1,d[i])-temp;
        ans=(ans+query(pos)*g[i]%mod*inf%mod)%mod;
        add(pos,(100-g[i])*inf%mod);
    }
    printf("%lld\n",ans);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/tianyizhicheng/article/details/82419692