#P7598. [APIO2021] 六边形领域

    ID: 6604 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2021APIO交互题Special JudgeO2优化

[APIO2021] 六边形领域

Description

On a plane tiled infinitely with hexagons, Pak Dengklek stands on one cell and calls it the initial cell. If two cells in the hexagonal tiling share a common edge, they are called adjacent cells. In one move, Pak Dengklek can move from one cell to an adjacent cell in one of six possible directions (numbered from 11 to 66 as shown in the figure below).

Given an action sequence consisting of NN actions, Pak Dengklek can construct a territory from the path it produces (which corresponds to a sequence of visited cells in order). The ii-th action consists of a moving direction D[i]D[i] and a move length L[i]L[i] in that direction, and the path must satisfy the following properties:

  • The path is closed, meaning that in the cell sequence, the starting cell and the ending cell (i.e., the initial cell) are the same.
  • The path is simple, meaning that in the cell sequence, except that the initial cell is visited exactly twice (once as the start and once as the end), every other cell can be visited at most once.
  • The path is exposed, meaning that in the cell sequence, every cell is adjacent to at least one non-internal cell that does not appear in the sequence.
    • If a cell does not appear in the cell sequence, and starting from it, without passing through any cell in the sequence, it can reach only finitely many cells (via some number of moves), then we call this cell an internal cell.

The figure below shows an example of a path that satisfies the conditions above. In the figure:

  • Cell 11 (pink) is the initial cell.
  • The numbered cells (light blue) form the cell sequence, and the numbers indicate the order in which they are visited.
  • The cells marked with crosses (dark blue) are internal cells.

The constructed territory contains all cells on the path and all internal cells. The distance of a cell cc in the territory is defined as the minimum number of moves needed to reach cc from the initial cell while only passing through cells contained in the territory. The score of a cell in the territory is defined as A+d×BA+d \times B, where AA and BB are constants given by Pak Dengklek, and dd is the distance of that cell in the territory. The figure below shows the distance of each cell in the territory constructed from the example path above.

Help Pak Dengklek compute the sum of scores of all cells in the territory constructed from the given action sequence. Since the total score may be very large, output the result modulo 109+7{10}^9+7.

You need to implement the following function:

int draw_territory(int N, int A, int B, int[] D, int[] L)

  • NN: the number of actions in the action sequence.
  • A,BA, B: constants in the score calculation.
  • DD: an array of length NN, where D[i]D[i] is the direction of the ii-th action.
  • LL: an array of length NN, where L[i]L[i] is the move length of the ii-th action.
  • The function should return the total score of all cells in the territory constructed from the given action sequence, modulo 109+7{10}^9+7.
  • This function will be called exactly once.

Input Format

The sample grader reads input in the following format:

  • Line 11: NN AA BB.
  • Line 2+i2+i (0iN10 \le i \le N-1): D[i]D[i] L[i]L[i].

Output Format

The sample grader prints your answer in the following format:

  • Line 11: the return value of draw_territory.
17 2 3
1 1
2 2
3 2
4 1
5 1
4 1
3 1
2 2
1 3
6 2
2 3
3 1
4 6
5 3
6 3
6 2
1 1
1003

Hint

Sample Explanation

Consider the following call:

draw_territory(17, 2, 3,
			   [1, 2, 3, 4, 5, 4, 3, 2, 1, 6, 2, 3, 4, 5, 6, 6, 1],
			   [1, 2, 2, 1, 1, 1, 1, 2, 3, 2, 3, 1, 6, 3, 3, 2, 1])

This action sequence is the same as the example given in the statement above. The table below lists the score corresponding to each possible distance value in this territory.

Distance value Number of cells Score per cell Total score
00 11 2+0×3=22+0 \times 3=2 1×2=21 \times 2=2
11 44 2+1×3=52+1 \times 3=5 4×5=204 \times 5=20
22 55 2+2×3=82+2 \times 3=8 5×8=405 \times 8=40
33 66 2+3×3=112+3 \times 3=11 6×11=666 \times 11=66
44 2+4×3=142+4 \times 3=14 4×14=564 \times 14=56
55 33 2+5×3=172+5 \times 3=17 3×17=513 \times 17=51
66 44 2+6×3=202+6 \times 3=20 4×20=804 \times 20=80
77 2+7×3=232+7 \times 3=23 4×23=924 \times 23=92
88 55 2+8×3=262+8 \times 3=26 5×26=1305 \times 26=130
99 33 2+9×3=292+9 \times 3=29 3×29=873 \times 29=87
1010 44 2+10×3=322+10 \times 3=32 4×32=1284 \times 32=128
1111 55 2+11×3=352+11 \times 3=35 5×35=1755 \times 35=175
1212 22 2+12×3=382+12 \times 3=38 2×38=762 \times 38=76

The total score is 2+20+40+66+56+51+80+92+130+87+128+175+76=10032+20+40+66+56+51+80+92+130+87+128+175+76=1003.

Therefore, draw_territory should return 10031003.

Constraints

  • 3N2×1053 \le N \le 2\times {10}^5.
  • 0A,B1090 \le A,B \le {10}^9.
  • 1D[i]61 \le D[i] \le 6 (0iN10 \le i \le N-1).
  • 1L[i]1 \le L[i] (0iN10 \le i \le N-1).
  • The sum of elements in LL does not exceed 109{10}^9.
  • The path corresponding to the given action sequence is guaranteed to be closed, simple, and exposed.

Subtasks

  1. (3 points): N=3N=3, B=0B=0.
  2. (6 points): N=3N=3.
  3. (11 points): The sum of elements in LL does not exceed 20002000.
  4. (12 points): B=0B=0, and the sum of elements in LL does not exceed 2×1052\times {10}^5.
  5. (15 points): B=0B=0.
  6. (19 points): The sum of elements in LL does not exceed 2×1052\times {10}^5.
  7. (18 points): L[i]=L[i+1]L[i]=L[i+1] (0iN20 \le i \le N-2).
  8. (16 points): No additional constraints.

Translated by ChatGPT 5