CF1540C2.Converging Array (Hard Version)
普及/提高-
通过率:0%
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 .
输入格式
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 ).
输出格式
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 .
输入输出样例
输入#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 .