这题一直re不造为啥。。后来yww大神把树状数组“倒过来”就过了,倒过来的好处是算sum(d[i]+1)就行,不涉及除法,不用求逆元。

题意:初始手牌颜值是0,一共抽卡n次,第i次抽卡有pi的概率能抽到颜值为di的卡,若di>当前手牌颜值,则替换,最后问改变手牌次数的期望。

做法:树状数组维护前缀概率积。先把di离散化,di作为下标,pi作为值,逆元用费马小定理那个推论,本质就是求每次改变手牌的概率,第i次就是pi(1-pj)(1-pk)...(其中j,k<i),即p[i]*sum(d[i]+1)。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<cstdlib>
  5. #include<ctime>
  6. #include<functional>
  7. #include<cmath>
  8. #include<vector>
  9. #include<queue>
  10. #include<map>
  11. #include<set>
  12. #include<stack>
  13. #include<bitset>
  14. using namespace std;
  15. typedef long long ll;
  16. typedef unsigned long long ull;
  17. typedef double db;
  18. typedef long double ldb;
  19. typedef pair<int,int> pii;
  20. typedef pair<ll,ll> pll;
  21. void open(const char *s){
  22. #ifndef ONLINE_JUDGE
  23. char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
  24. #endif
  25. }
  26. void open2(const char *s){
  27. #ifdef DEBUG
  28. char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
  29. #endif
  30. }
  31. template <class T>
  32. int upmin(T &a, const T &b){return (b<a?a=b,1:0);}
  33. template <class T>
  34. int upmax(T &a, const T &b){return (b>a?a=b,1:0);}
  35. namespace io
  36. {
  37. const int SIZE=(1<<20)+1;
  38. char ibuf[SIZE],*iS,*iT;
  39. char obuf[SIZE],*oS=obuf,*oT=oS+SIZE-1;
  40. int getc()
  41. {
  42. (iS==iT?iS=ibuf,iT=ibuf+fread(ibuf,1,SIZE,stdin):0);
  43. return iS==iT?EOF:*(iS++);
  44. }
  45. int f;
  46. char c;
  47. template <class T>
  48. void get(T &x)
  49. {
  50. f=1;
  51. for(c=getc();(c<'0'||c>'9')&&c!='-';c=getc());
  52. (c=='-'?f=-1,c=getc():0);
  53. x=0;
  54. for(;c>='0'&&c<='9';c=getc())
  55. x=x*10+c-'0';
  56. x*=f;
  57. }
  58. void flush()
  59. {
  60. fwrite(obuf,1,oS-obuf,stdout);
  61. oS=obuf;
  62. }
  63. void putc(char x)
  64. {
  65. *(oS++)=x;
  66. if(oS==oT)
  67. flush();
  68. }
  69. int a[55],t;
  70. template <class T>
  71. void put(T x)
  72. {
  73. if(!x)
  74. putc('0');
  75. x<0?putc('-'),x=-x:0;
  76. while(x)
  77. {
  78. a[++t]=x%10;
  79. x/=10;
  80. }
  81. while(t)
  82. putc(a[t--]+'0');
  83. }
  84. void space()
  85. {
  86. putc(' ');
  87. }
  88. void enter()
  89. {
  90. putc('\n');
  91. }
  92. struct flusher
  93. {
  94. ~flusher()
  95. {
  96. flush();
  97. }
  98. }
  99. io_flusher;
  100. }
  101. const int infi=0x3fffffff;
  102. const ll infll=0x3fffffffffffffffll;
  103. const int N=100010;
  104. const ll p=1000000007;
  105. ll fp(ll a,ll b)
  106. {
  107. ll s=1;
  108. for(;b;b>>=1,a=a*a%p)
  109. if(b&1)
  110. s=s*a%p;
  111. return s;
  112. }
  113. const ll inv100=fp(100,p-2);
  114. ll a[N],d[N];
  115. int b[N],c[N];
  116. int n,t;
  117. void add(int x,ll v)
  118. {
  119. for(;x;x-=x&-x)
  120. d[x]=d[x]*v%p;
  121. }
  122. ll sum(int x)
  123. {
  124. ll res=1;
  125. for(;x<=t;x+=x&-x)
  126. res=res*d[x]%p;
  127. return res;
  128. }
  129. void solve()
  130. {
  131. scanf("%d",&n);
  132. for(int i=1;i<=n;i++)
  133. {
  134. scanf("%lld%d",&a[i],&b[i]);
  135. a[i]=a[i]*inv100%p;
  136. c[i]=b[i];
  137. }
  138. sort(c+1,c+n+1);
  139. t=unique(c+1,c+n+1)-c-1;
  140. for(int i=1;i<=n;i++)
  141. b[i]=lower_bound(c+1,c+t+1,b[i])-c;
  142. for(int i=1;i<=n;i++)
  143. d[i]=1;
  144. ll ans=0;
  145. for(int i=1;i<=n;i++)
  146. {
  147. ans=(ans+a[i]*sum(b[i]+1))%p;
  148. add(b[i],1-a[i]);
  149. }
  150. ans=(ans%p+p)%p;
  151. printf("%lld\n",ans);
  152. }
  153. int main()
  154. {
  155. int t;
  156. scanf("%d",&t);
  157. while(t--)
  158. solve();
  159. return 0;
  160. }

neuoj1472 yuki的氪金之旅(倒置树状数组的更多相关文章

  1. UVA 11610 Reverse Prime (数论+树状数组+二分,难题)

    参考链接http://blog.csdn.net/acm_cxlove/article/details/8264290http://blog.csdn.net/w00w12l/article/deta ...

  2. HDU 1394 Minimum Inversion Number (树状数组 && 规律 && 逆序数)

    题意 : 有一个n个数的数列且元素都是0~n-1,问你将数列的其中某一个数及其前面的数全部置到后面这种操作中(比如3 2 1 0中选择第二个数倒置就产生1 0 3 2)能产生的最少的逆序数对是多少? ...

  3. BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]

    1103: [POI2007]大都市meg Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2221  Solved: 1179[Submit][Sta ...

  4. bzoj1878--离线+树状数组

    这题在线做很麻烦,所以我们选择离线. 首先预处理出数组next[i]表示i这个位置的颜色下一次出现的位置. 然后对与每种颜色第一次出现的位置x,将a[x]++. 将每个询问按左端点排序,再从左往右扫, ...

  5. codeforces 597C C. Subsequences(dp+树状数组)

    题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...

  6. BZOJ 2434: [Noi2011]阿狸的打字机 [AC自动机 Fail树 树状数组 DFS序]

    2434: [Noi2011]阿狸的打字机 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 2545  Solved: 1419[Submit][Sta ...

  7. BZOJ 3529: [Sdoi2014]数表 [莫比乌斯反演 树状数组]

    3529: [Sdoi2014]数表 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1399  Solved: 694[Submit][Status] ...

  8. BZOJ 3289: Mato的文件管理[莫队算法 树状数组]

    3289: Mato的文件管理 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 2399  Solved: 988[Submit][Status][Di ...

  9. 【Codeforces163E】e-Government AC自动机fail树 + DFS序 + 树状数组

    E. e-Government time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...

随机推荐

  1. 封装通用的 ajax, 基于 jQuery。

    在前端异步获取数据时候每次都是使用 ajax:为了通用性更好,然而封装通用的 ajax 是一个一劳永逸的办法. 本次基于 jQuery 封装实现: 第一步: 引入 jQuery: <script ...

  2. winXP 系统下ubuntu-12.04 硬盘安装

    目地:实现XP ubuntu双系统,引导可选择. 出处:根查阅网络资料和自己的安装体检,记录如是. 系统版本:windowsXP  SP3   Ubuntu 12.04 工具资源:grup4dos 2 ...

  3. (21)UML类图学习及使用

    UML类图的学习和使用 1.参考博客http://www.uml.org.cn/oobject/201211231.asp

  4. 安装JDK ,提示 错误1316 指定的账户已存在

    基于情况: 安装了一个JDK 后,在文件目录中删除了相关文件,之后再次安装,提示  错误1316 指定的账户已存在 造成原因:安装JDK,相当于安装了一个软件,要使用系统的软件卸载功能卸载,不能只删除 ...

  5. Pap.er 模仿 - 第一天

    最后更新: 2017-12-15 一. 项目初始化 解析对应的资源, 下载Pap.er之后,需要解析里面的资源. 采用如下的方法: http://blog.csdn.net/xuzihai0703/a ...

  6. SpringBoot:配置文件及自动配置原理

    西部开源-秦疆老师:基于SpringBoot 2.1.6 的博客教程 秦老师交流Q群号: 664386224 未授权禁止转载!编辑不易 , 转发请注明出处!防君子不防小人,共勉! SpringBoot ...

  7. 1>/dev/null 2>&1的含义

      shell中可能经常能看到:>/dev/null 2>&1    分解这个组合:“>/dev/null 2>&1” 为五部分. 1:> 代表重定向到哪 ...

  8. 内置函数zip,map,even

    内置函数的补充:1.zip:l1 = ['a','b','c','e','f','g']l2 = [1,2,3]l3=['A','B','C']L4=['牛','牛','niu']#zip,就是把俩l ...

  9. SharpBrowser

    SharpBrowser is the fastest open source C# web browser there is! Slightly faster than Google Chrome ...

  10. Where we love is home, home that our feet may leave, but not our hearts.

    parcel.n. 包裹 endurance.n.耐力 rot.v.腐烂 ornament.n.装饰 pinch.v.捏 nationality.n.国家 sunshine.n.阳光 stagger. ...