#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const int MAXK = 5;
const int INF = 1e9;
int n, k, q;
int a[MAXN][MAXK];
struct Node {
int min_val[1 << MAXK];
int max_val[1 << MAXK];
};
Node tree[4 * MAXN];
void build(int id, int l, int r) {
if (l == r) {
for (int mask = 0; mask < (1 << k); mask++) {
int sum = 0;
for (int i = 0; i < k; i++) {
if (mask & (1 << i)) {
sum += a[l][i];
} else {
sum -= a[l][i];
}
}
tree[id].min_val[mask] = sum;
tree[id].max_val[mask] = sum;
}
return;
}
int mid = (l + r) / 2;
build(id * 2, l, mid);
build(id * 2 + 1, mid + 1, r);
for (int mask = 0; mask < (1 << k); mask++) {
tree[id].min_val[mask] = min(tree[id * 2].min_val[mask], tree[id * 2 + 1].min_val[mask]);
tree[id].max_val[mask] = max(tree[id * 2].max_val[mask], tree[id * 2 + 1].max_val[mask]);
}
}
void update(int id, int l, int r, int pos) {
if (l == r) {
for (int mask = 0; mask < (1 << k); mask++) {
int sum = 0;
for (int i = 0; i < k; i++) {
if (mask & (1 << i)) {
sum += a[l][i];
} else {
sum -= a[l][i];
}
}
tree[id].min_val[mask] = sum;
tree[id].max_val[mask] = sum;
}
return;
}
int mid = (l + r) / 2;
if (pos <= mid) {
update(id * 2, l, mid, pos);
} else {
update(id * 2 + 1, mid + 1, r, pos);
}
for (int mask = 0; mask < (1 << k); mask++) {
tree[id].min_val[mask] = min(tree[id * 2].min_val[mask], tree[id * 2 + 1].min_val[mask]);
tree[id].max_val[mask] = max(tree[id * 2].max_val[mask], tree[id * 2 + 1].max_val[mask]);
}
}
pair<int, int> query(int id, int l, int r, int ql, int qr, int mask) {
if (ql <= l && r <= qr) {
return {tree[id].min_val[mask], tree[id].max_val[mask]};
}
int mid = (l + r) / 2;
pair<int, int> res = {INF, -INF};
if (ql <= mid) {
auto left_res = query(id * 2, l, mid, ql, qr, mask);
res.first = min(res.first, left_res.first);
res.second = max(res.second, left_res.second);
}
if (qr > mid) {
auto right_res = query(id * 2 + 1, mid + 1, r, ql, qr, mask);
res.first = min(res.first, right_res.first);
res.second = max(res.second, right_res.second);
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < k; j++) {
cin >> a[i][j];
}
}
build(1, 1, n);
cin >> q;
while (q--) {
int type;
cin >> type;
if (type == 1) {
int idx;
cin >> idx;
for (int j = 0; j < k; j++) {
cin >> a[idx][j];
}
update(1, 1, n, idx);
} else {
int l, r;
cin >> l >> r;
int ans = 0;
for (int mask = 0; mask < (1 << k); mask++) {
auto [min_val, max_val] = query(1, 1, n, l, r, mask);
ans = max(ans, max_val - min_val);
}
cout << ans << "\n";
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTUFYTiA9IDIwMDAwNTsKY29uc3QgaW50IE1BWEsgPSA1Owpjb25zdCBpbnQgSU5GID0gMWU5OwoKaW50IG4sIGssIHE7CmludCBhW01BWE5dW01BWEtdOwoKCnN0cnVjdCBOb2RlIHsKICAgIGludCBtaW5fdmFsWzEgPDwgTUFYS107CiAgICBpbnQgbWF4X3ZhbFsxIDw8IE1BWEtdOwp9OwoKTm9kZSB0cmVlWzQgKiBNQVhOXTsKCgp2b2lkIGJ1aWxkKGludCBpZCwgaW50IGwsIGludCByKSB7CiAgICBpZiAobCA9PSByKSB7CiAgICAgICAgZm9yIChpbnQgbWFzayA9IDA7IG1hc2sgPCAoMSA8PCBrKTsgbWFzaysrKSB7CiAgICAgICAgICAgIGludCBzdW0gPSAwOwogICAgICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IGs7IGkrKykgewogICAgICAgICAgICAgICAgaWYgKG1hc2sgJiAoMSA8PCBpKSkgewogICAgICAgICAgICAgICAgICAgIHN1bSArPSBhW2xdW2ldOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBzdW0gLT0gYVtsXVtpXTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICB0cmVlW2lkXS5taW5fdmFsW21hc2tdID0gc3VtOwogICAgICAgICAgICB0cmVlW2lkXS5tYXhfdmFsW21hc2tdID0gc3VtOwogICAgICAgIH0KICAgICAgICByZXR1cm47CiAgICB9CiAgICAKICAgIGludCBtaWQgPSAobCArIHIpIC8gMjsKICAgIGJ1aWxkKGlkICogMiwgbCwgbWlkKTsKICAgIGJ1aWxkKGlkICogMiArIDEsIG1pZCArIDEsIHIpOwogICAgCiAgICBmb3IgKGludCBtYXNrID0gMDsgbWFzayA8ICgxIDw8IGspOyBtYXNrKyspIHsKICAgICAgICB0cmVlW2lkXS5taW5fdmFsW21hc2tdID0gbWluKHRyZWVbaWQgKiAyXS5taW5fdmFsW21hc2tdLCB0cmVlW2lkICogMiArIDFdLm1pbl92YWxbbWFza10pOwogICAgICAgIHRyZWVbaWRdLm1heF92YWxbbWFza10gPSBtYXgodHJlZVtpZCAqIDJdLm1heF92YWxbbWFza10sIHRyZWVbaWQgKiAyICsgMV0ubWF4X3ZhbFttYXNrXSk7CiAgICB9Cn0KCgp2b2lkIHVwZGF0ZShpbnQgaWQsIGludCBsLCBpbnQgciwgaW50IHBvcykgewogICAgaWYgKGwgPT0gcikgewogICAgICAgIGZvciAoaW50IG1hc2sgPSAwOyBtYXNrIDwgKDEgPDwgayk7IG1hc2srKykgewogICAgICAgICAgICBpbnQgc3VtID0gMDsKICAgICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBrOyBpKyspIHsKICAgICAgICAgICAgICAgIGlmIChtYXNrICYgKDEgPDwgaSkpIHsKICAgICAgICAgICAgICAgICAgICBzdW0gKz0gYVtsXVtpXTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgc3VtIC09IGFbbF1baV07CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdHJlZVtpZF0ubWluX3ZhbFttYXNrXSA9IHN1bTsKICAgICAgICAgICAgdHJlZVtpZF0ubWF4X3ZhbFttYXNrXSA9IHN1bTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuOwogICAgfQogICAgCiAgICBpbnQgbWlkID0gKGwgKyByKSAvIDI7CiAgICBpZiAocG9zIDw9IG1pZCkgewogICAgICAgIHVwZGF0ZShpZCAqIDIsIGwsIG1pZCwgcG9zKTsKICAgIH0gZWxzZSB7CiAgICAgICAgdXBkYXRlKGlkICogMiArIDEsIG1pZCArIDEsIHIsIHBvcyk7CiAgICB9CiAgICAKICAgIGZvciAoaW50IG1hc2sgPSAwOyBtYXNrIDwgKDEgPDwgayk7IG1hc2srKykgewogICAgICAgIHRyZWVbaWRdLm1pbl92YWxbbWFza10gPSBtaW4odHJlZVtpZCAqIDJdLm1pbl92YWxbbWFza10sIHRyZWVbaWQgKiAyICsgMV0ubWluX3ZhbFttYXNrXSk7CiAgICAgICAgdHJlZVtpZF0ubWF4X3ZhbFttYXNrXSA9IG1heCh0cmVlW2lkICogMl0ubWF4X3ZhbFttYXNrXSwgdHJlZVtpZCAqIDIgKyAxXS5tYXhfdmFsW21hc2tdKTsKICAgIH0KfQoKCnBhaXI8aW50LCBpbnQ+IHF1ZXJ5KGludCBpZCwgaW50IGwsIGludCByLCBpbnQgcWwsIGludCBxciwgaW50IG1hc2spIHsKICAgIGlmIChxbCA8PSBsICYmIHIgPD0gcXIpIHsKICAgICAgICByZXR1cm4ge3RyZWVbaWRdLm1pbl92YWxbbWFza10sIHRyZWVbaWRdLm1heF92YWxbbWFza119OwogICAgfQogICAgCiAgICBpbnQgbWlkID0gKGwgKyByKSAvIDI7CiAgICBwYWlyPGludCwgaW50PiByZXMgPSB7SU5GLCAtSU5GfTsKICAgIAogICAgaWYgKHFsIDw9IG1pZCkgewogICAgICAgIGF1dG8gbGVmdF9yZXMgPSBxdWVyeShpZCAqIDIsIGwsIG1pZCwgcWwsIHFyLCBtYXNrKTsKICAgICAgICByZXMuZmlyc3QgPSBtaW4ocmVzLmZpcnN0LCBsZWZ0X3Jlcy5maXJzdCk7CiAgICAgICAgcmVzLnNlY29uZCA9IG1heChyZXMuc2Vjb25kLCBsZWZ0X3Jlcy5zZWNvbmQpOwogICAgfQogICAgCiAgICBpZiAocXIgPiBtaWQpIHsKICAgICAgICBhdXRvIHJpZ2h0X3JlcyA9IHF1ZXJ5KGlkICogMiArIDEsIG1pZCArIDEsIHIsIHFsLCBxciwgbWFzayk7CiAgICAgICAgcmVzLmZpcnN0ID0gbWluKHJlcy5maXJzdCwgcmlnaHRfcmVzLmZpcnN0KTsKICAgICAgICByZXMuc2Vjb25kID0gbWF4KHJlcy5zZWNvbmQsIHJpZ2h0X3Jlcy5zZWNvbmQpOwogICAgfQogICAgCiAgICByZXR1cm4gcmVzOwp9CgppbnQgbWFpbigpIHsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZShOVUxMKTsKICAgIAogICAgY2luID4+IG4gPj4gazsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkrKykgewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgazsgaisrKSB7CiAgICAgICAgICAgIGNpbiA+PiBhW2ldW2pdOwogICAgICAgIH0KICAgIH0KICAgIAogICAgYnVpbGQoMSwgMSwgbik7CiAgICAKICAgIGNpbiA+PiBxOwogICAgd2hpbGUgKHEtLSkgewogICAgICAgIGludCB0eXBlOwogICAgICAgIGNpbiA+PiB0eXBlOwogICAgICAgIAogICAgICAgIGlmICh0eXBlID09IDEpIHsKICAgICAgICAgICAgaW50IGlkeDsKICAgICAgICAgICAgY2luID4+IGlkeDsKICAgICAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBrOyBqKyspIHsKICAgICAgICAgICAgICAgIGNpbiA+PiBhW2lkeF1bal07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdXBkYXRlKDEsIDEsIG4sIGlkeCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaW50IGwsIHI7CiAgICAgICAgICAgIGNpbiA+PiBsID4+IHI7CiAgICAgICAgICAgIAogICAgICAgICAgICBpbnQgYW5zID0gMDsKICAgICAgICAgICAgZm9yIChpbnQgbWFzayA9IDA7IG1hc2sgPCAoMSA8PCBrKTsgbWFzaysrKSB7CiAgICAgICAgICAgICAgICBhdXRvIFttaW5fdmFsLCBtYXhfdmFsXSA9IHF1ZXJ5KDEsIDEsIG4sIGwsIHIsIG1hc2spOwogICAgICAgICAgICAgICAgYW5zID0gbWF4KGFucywgbWF4X3ZhbCAtIG1pbl92YWwpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIAogICAgICAgICAgICBjb3V0IDw8IGFucyA8PCAiXG4iOwogICAgICAgIH0KICAgIH0KICAgIAogICAgcmV0dXJuIDA7Cn0=