33OJ
登录 注册

#P17575. [JAG 2026 Summer Camp #3] Self-Destruct Sequence

[JAG 2026 Summer Camp #3] Self-Destruct Sequence

Problem Description

You are given a sequence of NN positive integers A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N).

For each kk (1≤k≤N1\le k\le N), solve the following problem:

Let BB initially be the sequence (A1,A2,…,Ak)(A_1,A_2,\ldots,A_k). At any point during the process, let ∣B∣|B| denote the current length of BB and let BiB_i denote its ii-th element.

You may perform the following operation any number of times.

  • Choose an index ii (1≤i≤∣B∣1\le i\le |B|) satisfying i+Bi−1≤∣B∣i+B_i-1\le |B|. Remove the elements Bi,Bi+1,…,Bi+Bi−1B_i,B_{i+1},\ldots,B_{i+B_i-1} from BB. The remaining elements, in their original order, form the new sequence BB.

Determine whether BB can be made empty. If so, find the minimum and maximum possible numbers of operations required.

Input Format

The input consists of a single test case of the following format.

N
A_1 A_2 ... A_N

The first line contains an integer NN (1≤N≤50001\le N\le5000), representing the length of the sequence.

The second line contains NN integers A1,A2,…,ANA_1,A_2,\ldots,A_N (1≤Ai≤N1\le A_i\le N).

Output Format

Print NN lines.

For each kk (1≤k≤N1\le k\le N), the kk-th line should contain the answer for B=(A1,A2,…,Ak)B=(A_1,A_2,\ldots,A_k). If it is impossible to make BB empty, print -1. Otherwise, print two integers: the minimum and maximum possible numbers of operations required to make BB empty, respectively.

5
3 4 2 1 1
-1
-1
1 1
2 2
2 3
6
2 1 3 2 1 2
-1
1 1
2 2
-1
2 3
3 4