問題一覧 > 通常問題

No.2743 Twisted Lattice

レベル : / AI推定難易度 : 1700 / 実行時間制限 : 1ケース 3.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 36
作問者 : Nzt3 / テスター : tassei903 kenken714 ponjuice cho435
お気に入りにしたユーザー ProblemId : 10835 / 自分の提出
問題文最終更新日: 2024-04-19 15:21:07
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
CPCTF 2024 : PPC (順位表) の他の問題:

Problem Statement

There is a grid with $H$ rows and $W$ columns.

The cell in the $i$-th row from the top and the $j$-th column from the left is denoted by $(i,j)$.

  • For $1\le i < H,1 \le j \le W$, you can move between $(i,j)$ and $(i+1,j)$ in either direction in time $1$.
  • For $1\le i \le H,1 \le j < W$, you can move between $(i,j)$ and $(i,j+1)$ in either direction in time $i$.

There are $N$ exits on the grid, and exit $i$ is at $(A_i,B_i)$.

Solve the following problem for each of $x=1,2,\ldots ,N$.

  • You are initially at exit $x$. Find the minimum time required to move to another exit.

Constraints

  • $1 \le H \le 10^9$
  • $1 \le W \le 10^9$
  • $2 \le H\times W$
  • $2 \le N \le 2 \times 10^5$
  • $1 \le A_i \le H$
  • $1 \le B_i \le W$
  • $(A_i,B_i)\not=(A_j,B_j)$ when $i\not=j$
  • All input values are integers.

Input

The input is given from standard input in the following format.

$H$ $W$ $N$
$A_1$ $B_1$
$\vdots$
$A_N$ $B_N$

Output

Print $N$ lines. The $i$-th line should contain the answer to the problem for $x=i$.

Sample

Sample 1
Input
10 10 6
1 2
2 3
3 3
10 7
8 2
3 5
Output
2
1
1
13
7
5

For line $1$ of the output, the shortest time to move to exit $2$ is $2$, and this is the minimum.

For line $2$ of the output, the shortest time to move to exit $3$ is $1$, and this is the minimum.

Sample 2
Input
1000000000 1000000000 2
1000000000 1
1000000000 1000000000
Output
2999999997
2999999997

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