题目描述

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

算一下每个箱子对答案的贡献,加在一起就可以了

对于第i个箱子,它对答案的贡献就为

也就是当且仅当当前箱子里出现钻石,且前面所有钻石比它大的箱子都不出现钻石,在经过这个箱子时才会replace(对答案有贡献)

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<string>
#include<math.h>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
#define LL long long
#define mod 998244353
LL tre[500005];
typedef struct Res
{int x, id, p;bool operator < (const Res &b) const{if(x>b.x || x==b.x && id<b.id)return 1;return 0;}
}Res;
Res s[200005];
void Create(int l, int r, int x)
{int m;if(l==r){tre[x] = 1;return;}m = (l+r)/2;Create(l, m, x*2);Create(m+1, r, x*2+1);tre[x] = 1;
}
void Update(int l, int r, int x, int a, int b)
{int m;if(l==r){tre[x] = (LL)(100-b)*828542813%mod;return;}m = (l+r)/2;if(a<=m)Update(l, m, x*2, a, b);elseUpdate(m+1, r, x*2+1, a, b);tre[x] = tre[x*2]*tre[x*2+1]%mod;
}
LL Query(int l, int r, int x, int a, int b)
{int m;LL ans = 1;if(l>=a && r<=b)return tre[x];m = (l+r)/2;if(a<=m)ans = ans*Query(l, m, x*2, a, b)%mod;if(b>=m+1)ans = ans*Query(m+1, r, x*2+1, a, b)%mod;return ans;
}
LL Pow(LL a, LL b)
{LL ans = 1;while(b){if(b%2)ans = ans*a%mod;a = a*a%mod;b /= 2;}return ans;
}
int main(void)
{LL ans;int n, i;scanf("%d", &n);for(i=1;i<=n;i++){scanf("%d%d", &s[i].p, &s[i].x);s[i].id = i;}sort(s+1, s+n+1);Create(1, n, 1);ans = 0;for(i=1;i<=n;i++){ans = (ans+Query(1, n, 1, 1, s[i].id)*s[i].p%mod*828542813)%mod;Update(1, n, 1, s[i].id, s[i].p);}printf("%lld\n", ans);return 0;
}

牛客网暑期ACM多校训练营(第五场): F. take(期望+线段树)相关推荐

  1. 牛客网暑期ACM多校训练营(第二场)J farm (二维树状数组)

    题目链接: https://www.nowcoder.com/acm/contest/140/J 思路: 都写在代码注释里了,非常好懂.. for_each函数可以去看一下,遍历起vector数组比较 ...

  2. 牛客网暑期ACM多校训练营(第五场): A. gpa(01分数规划)

    题目描述 Kanade selected n courses in the university. The academic credit of the i-th course is s[i] and ...

  3. 牛客网暑期ACM多校训练营(第九场)

    牛客网暑期ACM多校训练营(第九场) A. Circulant Matrix 做法:看到下标 \(xor\) 这种情况就想 \(FWT\),可是半天没思路,于是放弃了..其实这个 \(n\) 疯狂暗示 ...

  4. 牛客网暑期ACM多校训练营(第一场)

    牛客网暑期ACM多校训练营(第一场) A. Monotonic Matrix 考虑0和1的分界线,1和2的分界线,发现问题可以转化为两条不互相穿过的路径的方案数(可重叠),题解的做法就是把一条路径斜着 ...

  5. 牛客网暑期ACM多校训练营(第二场): H. travel(树形线头DP)

    链接:https://ac.nowcoder.com/acm/contest/140/H 来源:牛客网 题目描述 White Cloud has a tree with n nodes.The roo ...

  6. 牛客网暑期ACM多校训练营(第三场): E. Sort String(KMP)

    链接:https://www.nowcoder.com/acm/contest/141/E 来源:牛客网 题目描述 Eddy likes to play with string which is a ...

  7. 牛客网暑期ACM多校训练营(第三场): C. Shuffle Cards(splay)

    链接:https://www.nowcoder.com/acm/contest/141/C 来源:牛客网 题目描述 Eddy likes to play cards game since there ...

  8. 牛客网暑期ACM多校训练营(第二场)A .run

    链接:https://www.nowcoder.com/acm/contest/140/A 来源:牛客网 题目描述 White Cloud is exercising in the playgroun ...

  9. 牛客网暑期ACM多校训练营(第一场) J (莫队算法)

    题目链接:https://www.nowcoder.com/acm/contest/139/J 题目大意:给一个序列,进行q次查询,问1~l和r~n中有多少个不同的数字 题目思路:之前只是听说过莫队算 ...

最新文章

  1. 剑指offer——面试题10:斐波那契数列
  2. [UML]UML系列——状态机图statechart diagram
  3. 给我十分钟带你过完java多线程所有基础知识
  4. 如何使用BHO定制你的Internet Explorer浏览器
  5. 论文总结Graph Neural Networks-A review of methods and Applications
  6. 渐渐淡去的emacs
  7. 数学之美 第三版 目录
  8. 高中信息技术简答题汇总
  9. 惠普HP Color LaserJet Pro MFP M476 打印机驱动
  10. 识别各种安全设备及当今体现形态-区别UTM与NGFW
  11. 利用EXCEL批量重命名文件
  12. 云时代下主机安全防护建设,用RS-CDPS就够了
  13. 本地计算机上的MySQL服务启动后停止。某些服务在未由其他服务或程序使用时将自动停止.
  14. Java继承(extends )
  15. 你的文件还都在桌面吗?也许是时候换个地方了
  16. 无线传感器:智能建筑系统的眼睛和指尖
  17. 教你用大功率路由器实现覆盖3平方公里wix公众账号吸粉神器
  18. python批量检索文献_Python+Selenium,让浏览器自动帮你下文献
  19. 2021关于网站优化建议
  20. C++递增和递减运算符

热门文章

  1. python编程软件哪个好-来 看看谁最适合学Python编程
  2. python发音翻译-Python translate()方法
  3. python是什么 自学-自学Python会有什么困难?老男孩自学python编程
  4. 输入法黑科技:语音识别准确率98% 用户超过6亿
  5. php课后题,知到PHP语言程序设计课后习题答案
  6. java index.jsp为什么不默认跳转_Java开发人员怎么面试 常见Redis面试题有哪些
  7. 搭建NodeJS环境
  8. 关于axios中'$router' of undefined问题
  9. 蓝桥杯日期填空问题:高斯日记/星系炸弹
  10. linux定时任务被挖矿修改,Linux挖矿威胁情报分享(被植入计划任务)