Problem - D - Codeforces
思路
\(dp_i\) 表示从 \(1\) 到 \(i\) 单元都恰好被一次覆盖的概率。
整体不好转移。考虑贡献。
最显然的是:
\[dp_{r_i} =\sum _{i=1}^{m} dp_{l_i-1}\times x_i
\]
其中 \(x_i\) 表示在 \([l_i,r_i]\) 中只出现 \(i\) 这个区间的概率。
怎么维护 \(x\) :
\(P_{l,r}\) 为 \([l,r]\) 中所有区间都消失的概率。前缀和维护。
\[x_i=\frac{P_{l,r}}{1-\frac{p_i}{q_i}}\times \frac{p_i}{q_i}
\]
煎蛋
code
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10,mod=998244353;
#define ll __int128
struct Node{
int l,r;
ll pro;
bool operator<(const Node x)const{
return l<x.l;
}
}a[N];
int n,m;
ll qp(ll a,int b){
ll res=1;
while(b){
if(b&1) res=res*a%mod;
a=a*a%mod;
b>>=1;
}return res;
}
ll dp[N],P[N]/*P[l],[1,l]都无覆盖的p*/;
signed main(){
ios::sync_with_stdio(0),cin.tie(0);
cin>>n>>m;
for(int i=0;i<=m;++i)P[i]=1;
for(int i=1;i<=n;++i){
int q,p;
cin>>a[i].l>>a[i].r>>p>>q;
a[i].pro=1ll*p*qp(q,mod-2)%mod;
P[a[i].l]=P[a[i].l]*(1ll-a[i].pro+mod)%mod;
}
for(int i=1;i<=m;++i) P[i]=P[i-1]*P[i]%mod;
sort(a+1,a+1+n);
dp[0]=1;
for(int i=1;i<=n;++i){
int l=a[i].l,r=a[i].r,p=a[i].pro;
ll tmp=dp[l-1]*P[r]%mod*qp(P[l-1],mod-2)%mod*qp((1-p+mod)%mod,mod-2)%mod*p%mod;
dp[r]=(dp[r]+tmp)%mod;
}
cout<<(long long)dp[m];
return 0;
}

浙公网安备 33010602011771号