#P22306. Multidimensional Queries

    ID: 87 远端评测题 6000ms 512MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>数学位运算数据结构线段树*2300

Multidimensional Queries

题意

给你 nnkk 维的点 a1..na_{1..n},定义两点(x1,x2,,xk),(y1,y2,yk)(x_1,x_2,\cdots,x_k),(y_1,y_2,\cdots y_k) 间的曼哈顿距离为 i=1kxiyi\sum_{i=1}^k|x_i-y_i|

你需要执行下面两种操作:

1 i b1 b2bk1\ i\ b_1\ b_2\cdots b_k,表示将 aia_i 修改为 (b1,b2,,bk)(b_1,b_2,\cdots,b_k)

2 l r2\ l\ r,表示询问 [l,r][l,r] 内最大的两点间曼哈顿距离,即任取 x,y[l,r]x,y\in[l,r] 得到的所有曼哈顿距离中的最大值。

Input

The first line contains two numbers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $1 \le k \le 5$) — the number of elements in $a$ and the number of dimensions of the space, respectively.

Then $n$ lines follow, each containing $k$ integers $a_{i, 1}$, $a_{i, 2}$, ..., $a_{i, k}$ ($-10^6 \le a_{i, j} \le 10^6$) — the coordinates of $i$-th point.

The next line contains one integer $q$ ($1 \le q \le 2 \cdot 10^5$) — the number of queries.

Then $q$ lines follow, each denoting a query. There are two types of queries:

  • $1$ $i$ $b_1$ $b_2$ ... $b_k$ ($1 \le i \le n$, $-10^6 \le b_j \le 10^6$) — set $i$-th element of $a$ to the point $(b_1, b_2, \dots, b_k)$;
  • $2$ $l$ $r$ ($1 \le l \le r \le n$) — find the maximum distance between two points $a_i$ and $a_j$, where $l \le i, j \le r$.

There is at least one query of the second type.

Output

Print the answer for each query of the second type.

Samples

5 2
1 2
2 3
3 4
4 5
5 6
7
2 1 5
2 1 3
2 3 5
1 5 -1 -2
2 1 5
1 4 -1 -2
2 1 5
8
4
4
12
10