#P9213. [入门赛 #11] 移植柳树 (Hard Version)

[入门赛 #11] 移植柳树 (Hard Version)

Background

This problem has exactly the same meaning as the Easy Version. The only differences are the constraints and the number of test cases contained in a single test point.

HG is walking to school out of boredom. Looking at the row of willows by the roadside, a strange question suddenly pops into his mind...

Problem Description

Suppose there are nn willow trees in total, and the distance between each adjacent pair is xx.

Now he needs to perform some operations on these trees so that, while keeping the “starting point of these nn trees” unchanged, the distance between any two adjacent trees becomes yy (y>xy > x).

The operations he is allowed to do are as follows:

  • Transplant a tree: move a tree from one position to another position.

If you are confused about what “starting point unchanged” means, you can refer to the illustration in “Sample Explanation”.

Obviously, operations cost physical effort, so HG wants to keep as many trees as possible in their original positions. Now HG wants to know: in order to achieve the goal that the distance between any two adjacent trees is yy, at most how many trees can remain at their original positions.

Please help him.

Input Format

This problem contains multiple test cases within a single test point.

The input has T+1T + 1 lines.

The first line contains an integer TT, representing the number of test cases.
The next TT lines each contain three integers n,x,yn, x, y, representing the number of willows, the original spacing, and the desired spacing.

Output Format

Output TT lines. Each line contains one integer, meaning for the corresponding test case, in order to achieve the goal that the distance between any two adjacent trees is yy, the maximum number of trees that can stay in their original positions.

1
8 2 3
3

Hint

Sample 1 Explanation

The squares in the figure represent trees. The first row shows the situation before adjustment, and the second row shows the situation after adjustment. The three marked green squares are the trees that do not need to be moved; all other trees need to be moved.

Constraints

For 100%100\% of the data, it is guaranteed that 1T1051 \leq T \leq 10 ^ 5, 1n10181 \leq n \leq 10 ^ {18}, 1x<y1091 \leq x < y \leq 10 ^ 9.

Translated by ChatGPT 5