問題一覧 > 通常問題

No.905 Sorted?

レベル : / AI推定難易度 : 500 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 218
作問者 : face4 / テスター : 37zigen
お気に入りにしたユーザー ProblemId : 3433 / 自分の提出
問題文最終更新日: 2019-10-05 08:43:23
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 227 (順位表) の他の問題:

Problem Statement

You are given an integer sequence $A$ of length $N$ and a pair of its indices $l$,$r$. Determine whether the subsequence [$A_l, A_{l+1},\cdots,A_{r-1},A_r$] is
monotonically non-decreasing, and whether it is monotonically non-increasing.

Answer by printing the values of the two functions $f(l, r), g(l, r)$ defined below, in this order, separated by a space.
\begin{eqnarray} f(l, r)=\left\{ \begin{array}{ll} 1 & (\text{the subsequence }[A_l, A_{l+1},\cdots,A_{r-1},A_r]\text{ is monotonically non-decreasing}) \\ 0 & (\text{otherwise}) \\ \end{array} \right. \end{eqnarray} \begin{eqnarray} g(l, r)=\left\{ \begin{array}{ll} 1 & (\text{the subsequence }[A_l, A_{l+1},\cdots,A_{r-1},A_r]\text{ is monotonically non-increasing}) \\ 0 & (\text{otherwise}) \\ \end{array} \right. \end{eqnarray}

In this problem,
a sequence $A_0, ... A_k$ is monotonically non-decreasing if $A_i \leq A_{i+1}$ for all $0 \leq i < k$, and
a sequence $A_0, ... A_k$ is monotonically non-increasing if $A_i \geq A_{i+1}$ for all $0 \leq i < k$.
A subsequence of length 1 is considered to be both monotonically non-increasing and monotonically non-decreasing.

There are $Q$ pairs of indices $l$,$r$ given; process all of them.

Input

$N$
$A_0\ \cdots\ A_{N-1}$
$Q$
$l_0\ r_0$
$\vdots$
$l_{Q-1}\ r_{Q-1}$

All inputs are integers.

  • $1 \leq N \leq 10^5$
  • $-10^{18} \leq A_i \leq 10^{18}$
  • $1 \leq Q \leq 10^5$
  • $0 \leq l_i \leq r_i \leq N-1$

Output

Print $Q$ lines. On the $i$-th line, print $f(l_i, r_i),g(l_i, r_i)$ separated by a space. Print a newline at the end.

Sample

Sample 1
Input
5
8 -3 -4 0 9
3
0 1
1 3
2 4
Output
0 1
0 0
1 0
Sample 2
Input
5
10 10 10 9 9
3
0 0
0 2
2 4
Output
1 1
1 1
0 1
Sample 3
Input
4
-2 0 -2 -3
1
0 3
Output
0 0

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。