#P13509. [OOI 2024] Almost Certainly

[OOI 2024] Almost Certainly

题目描述

Let's say that two multisets are equal almost certainly\textbf{almost certainly} if they are equal up to one element. That is, it should be possible to change at most one element in the first multiset so that they become equal. For example, the multisets {1,1,2}\{ 1, 1, 2 \} and {1,2,3}\{ 1, 2, 3\} are equal almost certainly\textit{almost certainly}, {1,1,1}\{1, 1, 1 \} and {1,1,1}\{ 1, 1, 1 \} are equal almost certainly\textit{almost certainly}, and {1,2,3}\{ 1, 2, 3 \} and {3,4,5}\{ 3, 4, 5 \} are not equal almost certainly\textit{almost certainly}.

A boy named Vasya really liked this definition and immediately came up with a problem about it.

Vasya has two arrays aa and bb, where aibia_i \ge b_i for all ii from 11 to nn. Vasya can apply the following operation to array aa as many times as he wants (possibly zero times): choose any index ii (1in1 \le i \le n) and subtract 1 from aia_i. At the same time, Vasya does not change array bb.

Vasya quickly understood what sequence of operations is needed to make the multiset of values of arrays aa and bb equal almost certainly\textit{almost certainly}. Therefore, Vasya made the task more complicated --- now for each prefix of these arrays, he wants to know the minimum number of operations needed to make the prefixes of the arrays equal almost certainly\textit{almost certainly}.

More formally, for each kk from 11 to nn, Vasya wants to take the elements a1,a2,,aka_1, a_2, \ldots, a_k, as well as the elements b1,b2,,bkb_1, b_2, \ldots, b_k. Vasya wants to know the minimum number of operations needed to make the multisets of these elements equal almost certainly\textit{almost certainly}. Note that the task for each kk is solved independently\textbf{independently}.

输入格式

Each test consists of one or more sets of input data. The first line contains a single integer tt (1t1000001 \le t \le 100\,000) --- the number of sets of input data. Then follows the description of the sets of input data.

The first line of each set of input data contains a single integer nn (1n2000001 \le n \le 200\,000) --- the size of arrays aa and bb.

The second line of each set of input data contains nn integers a1, a2, , ana_1,\ a_2,\ \ldots,\ a_n (1ai1091 \le a_i \le 10^9) --- the elements of array aa.

The third line of each set of input data contains nn integers b1, b2, , bnb_1,\ b_2,\ \ldots,\ b_n (1biai1 \le b_i \le a_i) --- the elements of array bb.

Let NN be the sum of nn for all sets of input data in one test. It is guaranteed that N200000N \le 200\,000.

输出格式

For each set of input data, output nn integers, each of which is the answer to the task for each possible prefix length. It can be shown that the answer always exists.

4
2
3 4
1 2
2
3 4
1 3
3
11 17 14
1 13 10
4
100 11 50 42
30 1 20 5
0 1
0 0
0 4 2
0 10 30 48
3
4
2 4 5 12
1 3 4 10
4
3 5 8 20
1 2 6 7
4
4 4 4 4
1 2 3 4
0 1 1 3
0 1 3 6
0 2 3 3

提示

Note

Consider the first set of input data in the first example.

  • For a prefix of length 11, nothing needs to be done.
  • For a prefix of length 22, a1=3a_1 = 3 needs to be decreased by 1 once, after which aa will be equal to [2,4][2, 4], bb will be equal to [1,2][1, 2], and they will be equal almost certainly\textit{almost certainly}.

Consider the third set of input data in the first example.

  • For a prefix of length 11, nothing needs to be done.
  • For a prefix of length 22, a2=17a_2 = 17 needs to be decreased by 4 times, after which the prefix of aa will be equal to [11,13][11, 13], the prefix of bb will be equal to [1,13][1, 13], and they will be equal almost certainly\textit{almost certainly}.
  • For a prefix of length 33, a1=11a_1 = 11 needs to be decreased by 1 and a3=14a_3 = 14 needs to be decreased by 1, after which aa will be equal to [10,17,13][10, 17, 13], bb will be equal to [1,13,11][1, 13, 11], and they will be equal almost certainly\textit{almost certainly}.

Scoring

The tests for this problem consist of six groups. Points for each group are given only if all tests of the group and all tests of the required groups are passed. Please note that passing the example tests is not required for some groups. Offline-evaluation\textbf{Offline-evaluation} means that the results of testing your solution on this group will only be available after the end of the competition.

Group Points Additional constraints Required groups Comment
0 -- Examples.
1 16 N100N \leqslant 100 0 --
2 13 N500N \leqslant 500 0, 1
3 24 N3000N \leqslant 3000 0--2
4 13 -- -- ai<bi+1a_i < b_{i + 1}
5 14 4 aiai+1,bibi+1a_i \leqslant a_{i + 1}, b_i \leqslant b_{i + 1}
6 20 0--5 Offline-evaluation.