dp姿势不对导致复杂度直线上升qaq
这个的期望主要是通过计算每个点的贡献,每个点都会发生交换,那么就看发生交换的概率了。。
这个概率主要是让前面的size大于他的点不出现,那么把对立事件的概率乘起来再乘他本身出现的概率就可以了。。
那么可以这么做。。按size从大到小算,每次将1-pi维护到前缀乘积中。。
单点修改,单点查询肯定用bit啦。。
/**
* ┏┓ ┏┓
* ┏┛┗━━━━━━━┛┗━━━┓
* ┃ ┃
* ┃ ━ ┃
* ┃ > < ┃
* ┃ ┃
* ┃... ⌒ ... ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃ Code is far away from bug with the animal protecting
* ┃ ┃ 神兽保佑,代码无bug
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━━━━━━━━┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-8
#define succ(x) (1LL<<(x))
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 100005
#define nm 100005
#define N 1000005
#define M(x,y) x=max(x,y)
const double pi=acos(-1);
const ll inf=998244353;
using namespace std;
ll read(){
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}
ll qpow(ll x,ll t){return t?qpow(sqr(x)%inf,t>>1)*(t&1?x:1)%inf:1LL;}
int n,a[NM],b[NM],tmp[NM];
ll ans,c[NM],inv100;
bool cmp(int x,int y){return b[x]>b[y];}
void add(int x,ll t){for(;x<=n;x+=lowbit(x))c[x]=c[x]*t%inf;}
ll sum(int x,ll s=1){for(;x;x-=lowbit(x))s=s*c[x]%inf;return s;}
int main(){
inv100=qpow(100,inf-2);
n=read();inc(i,1,n)a[i]=read(),b[i]=read(),tmp[i]=i;
inc(i,1,n)c[i]=1;
sort(tmp+1,tmp+1+n,cmp);
inc(k,1,n){
int i=tmp[k];
ans+=sum(i-1)*inv100%inf*a[i]%inf;ans%=inf;
add(i,(100-a[i])*inv100%inf);
}
return 0*printf("%lld\n",ans);
}
链接:https://www.nowcoder.com/acm/contest/143/F
来源:牛客网
take
时间限制: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