QOJ.ac

QOJ

Time Limit: 4.7 s Memory Limit: 512 MB Total points: 100

#197. 松鼠

Statistics

你位于一个 $M \times N$ 的树木网格的左上角,坐标为 $(1,1)$。一只松鼠在树与树之间跳跃。作为一只计算机科学松鼠,它跳跃的方式会形成分形图案……当然是树的分形!$S$ 分形看起来就像图片中那样:

大小为 1、2、4 和 8 的分形

松鼠遵循以下规则:

  • 松鼠从给定的树开始。
  • 然后它向北跳跃 $P$ 棵树,其中 $P$ 是给定的 2 的幂。
  • 然后它在两条长度为 $P/2$ 的对角线上跳跃。
  • 然后它跳跃形成四个大小为 $P/2$ 的分形。
  • 它持续跳跃直到形成大小为 1 的分形。
  • 图片展示了大小分别为 1、2、4 和 8 的前四个分形。

松鼠不断跳跃,直到完成一个分形形状,然后开始下一个分形。你能在多少棵树上看到松鼠?

输入格式

第一行包含三个整数 $M$、$N$ 和 $F$。接下来的 $F$ 行描述 $F$ 个分形。每一行包含三个整数,即起始树的坐标,后跟分形大小。

输出格式

输出一个整数,表示你能看到松鼠的位置数量。

数据范围

  • 如果你和松鼠所在的树之间没有其他树,你就能看到松鼠。
  • 松鼠在完成当前分形的所有跳跃后停止,然后开始下一个分形。
  • 松鼠永远不会跳到你所在的 $(1,1)$ 位置。
  • 松鼠永远不会跳出树木网格。
  • 如果松鼠在同一棵树上跳跃多次,且该树可见,则它会被多次计入最终结果。
  • $2 \le M, N \le 50,000$
  • $1 \le F \le 1000$
  • $1 \le \text{fractal size} \le 1024$,且分形大小为 2 的幂。
  • 总跳跃次数最多为 3 亿次。

子任务

测试用例将单独评分。

子任务 分值 附加输入限制
1 15% 总跳跃次数最多为 4000 万次。
2 10% 总跳跃次数最多为 6500 万次。
3 25% 总跳跃次数最多为 1.25 亿次。
4 50% 无。

样例

样例输入 1

14 20 3
11 10 4
7 6 2
8 7 2

样例输出 1

35

说明 1

该样例对应: 树木网格有 14 行 20 列。 松鼠跳跃了三个分形,分别是黑色、红色和绿色。 三角形标记了分形的起始点。 圆圈标记了从坐标 $(1, 1)$ 可见的树。 较粗的圆圈标记了可见的树,且松鼠在这些树上跳跃了多次。 可见树上的总跳跃次数为 35。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.