#P4739. [CERC2017] Donut Drone

[CERC2017] Donut Drone

题目描述

You are building a simulation in which a drone explores a volatile torus-shaped planet. Technically,the drone is moving across a toroidal grid — a rectangular grid that wraps around circularly in both dimensions. The grid consists of cells organized into rr rows numbered 11 through rr top to bottom and cc columns numbered 11 through cc left to right. Each grid cell has a certain elevation — a positive integer.

PZ6NxP.png

The drone is initially located in the cell in the first row and first column. In each step the drone considers three cells: the cell directly to the right, the cell diagonally right-down and the cell diagonally right-up (wrapping around if necessary). The drone flies to the cell with the largest elevation of the three.

Two types of events may happen during the simulation:

  • move k” — The drone makes kk steps.
  • change a b e” — The elevation of the cell in row aa column bb changes to ee.

Find the drone’s position immediately after each move event. You may assume that at each point in time, no sequence of three circularly consecutive cells in the same column will have the same elevation. Hence, each drone step is well defined.

输入格式

The first line contains two integers rr and c(3r,c2000)c(3 \le r,c \le 2 000) — the number of rows and the number of columns of the toroidal grid. The ithi-th of the following rr lines contains a sequence of cc integers $e_{i,1},e_{i,2},...,e_{i,c}(1 \le e_{i,j} \le 10^9)$ — the initial elevations of cells in row ii.

The following line contains an integer m(1m5000)m(1 \le m \le 5 000) — the number of events. The jthj-th of the following mm lines contains the jthj-th event and is either of the form “move k” where kk is an integer such that 1k1091 \le k \le 10^9 or “change a b e” where a,ba,b and ee are integers such that 1ar,1bc1 \le a \le r, 1 \le b \le c and 1e1091 \le e \le 10^9.

输出格式

Output ww lines where ww is the number of move events in the input — the jthj-th line should contain the drone’s position (row and column numbers) after the jthj-th move event in the input.

题目大意

输入一个循环矩阵(即第一行的上一行是最后一行,最后一行的下一行是第一行,最后一列的下一列是第一列)。你的初始位置在 (1,1)(1,1),每一步会走向右上、右、右下三个格子中权值最大的一个格子。

支持两种操作:

  • 修改一个格子的权值
  • 从当前位置走 kk 步,并输出目标位置
4 4
1 2 9 3
3 5 4 8
4 3 2 7
5 8 1 6
4
move 1
move 1
change 1 4 100
move 1

4 2
1 3
1 4

3 4
10 20 30 40
50 60 70 80
90 93 95 99
3
move 4
change 2 1 100
move 4

3 1
2 1