CF1540C2.Converging Array (Hard Version)

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is the hard version of the problem. The only difference is that in this version 1≤q≤1051 \le q \le 10^5. You can make hacks only if both versions of the problem are solved.

There is a process that takes place on arrays aa and bb of length nn and length n−1n-1 respectively.

The process is an infinite sequence of operations. Each operation is as follows:

  • First, choose a random integer ii (1≤i≤n−11 \le i \le n-1).
  • Then, simultaneously set ai=min⁡(ai,ai+ai+1−bi2)a_i = \min\left(a_i, \frac{a_i+a_{i+1}-b_i}{2}\right) and ai+1=max⁡(ai+1,ai+ai+1+bi2)a_{i+1} = \max\left(a_{i+1}, \frac{a_i+a_{i+1}+b_i}{2}\right) without any rounding (so values may become non-integer).

See notes for an example of an operation.

It can be proven that array aa converges, i. e. for each ii there exists a limit aia_i converges to. Let function F(a,b)F(a, b) return the value a1a_1 converges to after a process on aa and bb.

You are given array bb, but not array aa. However, you are given a third array cc. Array aa is good if it contains only integers and satisfies 0≤ai≤ci0 \leq a_i \leq c_i for 1≤i≤n1 \leq i \leq n.

Your task is to count the number of good arrays aa where F(a,b)≥xF(a, b) \geq x for qq values of xx. Since the number of arrays can be very large, print it modulo 109+710^9+7.

这是该问题的困难版本。唯一区别在于本版本中 1≤q≤1051 \le q \le 10^5。仅当该问题的两个版本均被解决时,才允许进行 hack。

存在一个在长度为 nn 的数组 aa 和长度为 n−1n-1 的数组 bb 上进行的过程。

该过程是一系列无限次操作。每次操作如下:

  • 首先,随机选择一个整数 ii(1≤i≤n−11 \le i \le n-1);
  • 然后,同时执行以下赋值(不作任何舍入,因此数值可能变为非整数):

    ai=min⁡(ai,ai+ai+1−bi2),ai+1=max⁡(ai+1,ai+ai+1+bi2).a_i = \min\left(a_i, \frac{a_i+a_{i+1}-b_i}{2}\right), \quad a_{i+1} = \max\left(a_{i+1}, \frac{a_i+a_{i+1}+b_i}{2}\right).

参见“注释”部分以了解一次操作的示例。

可以证明数组 aa 是收敛的,即对每个 ii,极限 lim⁡t→∞ai(t)\lim_{t \to \infty} a_i^{(t)} 存在。定义函数 F(a,b)F(a, b) 为:在数组 aa 和 bb 上执行该过程后,a1a_1 所收敛到的极限值。

你被给定数组 bb,但未给出数组 aa。然而,你还被给定第三个数组 cc。若数组 aa 仅包含整数,且对所有 1≤i≤n1 \le i \le n 满足 0≤ai≤ci0 \leq a_i \leq c_i,则称其为合法数组(good array)。

你的任务是:对 qq 个不同的 xx 值,分别计算满足 F(a,b)≥xF(a, b) \geq x 的合法数组 aa 的个数。由于数组总数可能极大,请将结果对 109+710^9+7 取模后输出。

输入格式

The first line contains a single integer nn (2≤n≤1002 \le n \le 100).

The second line contains nn integers c1,c2…,cnc_1, c_2 \ldots, c_n (0≤ci≤1000 \le c_i \le 100).

The third line contains n−1n-1 integers b1,b2,…,bn−1b_1, b_2, \ldots, b_{n-1} (0≤bi≤1000 \le b_i \le 100).

The fourth line contains a single integer qq (1≤q≤1051 \le q \le 10^5).

The fifth line contains qq space separated integers x1,x2,…,xqx_1, x_2, \ldots, x_q (−105≤xi≤105-10^5 \le x_i \le 10^5).

第一行包含一个整数 nn(2≤n≤1002 \le n \le 100)。

第二行包含 nn 个整数 c1,c2,…,cnc_1, c_2, \ldots, c_n(0≤ci≤1000 \le c_i \le 100)。

第三行包含 n−1n-1 个整数 b1,b2,…,bn−1b_1, b_2, \ldots, b_{n-1}(0≤bi≤1000 \le b_i \le 100)。

第四行包含一个整数 qq(1≤q≤1051 \le q \le 10^5)。

第五行包含 qq 个用空格分隔的整数 x1,x2,…,xqx_1, x_2, \ldots, x_q(−105≤xi≤105-10^5 \le x_i \le 10^5)。

输出格式

Output qq integers, where the ii-th integer is the answer to the ii-th query, i. e. the number of good arrays aa where F(a,b)≥xiF(a, b) \geq x_i modulo 109+710^9+7.

输出 qq 个整数,其中第 ii 个整数是第 ii 个查询的答案,即满足 F(a,b)≥xiF(a, b) \geq x_i 的好数组 aa 的数量对 109+710^9+7 取模的结果。

输入输出样例

  • 输入#1

    3
    2 3 4
    2 1
    5
    -1 0 1 -100000 100000

    输出#1

    56
    28
    4
    60
    0

说明/提示

The following explanation assumes b=[2,1]b = [2, 1] and c=[2,3,4]c=[2, 3, 4] (as in the sample).

Examples of arrays aa that are not good:

  • a=[3,2,3]a = [3, 2, 3] is not good because a1>c1a_1 \gt c_1;
  • a=[0,−1,3]a = [0, -1, 3] is not good because a2<0a_2 \lt 0.

One possible good array aa is [0,2,4][0, 2, 4]. We can show that no operation has any effect on this array, so F(a,b)=a1=0F(a, b) = a_1 = 0.

Another possible good array aa is [0,1,4][0, 1, 4]. In a single operation with i=1i = 1, we set a1=min⁡(0+1−22,0)a_1 = \min(\frac{0+1-2}{2}, 0) and a2=max⁡(0+1+22,1)a_2 = \max(\frac{0+1+2}{2}, 1). So, after a single operation with i=1i = 1, aa becomes equal to [−12,32,4][-\frac{1}{2}, \frac{3}{2}, 4]. We can show that no operation has any effect on this array, so F(a,b)=−12F(a, b) = -\frac{1}{2}.

以下说明假设 b=[2,1]b = [2, 1] 且 c=[2,3,4]c=[2, 3, 4](如样例所示)。

不是“好”数组的 aa 的示例:

  • a=[3,2,3]a = [3, 2, 3] 不是好数组,因为 a1>c1a_1 \gt c_1;
  • a=[0,−1,3]a = [0, -1, 3] 不是好数组,因为 a2<0a_2 \lt 0。

一个可能的好数组 aa 是 [0,2,4][0, 2, 4]。我们可以证明对该数组执行任何操作均无效果,因此 F(a,b)=a1=0F(a, b) = a_1 = 0。

另一个可能的好数组 aa 是 [0,1,4][0, 1, 4]。在一次以 i=1i = 1 进行的操作中,我们设 a1=min⁡(0+1−22,0)a_1 = \min(\frac{0+1-2}{2}, 0) 且 a2=max⁡(0+1+22,1)a_2 = \max(\frac{0+1+2}{2}, 1)。因此,在一次以 i=1i = 1 进行的操作后,aa 变为 [−12,32,4][-\frac{1}{2}, \frac{3}{2}, 4]。我们可以证明对该数组执行任何操作均无效果,因此 F(a,b)=−12F(a, b) = -\frac{1}{2}。

输入解题思路,AI测评打分。不知道怎么写?

首页