問題一覧 > 通常問題

No.1596 Distance Sum in 2D Plane

レベル : / AI推定難易度 : 1300 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 268
作問者 : e869120 / テスター : hirakich1000000007 ygussany
お気に入りにしたユーザー ProblemId : 6419 / 自分の提出
問題文最終更新日: 2021-07-08 23:25: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
競プロ典型 90 問 期末試験 (順位表) の他の問題:

Problem Statement

There is a $2$-dimensional plane, and you want to move from your current coordinates $(0, 0)$ to the destination coordinates $(N, N)$.
When you are at cell $(r, c)$, you can perform the following $2$ types of moves.

  • Basically, pay $1$ yen and move from cell $(r, c)$ to cell $(r+1, c)$. This move can be used when $r < N$.
  • Basically, pay $1$ yen and move from cell $(r, c)$ to cell $(r, c+1)$. This move can be used when $c < N$.

However, the following $M$ moves alone can be performed for free. (Conversely, note that these moves cannot be performed by paying $1$ yen.)

  • When $t_i = 1$: the move from cell $(x_i, y_i)$ to cell $(x_i + 1, y_i)$ can be performed for free.
  • When $t_i = 2$: the move from cell $(x_i, y_i)$ to cell $(x_i, y_i + 1)$ can be performed for free.
There are many possible ways to move. Find the sum of "the amount of money required for the movement" over all of them, modulo $10^9+7$.

Input

$N$ $M$
$t_1$ $x_1$ $y_1$
$t_2$ $x_2$ $y_2$
$t_3$ $x_3$ $y_3$
 $\vdots$
$t_M$ $x_M$ $y_M$

Output

Output the answer.

Constraints

  • $1 \leq N \leq 200000$
  • $0 \leq M \leq 200000$
  • $1 \leq t_i \leq 2$
  • When $t_i = 1$, $0 \leq x_i < N$ and $0 \leq y_i \leq N$
  • When $t_i = 2$, $0 \leq x_i \leq N$ and $0 \leq y_i < N$
  • $(t_1, x_1, y_1), (t_2, x_2, y_2), (t_3, x_3, y_3), \dots, (t_N, x_N, y_N)$ are pairwise distinct
  • All input values are integers

Sample

Sample 1
Input
2 1
1 0 0
Output
21

As shown in the figure below, there are $6$ ways to move. The total amount is $3 + 3 + 3 + 4 + 4 + 4 = 21$ yen.

1

Sample

Sample 2
Input
5 0
Output
2520

There are $252$ ways to move, and "the amount of money required for the movement" is $10$ yen for all of them, so the answer is $252 \times 10 = 2520$.

Sample 3
Input
400 10
2 73 190
2 351 261
1 164 365
1 62 221
1 18 209
1 358 211
2 32 206
1 147 46
1 36 77
2 5 203
Output
85571926

Output "the amount of money required for the movement" modulo $10^9+7$.

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