题意
给定\(n\)个元素的序列\(\{a_i\}\),\(m\)个元素的序列\(\{b_i\}\),以及\(L\),求:
\(\sum\limits_{i=1}^n\sum\limits_{j=1}^m\sum\limits_{k=1}^L\lceil\frac{a_i+b_j}{k}\rceil\)
\(n,m\le 1000\)
\(a_i、b_i\in[1,10^9]\)
\(L\in[1,2\times 10^9]\)
做法
取\(B\ge \sqrt{a_i+b_j}\)
\[\begin{aligned}&\sum\limits_{i=1}^n\sum\limits_{j=1}^m\sum\limits_{k=1}^L\lceil\frac{a_i+b_j}{k}\rceil\\ =&\sum\limits_{i=1}^n\sum\limits_{j=1}^m\sum\limits_{l=1}^{\infty}\sum\limits_{k=1}^L[\lceil\frac{a_i+b_j}{k}\rceil\ge l]\\ =&\sum\limits_{i=1}^n\sum\limits_{j=1}^m\{(\sum\limits_{l=1}^{B}\sum\limits_{k=1}^L[\lceil\frac{a_i+b_j}{k}\rceil\ge l])+\sum\limits_{k=1}^L\max(\lceil\frac{a_i+b_j}{k}\rceil-B,0)\}\\ =&\sum\limits_{i=1}^n\sum\limits_{j=1}^m\{\sum\limits_{l=1}^{B}\min(\lfloor\frac{a_i+b_j-1}{l-1}\rfloor,L)+\sum\limits_{k=1}^L\max(\lceil\frac{a_i+b_j}{k}\rceil-B,0)\}\\ =&\sum\limits_{i=1}^n\sum\limits_{j=1}^m\{\sum\limits_{l=1}^{B}\min(\lfloor\frac{a_i+b_j-1}{l-1}\rfloor,L)+\sum\limits_{k=1}^B\max(\lceil\frac{a_i+b_j}{k}\rceil-B,0)\}\\ =&\sum\limits_{i=1}^n\sum\limits_{j=1}^m\{\sum\limits_{l=1}^{B}\min(\lfloor\frac{a_i+b_j-1}{l-1}\rfloor,L)+\sum\limits_{k=1}^B\max(\lceil\frac{a_i+b_j}{k}\rceil,B)-B\}\\ =&\sum\limits_{l=1}^{B}\sum\limits_{i=1}^n\sum\limits_{j=1}^m\min(\lfloor\frac{a_i+b_j-1}{l-1}\rfloor,L)+\sum\limits_{k=1}^B\sum\limits_{i=1}^n\sum\limits_{j=1}^m\max(\lceil\frac{a_i+b_j}{k}\rceil,B)-B\\ \end{aligned}\]两部分处理类似,
例如第一部分,对\(\{a_i\},\{b_i\}\)排序,枚举\(l\),扫描\(i\),这时\(j\)可以分为前后两部分从而去掉\(\min\),\(\lfloor\frac{x+y}{l}\rfloor=\lfloor\frac{x}{l}\rfloor+\lfloor\frac{y}{l}\rfloor+[x\mod l+y\mod l\ge l]\),布尔表达式用树状数组处理。
复杂度\(O(nB\log B)\)
标签:lfloor,lceil,frac,limits,rceil,sum,杂题 From: https://www.cnblogs.com/Grice/p/17591551.html