QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#10962. Shock Wave

统计

Bessie is experimenting with a powerful hoof implant that has the ability to create massive shock waves. She has $N$ ($2 \leq N \leq 10^5$) tiles lined up in front of her, which require powers of at least $p_0,p_1,\dots,p_{N-1}$ to break, respectively ($0 \leq p_i \leq 10^{18}$). Bessie can apply power by punching a specific tile but due to the strange nature of her implant, it will not apply any power to the tile she punches. Instead, if she chooses to punch tile $x$ once, where $x$ is an integer in $[0,N-1]$, it applies $|i-x|$ power to tile $i$ for all integers $i$ in the range $[0,N-1]$. This power is also cumulative, so applying $2$ power twice to a tile will apply a total of $4$ power to the tile. Please determine the fewest number of punches required to break all the tiles.

Input Format

Line $2t$ contains a single integer $N$, the number of tiles in test case $t$. Line $2t+1$ contains $N$ space separated numbers $p_0,p_1, \ldots, p_{N-1}$ representing that tile $i$ takes $p_i$ power to be broken. It is guaranteed that the sum of all $N$ in a single input does not exceed $5\cdot 10^5$.

Line $2t+1$ contains $N$ space separated numbers $p_0,p_1, \ldots, p_{N-1}$ representing that tile $i$ takes $p_i$ power to be broken. It is guaranteed that the sum of all $N$ in a single input does not exceed $5\cdot 10^5$.

It is guaranteed that the sum of all $N$ in a single input does not exceed $5\cdot 10^5$.

Output Format

$T$ lines, the $i$th line representing the answer to the $i$th test case.

Sample Data

Sample Input

6
5
0 2 4 5 8
5
6 5 4 5 6
5
1 1 1 1 1
5
12 10 8 6 4
7
6 1 2 3 5 8 13
2
1000000000000000000 1000000000000000000

Sample Output

2
3
2
4
4
2000000000000000000

Sample Explanation

For the first test, the only way for Bessie to break all the tiles with two punches is to punch $0$ twice, applying total powers of $[0,2,4,6,8]$ respectively. For the second test, one way for Bessie to break all the tiles with three punches is to punch $0$, $2$, and $4$ one time each, applying total powers of $[6,5,4,5,6]$ respectively. For the third test, one way for Bessie to break all the tiles with two punches is to punch $0$ and $1$ one time each, applying total powers of $[1,1,3,5,7]$ respectively.

Constraints

  • Input 2: All $p_i$ are equal.
  • Inputs 3-6: $N\le 100$
  • Inputs 7-14: No additional constraints.
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.