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≤105. You can make hacks only if both versions of the problem are solved.
There is a process that takes place on arrays a and b of length n and length n−1 respectively.
The process is an infinite sequence of operations. Each operation is as follows:
- First, choose a random integer i (1≤i≤n−1).
- Then, simultaneously set ai=min(ai,2ai+ai+1−bi) and ai+1=max(ai+1,2ai+ai+1+bi) without any rounding (so values may become non-integer).
See notes for an example of an operation.
It can be proven that array a converges, i. e. for each i there exists a limit ai converges to. Let function F(a,b) return the value a1 converges to after a process on a and b.
You are given array b, but not array a. However, you are given a third array c. Array a is good if it contains only integers and satisfies 0≤ai≤ci for 1≤i≤n.
Your task is to count the number of good arrays a where F(a,b)≥x for q values of x. Since the number of arrays can be very large, print it modulo 109+7.
这是该问题的困难版本。唯一区别在于本版本中 1≤q≤105。仅当该问题的两个版本均被解决时,才允许进行 hack。
存在一个在长度为 n 的数组 a 和长度为 n−1 的数组 b 上进行的过程。
该过程是一系列无限次操作。每次操作如下:
- 首先,随机选择一个整数 i(1≤i≤n−1);
- 然后,同时执行以下赋值(不作任何舍入,因此数值可能变为非整数):
ai=min(ai,2ai+ai+1−bi),ai+1=max(ai+1,2ai+ai+1+bi).
参见“注释”部分以了解一次操作的示例。
可以证明数组 a 是收敛的,即对每个 i,极限 limt→∞ai(t) 存在。定义函数 F(a,b) 为:在数组 a 和 b 上执行该过程后,a1 所收敛到的极限值。
你被给定数组 b,但未给出数组 a。然而,你还被给定第三个数组 c。若数组 a 仅包含整数,且对所有 1≤i≤n 满足 0≤ai≤ci,则称其为合法数组(good array)。
你的任务是:对 q 个不同的 x 值,分别计算满足 F(a,b)≥x 的合法数组 a 的个数。由于数组总数可能极大,请将结果对 109+7 取模后输出。
输入格式
The first line contains a single integer n (2≤n≤100).
The second line contains n integers c1,c2…,cn (0≤ci≤100).
The third line contains n−1 integers b1,b2,…,bn−1 (0≤bi≤100).
The fourth line contains a single integer q (1≤q≤105).
The fifth line contains q space separated integers x1,x2,…,xq (−105≤xi≤105).
第一行包含一个整数 n(2≤n≤100)。
第二行包含 n 个整数 c1,c2,…,cn(0≤ci≤100)。
第三行包含 n−1 个整数 b1,b2,…,bn−1(0≤bi≤100)。
第四行包含一个整数 q(1≤q≤105)。
第五行包含 q 个用空格分隔的整数 x1,x2,…,xq(−105≤xi≤105)。
输出格式
Output q integers, where the i-th integer is the answer to the i-th query, i. e. the number of good arrays a where F(a,b)≥xi modulo 109+7.
输出 q 个整数,其中第 i 个整数是第 i 个查询的答案,即满足 F(a,b)≥xi 的好数组 a 的数量对 109+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] and c=[2,3,4] (as in the sample).
Examples of arrays a that are not good:
- a=[3,2,3] is not good because a1>c1;
- a=[0,−1,3] is not good because a2<0.
One possible good array a is [0,2,4]. We can show that no operation has any effect on this array, so F(a,b)=a1=0.
Another possible good array a is [0,1,4]. In a single operation with i=1, we set a1=min(20+1−2,0) and a2=max(20+1+2,1). So, after a single operation with i=1, a becomes equal to [−21,23,4]. We can show that no operation has any effect on this array, so F(a,b)=−21.
以下说明假设 b=[2,1] 且 c=[2,3,4](如样例所示)。
不是“好”数组的 a 的示例:
- a=[3,2,3] 不是好数组,因为 a1>c1;
- a=[0,−1,3] 不是好数组,因为 a2<0。
一个可能的好数组 a 是 [0,2,4]。我们可以证明对该数组执行任何操作均无效果,因此 F(a,b)=a1=0。
另一个可能的好数组 a 是 [0,1,4]。在一次以 i=1 进行的操作中,我们设 a1=min(20+1−2,0) 且 a2=max(20+1+2,1)。因此,在一次以 i=1 进行的操作后,a 变为 [−21,23,4]。我们可以证明对该数组执行任何操作均无效果,因此 F(a,b)=−21。
输入解题思路,AI测评打分。不知道怎么写?