标签:计算方法 play class because abs 方法 https ali hdu
Link
如果\(l=r\)那么我们给它加个特判。(虽然数据里没有)
先写出答案的表达式:
\[
\frac{\int_{l_1}^{r_1}\cdots\int_{l_n}^{r_n}|\sum\limits_{i=1}^nx_i|\mathrm dx_n\cdots\mathrm dx_1}{\prod\limits_{i=1}^n(r_i-l_i)}
\]
注意到\(|x|=\max(x,0)-\min(x,0)\),\(\min,\max\)的计算方法非常相似,因此我们只考虑计算:
\[
\int_{l_1}^{r_1}\cdots\int_{l_n}^{r_n}\max(\sum\limits_{i=1}^nx_i,0)\mathrm dx_n\cdots\mathrm dx_1
\]
考虑容斥,我们需要计算的变成了:
\[
f(t_1,\cdots,t_n)=\int_{-\infty}^{t_1}\cdots\int_{-\infty}^{t_n}\max(\sum\limits_{i=1}^nx_i,0)\mathrm dx_n\cdots\mathrm dx_1
\]
设\(y_i=t_i-x_i,S=\sum\limits_{i=1}^nt_i\):
\[
\begin{aligned}
&f(t_1,\cdots,t_n)=\int_0^{+\infty}\cdots\int_0^{+\infty}\max(S-\sum\limits_{i=1}^ny_i,0)\mathrm dy_n\cdots\mathrm dy_1\&\because\qquad\max(S-\sum\limits_{i=1}^ny_i,0)=\int_0^{+\infty}[\sum\limits_{i=1}^{n+1}y_i\le S]\mathrm dy_{n+1}\&\therefore\qquad f(t_1,\cdots,t_n)=\int_0^{+\infty}\cdots\int_0^{+\infty}[\sum\limits_{i=1}^{n+1}y_i\le S]\mathrm dy_{n+1}\cdots\mathrm dy_1
\end{aligned}
\]
设\(s_m=\sum\limits_{i=1}^m y_i\):
\[
f(t_1,\cdots,t_n)=\int_0^S\cdots\int_{s_n}^S1\mathrm ds_{n+1}\cdots\mathrm ds_1=\frac{S^{n+1}}{(n+1)!}
\]
那么答案就是:
\[
\sum\limits_{t_i\in\{l_i,r_i\}}(-1)^{\sum\limits_{i=1}^n[t_i=l_i]}f(t_1,\cdots,t_n)
\]
#include<cstdio>
const int N=100007,P=998244353;
int read(){int x;scanf("%d",&x);return x;}
void inc(int&a,int b){a+=b-P,a+=a>>31&P;}
void dec(int&a,int b){a-=b,a+=a>>31&P;}
int mul(int a,int b){return 1ll*a*b%P;}
int pow(int a,int k){int r=1;for(;k;k>>=1,a=mul(a,a))if(k&1)r=mul(a,r);return r;}
int n,l[N],r[N],ans;
void dfs(int k,int s,int f1,int f2)
{
if(k>n)
{
if(s>0) inc(ans,mul(f1,pow(s,n+1)));
if(s<0) dec(ans,mul(f2,pow(-s,n+1)));
return ;
}
dfs(k+1,s+l[k],P-f1,f2),dfs(k+1,s+r[k],f1,P-f2);
}
int main()
{
n=read();int m=n+1;
for(int i=1;i<=n;++i) l[i]=read(),r[i]=read(),m=mul(m,mul(r[i]-l[i],i));
dfs(1,0,1,P-1),printf("%d\n",mul(ans,pow(m,P-2)));
}
标签:计算方法 play class because abs 方法 https ali hdu
原文地址:https://www.cnblogs.com/cjoierShiina-Mashiro/p/12507682.html