Sugar Sweet II

시간 제한2초메모리 제한2048 MB

요약
n개의 이벤트가 무작위 순서로 일어나며, i번 아이가 b_i번 아이보다 사탕이 적으면 w_i개를 받는다. 모든 이벤트가 끝난 뒤 각 아이가 가질 사탕 수의 기댓값을 1e9+7로 나눈 나머지로 구한다.
난이도

어려움10점 중 8점

유형
확률, 그래프, 수학
정답자
아직 제출이 없습니다

문제

Sugar is sweet.

There are nn children asking for sugar. Prof. Chen gives out sugar to the children. The ii-th child initially has a_ia\_{i} bags of sugar. There are nn events happening in uniformly randomized order. The ii-th event is:

  • If the ii-th child has strictly less bags of sugar than the b_ib\_{i}-th child, then the ii-th child will get extra w_iw\_{i} bags of sugar. Otherwise, nothing happens.

Now, since the events happen in random order, Randias, which is the assistant of Prof. Chen, wants to know the expected number of bags of sugar each child will have after all the events happen.

It can be shown that the answer can be expressed as an irreducible fraction xy\frac{x}{y} where xx and yy are integers and y≢0(mod109+7)y \not \equiv 0 \pmod {10^9 + 7}. Output the integer equal to x⋅y−1(mod109+7)x \cdot y^{-1} \pmod {10^9 + 7}. In other words, output such an integer aa that 0≤a<109+70\leq a < 10^9 + 7 and a⋅y≡x(mod109+7)a \cdot y \equiv x \pmod {10^9 + 7}.

입력

Each test contains multiple test cases. The first line contains a single interger tt (1≤t≤5⋅1051 \leq t \leq 5 \cdot 10^5) denoting the number of test cases. For each test case:

The first line contains a single integer nn (1≤n≤5⋅1051 \le n \le 5 \cdot 10^5) denoting the number of children.

The second line contains nn integers a_ia\_{i} (1≤a_i≤1091 \le a\_{i} \le 10^9): the initial number of bags of sugar each child has.

The third line contains nn integers b_ib\_{i} (1≤b_i≤n1 \le b\_{i} \le n).

The fourth line contains nn integers w_iw\_{i} (1≤w_i≤1091 \le w\_{i} \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 5⋅1055 \cdot 10^5.

출력

For each test case, output nn integers in a line: the expected number of bags of sugar each child will get. Output the answers as integers modulo 109+710^9 + 7, as described above.

예제1

  1. 예제 1

    입력
    4
    4
    2 5 5 2
    4 2 1 3
    3 2 1 4
    3
    5 4 3
    1 1 1
    6 6 6
    3
    5 4 3
    2 3 1
    1 2 3
    5
    2 1 3 2 1
    5 1 1 3 4
    1 3 4 2 4
    
    예상 출력
    500000007 5 5 6
    5 10 9
    166666673 5 6
    500000006 4 3 4 5