牛客网 暑期集训第五场 树状数组+概率思维

时间限制:C/C++ 1秒,其他语言2秒

空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述

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

输入

复制

3
50 1
50 2
50 3

输出

复制

499122178

备注:

1<= n <= 100000

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

1<=d[i]<=10^9
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int maxn=1e5+5;
ll inv[105],cal[maxn],res;
struct node{int d,pos;ll p;}a[maxn];
int n;
void init()
{
    for(int i=0;i<maxn;i++)
        cal[i]=1;
    inv[1]=inv[0]=1;
    for(int i=2;i<105;++i)
        inv[i]=inv[mod%i]*(mod-mod/i)%mod;
}
bool cmp(node a,node b)
{
    if(a.d==b.d)
        return a.pos<b.pos;
    return a.d>b.d;
}
inline int low_bit(int i)
{
    return i&(-i);
}
inline void update(int i,ll val)
{
    while(i<=n)
    {
        cal[i]=cal[i]*val%mod;
        i+=low_bit(i);
    }
}
inline ll ask(int i)
{
    ll ans=1;
    while(i)
    {
        ans=ans*cal[i]%mod;
        i-=low_bit(i);
    }
    return ans;
}
int main()
{
    init();
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld%d",&a[i].p,&a[i].d);
        a[i].p=a[i].p*inv[100]%mod;
        a[i].pos=i;
    }
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++)
    {
        res=(res+a[i].p*ask(a[i].pos-1)%mod)%mod;
        update(a[i].pos,((1-a[i].p)%mod+mod)%mod);
    }
    printf("%lld\n",res);
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值