| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 3 초 | 2048 MB | 9 | 1 | 1 | 25.000% |
The JOI Art Museum is planning to hold an exhibition of paintings soon. The museum owns $N$ paintings numbered from 1ドル$ to $N,ドル and the beauty of painting $i$ (1ドル ≤ i ≤ N$) is given as $A_i$. For the exhibition, these paintings will be arranged in a single row from left to right, but the order in which they are placed has not yet been determined.
There will be $M$ magazines covering the exhibition. These magazines are numbered from 1ドル$ to $M$ in descending order of their influence. Each magazine will publish photographs of a certain contiguous segment of paintings in the arranged row. Specifically, magazine $j$ (1ドル ≤ j ≤ M$) will publish photographs of the $L_j , L_j + 1, \dots , R_j$-th paintings from the left in the row. The appeal of the article by magazine $j$ (1ドル ≤ j ≤ M$) is defined as the maximum beauty among the paintings it covers.
JOI-kun, the director of the JOI Art Museum, aims to arrange the paintings in a way that allows these magazines to write articles with greater appeal, thereby attracting more people to the exhibition. Since magazines with greater influence reach a larger audience, he wants to prioritize increasing the appeal of articles in more influential magazines. More precisely, let $b_j$ be the appeal of the article published by magazine $j$ (1ドル ≤ j ≤ M$), then JOI-kun wants to arrange the paintings so that the sequence $b = (b_1, b_2, \dots , b_M)$ is lexicographically maximized. Here, for two distinct sequences $b = (b_1, b_2, \dots , b_M)$ and $b' = (b'_1, b'_2, \dots , b'_M),ドル $b$ is said to be lexicographically larger than $b'$ when, for the smallest index $k$ (1ドル ≤ k ≤ M$) such that $b_k \ne b'_k,ドル $b_k > b'_k$ holds.
Write a program which, given the information of the paintings to be exhibited and the magazines covering the event, calculates the appeal of each magazine’s article when the paintings are arranged to maximize the lexicographical order of sequence $b = (b_1, b_2, \dots , b_M)$.
Read the following data from the standard input.
$N$ $M$
$A_1$ $A_2$ $\cdots$ $A_N$
$L_1$ $R_1$
$L_2$ $R_2$
$\vdots$
$L_M$ $R_M$
Write $M$ lines to the standard output. The $j$-th line (1ドル ≤ j ≤ M$) of the output should contain $b_j,ドル the appeal of the article published by magazine $j$. Here, the sequence $b = (b_1, b_2, \dots , b_M)$ must be lexicographically maximized.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 19 | $N ≤ 400,ドル $M ≤ 400$. |
| 2 | 9 | $N ≤ 400$. |
| 3 | 19 | $A_i ≤ 5$ (1ドル ≤ i ≤ N$). |
| 4 | 12 | $A_i = i$ (1ドル ≤ i ≤ N$). |
| 5 | 17 | For each $k$ (1ドル ≤ k ≤ N$), the number of $i$ (1ドル ≤ i ≤ N$) satisfying $A_i = k$ is at most 5ドル$. |
| 6 | 24 | No additional constraints. |
4 4 1 2 1 2 1 1 2 3 4 4 3 4
2 2 1 2
When the paintings are arranged in the order 2,ドル 3, 4, 1$ from left to right, the appeal of each magazine’s article are determined as follows:
Thus, the sequence $b$ is $(2, 2, 1, 2)$. Since there is no arrangement of paintings that results in a lexicographically larger sequence than this, the output should be 2ドル,ドル 2ドル,ドル 1ドル,ドル and 2ドル$ in this order, separated by new lines.
This sample input satisfies the constraints of Subtasks 1, 2, 3, 5, and 6.
4 8 1 2 3 4 1 2 2 3 4 4 1 1 2 4 3 3 3 3 4 4
4 4 3 2 4 1 1 3
This sample input satisfies the constraints of all the subtasks.
12 10 6 2 2 5 2 5 2 3 3 3 2 2 3 5 10 12 12 12 2 4 8 9 10 11 1 3 7 9 9 10 10 11
6 5 5 6 5 3 6 5 5 3
This sample input satisfies the constraints of Subtasks 1, 2, and 6.