neuoj1472 yuki的氪金之旅(倒置树状数组
这题一直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)。
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- #include<cstdlib>
- #include<ctime>
- #include<functional>
- #include<cmath>
- #include<vector>
- #include<queue>
- #include<map>
- #include<set>
- #include<stack>
- #include<bitset>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef double db;
- typedef long double ldb;
- typedef pair<int,int> pii;
- typedef pair<ll,ll> pll;
- void open(const char *s){
- #ifndef ONLINE_JUDGE
- char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
- #endif
- }
- void open2(const char *s){
- #ifdef DEBUG
- char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
- #endif
- }
- template <class T>
- int upmin(T &a, const T &b){return (b<a?a=b,1:0);}
- template <class T>
- int upmax(T &a, const T &b){return (b>a?a=b,1:0);}
- namespace io
- {
- const int SIZE=(1<<20)+1;
- char ibuf[SIZE],*iS,*iT;
- char obuf[SIZE],*oS=obuf,*oT=oS+SIZE-1;
- int getc()
- {
- (iS==iT?iS=ibuf,iT=ibuf+fread(ibuf,1,SIZE,stdin):0);
- return iS==iT?EOF:*(iS++);
- }
- int f;
- char c;
- template <class T>
- void get(T &x)
- {
- f=1;
- for(c=getc();(c<'0'||c>'9')&&c!='-';c=getc());
- (c=='-'?f=-1,c=getc():0);
- x=0;
- for(;c>='0'&&c<='9';c=getc())
- x=x*10+c-'0';
- x*=f;
- }
- void flush()
- {
- fwrite(obuf,1,oS-obuf,stdout);
- oS=obuf;
- }
- void putc(char x)
- {
- *(oS++)=x;
- if(oS==oT)
- flush();
- }
- int a[55],t;
- template <class T>
- void put(T x)
- {
- if(!x)
- putc('0');
- x<0?putc('-'),x=-x:0;
- while(x)
- {
- a[++t]=x%10;
- x/=10;
- }
- while(t)
- putc(a[t--]+'0');
- }
- void space()
- {
- putc(' ');
- }
- void enter()
- {
- putc('\n');
- }
- struct flusher
- {
- ~flusher()
- {
- flush();
- }
- }
- io_flusher;
- }
- const int infi=0x3fffffff;
- const ll infll=0x3fffffffffffffffll;
- const int N=100010;
- const ll p=1000000007;
- ll fp(ll a,ll b)
- {
- ll s=1;
- for(;b;b>>=1,a=a*a%p)
- if(b&1)
- s=s*a%p;
- return s;
- }
- const ll inv100=fp(100,p-2);
- ll a[N],d[N];
- int b[N],c[N];
- int n,t;
- void add(int x,ll v)
- {
- for(;x;x-=x&-x)
- d[x]=d[x]*v%p;
- }
- ll sum(int x)
- {
- ll res=1;
- for(;x<=t;x+=x&-x)
- res=res*d[x]%p;
- return res;
- }
- void solve()
- {
- scanf("%d",&n);
- for(int i=1;i<=n;i++)
- {
- scanf("%lld%d",&a[i],&b[i]);
- a[i]=a[i]*inv100%p;
- c[i]=b[i];
- }
- sort(c+1,c+n+1);
- t=unique(c+1,c+n+1)-c-1;
- for(int i=1;i<=n;i++)
- b[i]=lower_bound(c+1,c+t+1,b[i])-c;
- for(int i=1;i<=n;i++)
- d[i]=1;
- ll ans=0;
- for(int i=1;i<=n;i++)
- {
- ans=(ans+a[i]*sum(b[i]+1))%p;
- add(b[i],1-a[i]);
- }
- ans=(ans%p+p)%p;
- printf("%lld\n",ans);
- }
- int main()
- {
- int t;
- scanf("%d",&t);
- while(t--)
- solve();
- return 0;
- }
neuoj1472 yuki的氪金之旅(倒置树状数组的更多相关文章
- UVA 11610 Reverse Prime (数论+树状数组+二分,难题)
参考链接http://blog.csdn.net/acm_cxlove/article/details/8264290http://blog.csdn.net/w00w12l/article/deta ...
- HDU 1394 Minimum Inversion Number (树状数组 && 规律 && 逆序数)
题意 : 有一个n个数的数列且元素都是0~n-1,问你将数列的其中某一个数及其前面的数全部置到后面这种操作中(比如3 2 1 0中选择第二个数倒置就产生1 0 3 2)能产生的最少的逆序数对是多少? ...
- BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]
1103: [POI2007]大都市meg Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2221 Solved: 1179[Submit][Sta ...
- bzoj1878--离线+树状数组
这题在线做很麻烦,所以我们选择离线. 首先预处理出数组next[i]表示i这个位置的颜色下一次出现的位置. 然后对与每种颜色第一次出现的位置x,将a[x]++. 将每个询问按左端点排序,再从左往右扫, ...
- codeforces 597C C. Subsequences(dp+树状数组)
题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...
- BZOJ 2434: [Noi2011]阿狸的打字机 [AC自动机 Fail树 树状数组 DFS序]
2434: [Noi2011]阿狸的打字机 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 2545 Solved: 1419[Submit][Sta ...
- BZOJ 3529: [Sdoi2014]数表 [莫比乌斯反演 树状数组]
3529: [Sdoi2014]数表 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1399 Solved: 694[Submit][Status] ...
- BZOJ 3289: Mato的文件管理[莫队算法 树状数组]
3289: Mato的文件管理 Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 2399 Solved: 988[Submit][Status][Di ...
- 【Codeforces163E】e-Government AC自动机fail树 + DFS序 + 树状数组
E. e-Government time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...
随机推荐
- 封装通用的 ajax, 基于 jQuery。
在前端异步获取数据时候每次都是使用 ajax:为了通用性更好,然而封装通用的 ajax 是一个一劳永逸的办法. 本次基于 jQuery 封装实现: 第一步: 引入 jQuery: <script ...
- winXP 系统下ubuntu-12.04 硬盘安装
目地:实现XP ubuntu双系统,引导可选择. 出处:根查阅网络资料和自己的安装体检,记录如是. 系统版本:windowsXP SP3 Ubuntu 12.04 工具资源:grup4dos 2 ...
- (21)UML类图学习及使用
UML类图的学习和使用 1.参考博客http://www.uml.org.cn/oobject/201211231.asp
- 安装JDK ,提示 错误1316 指定的账户已存在
基于情况: 安装了一个JDK 后,在文件目录中删除了相关文件,之后再次安装,提示 错误1316 指定的账户已存在 造成原因:安装JDK,相当于安装了一个软件,要使用系统的软件卸载功能卸载,不能只删除 ...
- Pap.er 模仿 - 第一天
最后更新: 2017-12-15 一. 项目初始化 解析对应的资源, 下载Pap.er之后,需要解析里面的资源. 采用如下的方法: http://blog.csdn.net/xuzihai0703/a ...
- SpringBoot:配置文件及自动配置原理
西部开源-秦疆老师:基于SpringBoot 2.1.6 的博客教程 秦老师交流Q群号: 664386224 未授权禁止转载!编辑不易 , 转发请注明出处!防君子不防小人,共勉! SpringBoot ...
- 1>/dev/null 2>&1的含义
shell中可能经常能看到:>/dev/null 2>&1 分解这个组合:“>/dev/null 2>&1” 为五部分. 1:> 代表重定向到哪 ...
- 内置函数zip,map,even
内置函数的补充:1.zip:l1 = ['a','b','c','e','f','g']l2 = [1,2,3]l3=['A','B','C']L4=['牛','牛','niu']#zip,就是把俩l ...
- SharpBrowser
SharpBrowser is the fastest open source C# web browser there is! Slightly faster than Google Chrome ...
- 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. ...