#11025. [CERC2017] Donut Drone

[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 $r$ rows numbered $1$ through $r$ top to bottom and $c$ columns numbered $1$ through $c$ left to right. Each grid cell has a certain elevation — a positive integer.

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 $r$ and $c(3 \le r,c \le 2 000)$ — the number of rows and the number of columns of the toroidal grid. The $i-th$ of the following $r$ lines contains a sequence of $c$ 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 $i$.

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

输出格式

Output $w$ lines where $w$ is the number of ``move`` events in the input — the $j-th$ line should contain the drone’s position (row and column numbers) after the $j-th$ ``move`` event in the input.
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

提示

(暂无提示) 标签: P4739|2017|线段树|倍增|ICPC|CERC

来源

P4739|[CERC2017] Donut Drone