問題一覧 > 通常問題

No.2710 How many more?

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 190
作問者 : Nafmo2 / テスター : dyktr_06 sepa38 ryota2357
お気に入りにしたユーザー ProblemId : 9987 / 自分の提出
問題文最終更新日: 2024-03-31 15:47:39
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 425 (MMA Contest 018) (順位表) の他の問題:

Problem Statement

There is a marathon with $N$ participants. Each participant wears a bib with a serial number from $1$ to $N$, and the course is a straight line with no branches.
Currently, the person with bib $i$ is at a point at distance $A_i$ from the goal. Answer the $Q$ queries described below.

  • Query $q$: A pair of integers $(x_q,y_q)$ is given.
    Output how many people the person with bib $x_q$ needs to overtake in order to catch up with the person with bib $y_q$. However, if the person with bib $x_q$ is already at the same position as the person with bib $y_q$ or closer to the goal, output 0.
    More formally, output the number of $z$ satisfying $A_{y_q} < A_z < A_{x_q}$.

Input

$N \ Q$
$A_1 \ A_2 \ \dots \ A_N$
$x_1 \ y_1$
$\dots$
$x_Q \ y_Q$

  • $2 \leq N \leq 10^5$
  • $1 \leq Q \leq 10^5$
  • $1 \leq A_i \leq 10^9$
  • $1 \leq x_q,y_q \leq N$
  • $x_q \neq y_q $
  • $(x_q,y_q) \neq (x_r,y_r) \ (q \neq r) $
  • All inputs are integers.

Output

Process the $Q$ queries and output the result of each query on $1$ line, separated by newlines.

Sample

Sample 1
Input
4 3
7 20 14 8
2 1
3 1
4 1
Output
2
1
0

Before the person with bib $2$ draws level with the person with bib $1$, they need to overtake the $2$ people with bibs $3,4$.
Before the person with bib $3$ draws level with the person with bib $1$, they need to overtake the $1$ person with bib $4$.
There is no one the person with bib $4$ needs to overtake before drawing level with the person with bib $1$.

Sample 2
Input
8 5
18 14 10 15 11 3 13 2
7 8
2 1
2 8
7 6
3 8
Output
3
0
4
2
1

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