链接:https://www.nowcoder.com/acm/contest/143/F
来源:牛客网

题目描述

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

输入例子:
3
50 1
50 2
50 3
输出例子:
499122178

-->

示例1

输入

复制

3
50 1
50 2
50 3

输出

复制

499122178

备注:

1<= n <= 100000

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

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

题意:开始手中有一个大小为0的钻石,然后给出n个箱子,有x/100的概率开出y大小的钻石,如果比手中的钻石大的话就交换,求交换次数

思路:这个牵扯到一些数学知识,我们单独算每个箱子得贡献,如果我要交换当前箱子的钻石,说明当前箱子一定要能开出钻石,所以要乘以当前得概率
然后既然当前箱子要交换,说明当前得钻石说明肯定比手中得钻石大,也就是说前面比这个箱子大得钻石都没有开出钻石,也就是要再乘以前面比它大得
钻石得失败概率,比它小的钻石开不开出钻石都不影响当前钻石,所以概率为1
所以每个箱子得贡献为: 比当前钻石大得箱子开钻石失败得概率 * 当前钻石成功概率
但是我们这样取间断的概率有点麻烦,我们这里用树状数组维护前缀积,优化了一下
我们还要注意,我们的数的范围是1e9 但是箱子的个数是1e5,
1e9的数组我们开不了,所以我们需要离散化
还有我们分数取模无法取,所以我们还要使用逆元来计算 下面看代码注释
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define maxn 998244353
using namespace std;
typedef long long ll;
struct sss
{
ll id,x;
}a[];
ll inv;
ll d[],c[];
ll n,cnt;
ll qpow(ll a,ll n)
{
ll ans=;
while(n)
{
if(n%) ans=(ans*a)%maxn;
a=(a*a)%maxn;
n>>=;
}
return ans;
}
ll lowbit(ll x)
{
return x&(-x);
}
ll sum(ll x)//因为我们要求的是比当前大的钻石概率,而模版树状数组是求小的,我们就反过来即可
{
ll ans=;
while(x<=n)
{
ans=(ans*c[x])%maxn;
x+=lowbit(x);
}
return ans;
}
void updata(ll x,ll d)//同上
{
while(x>)
{
c[x]=(c[x]*d)%maxn;
x-=lowbit(x);
}
}
int main()
{
scanf("%lld",&n);
inv=qpow(,maxn-);//计算分母100的逆元
for(int i=;i<=n;i++)
{
scanf("%lld%lld",&a[i].id,&a[i].x);
d[i-]=a[i].x;
}
sort(d,d+n);//离散化
cnt=unique(d,d+n)-d;
for(int i=;i<=n;i++)
{
c[i]=;//初始化前缀积数组
a[i].x=upper_bound(d,d+cnt,a[i].x)-d+;
}
ll ans=;
for(int i=;i<=n;i++)
{
ans = (ans + (1LL * sum(a[i].x) * a[i].id % maxn * inv)) % maxn;//把前面把他大的箱子的失败概率乘以当前成功的概率
updata(a[i].x, 1LL * ( - a[i].id)*inv % maxn);//更新树状数组 注意是100-当前概率 因为我们要存的是失败概率
}
printf("%lld",ans);
}

牛客多校第五场 F take的更多相关文章

  1. 牛客多校第五场 F take 期望转化成单独事件概率(模板) 树状数组

    链接:https://www.nowcoder.com/acm/contest/143/F来源:牛客网 Kanade has n boxes , the i-th box has p[i] proba ...

  2. 2019牛客多校第五场 F maximum clique 1 状压dp+最大独立集

    maximum clique 1 题意 给出一个集合s,求每个子集的最大独立集的权值和(权值是独立集的点个数) 分析 n比较小,一股浓浓的暴力枚举每一个子集的感觉,但是暴力枚举模拟肯定会T,那么想一想 ...

  3. 2019牛客多校第五场F maximum clique 1 最大独立集

    题意:给你n个数,现在让你选择一个数目最大的集合,使得集合中任意两个数的二进制表示至少有两位不同,问这个集合最大是多大?并且输出具体方案.保证n个数互不相同. 思路:容易发现,如果两个数不能同时在集合 ...

  4. 牛客多校第三场 F Planting Trees

    牛客多校第三场 F Planting Trees 题意: 求矩阵内最大值减最小值大于k的最大子矩阵的面积 题解: 矩阵压缩的技巧 因为对于我们有用的信息只有这个矩阵内的最大值和最小值 所以我们可以将一 ...

  5. 2019牛客多校第八场 F题 Flowers 计算几何+线段树

    2019牛客多校第八场 F题 Flowers 先枚举出三角形内部的点D. 下面所说的旋转没有指明逆时针还是顺时针则是指逆时针旋转. 固定内部点的答案的获取 anti(A)anti(A)anti(A)或 ...

  6. 牛客多校第四场 F Beautiful Garden

    链接:https://www.nowcoder.com/acm/contest/142/F来源:牛客网 题目描述 There's a beautiful garden whose size is n ...

  7. 牛客多校第五场 J:Plan

    链接:https://www.nowcoder.com/acm/contest/143/J 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524 ...

  8. 牛客多校第五场-D-inv

    链接:https://www.nowcoder.com/acm/contest/143/D来源:牛客网 题目描述 Kanade has an even number n and a permutati ...

  9. 牛客多校第五场 E room 二分图匹配 KM算法模板

    链接:https://www.nowcoder.com/acm/contest/143/E来源:牛客网 Nowcoder University has 4n students and n dormit ...

随机推荐

  1. 基于BindingSource的WinForm开发

    BindingSource控件介绍 BindingSource控件介绍 BindingSource控件是.NET Framework 2.0提供的新控件之一.BindingSource控件与数据源建立 ...

  2. 关于Android如何创建空文件夹,以及mkdir和mkdirs的区别

    File().mkdir 和File().mkdirs的区别 mkdir是只能建立一级目录 比如 /sdcard/test/pp 就只能建立test 而mkdirs 则可以全部建立

  3. AVL平衡二叉树的各种问题(Balanced Binary Tree)

    AVL树或者是一棵空树,或者是具有以下性质的非空二叉搜索树: 1. 任一结点的左.右子树均为AVL树: 2.根结点左.右子树高度差的绝对值不超过1. 1.声明 #include<iostream ...

  4. 151. Reverse Words in a String(java 注意细节处理)

    题目:reverse words in a string Given an input string, reverse the string word by word. For example,Giv ...

  5. Remove Element leetcode java

    问题描述: Given an array and a value, remove all instances of that value in place and return the new len ...

  6. 【基础知识】【1】CDN

    正文: CDN:Content Delivery Network,内容分发网络.使用户访问离ta最近的资源服务器,优化访问速度 优点: 1,内容可以共享,不同站点的同一文件可以不用多次缓存 2,增加下 ...

  7. python 线程 进程

    1.进程与线程优.缺点的比较总言:使用进程和线程的目的,提高执行效率. 进程: 优点:能利用机器的多核性能,同时进行多个操作. 缺点:需要耗费资源,重新开辟内存空间,耗内存. 线程: 优点:共享内存( ...

  8. Leetcode 116

    /** * Definition for binary tree with next pointer. * struct TreeLinkNode { * int val; * TreeLinkNod ...

  9. SpringBoot 使用Thymeleaf解决静态页面跳转问题

    参考:springboot配置跳转html页面 1,首先在pom文件中引入模板引擎jar包 <dependency> <groupId>org.springframework. ...

  10. Git中ssh的使用

    远程仓库前期工作(SSH HEY的使用) 1.1.注册GitHub账号 1.2.创建SSH Key 打开Git Bash后,输入ssh-keygen -t rsa -C "youremail ...